OSDN Git Service

ログ管理にSQLiteを導入。実装はまだ行っていない
authorspark_xp <spark_xp@d8c9ecd3-d47d-4367-8645-de82c00e513f>
Wed, 22 Jun 2011 17:01:10 +0000 (17:01 +0000)
committerspark_xp <spark_xp@d8c9ecd3-d47d-4367-8645-de82c00e513f>
Wed, 22 Jun 2011 17:01:10 +0000 (17:01 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/nt-manager/NishioTweetManager/trunk@147 d8c9ecd3-d47d-4367-8645-de82c00e513f

lib/commons-dbutils-1.3.jar [new file with mode: 0644]
lib/sqlite-jdbc-3.7.2.jar [new file with mode: 0644]
sql/createTable.sql [new file with mode: 0644]
src/twitter/log/TweetDBObject.java [new file with mode: 0644]
src/twitter/log/TwitterLogDao.java [new file with mode: 0644]
src/twitter/manage/TweetConfiguration.java

diff --git a/lib/commons-dbutils-1.3.jar b/lib/commons-dbutils-1.3.jar
new file mode 100644 (file)
index 0000000..953e13c
Binary files /dev/null and b/lib/commons-dbutils-1.3.jar differ
diff --git a/lib/sqlite-jdbc-3.7.2.jar b/lib/sqlite-jdbc-3.7.2.jar
new file mode 100644 (file)
index 0000000..b0bec7b
Binary files /dev/null and b/lib/sqlite-jdbc-3.7.2.jar differ
diff --git a/sql/createTable.sql b/sql/createTable.sql
new file mode 100644 (file)
index 0000000..fc88d8e
--- /dev/null
@@ -0,0 +1,39 @@
+CREATE TABLE IF NOT EXISTS TWEET(
+       id INTEGER PRIMARY KEY,
+       following TEXT,
+       date TEXT,
+       replyStatusID INTEGER,
+       replyUserID INTEGER,
+       text TEXT,
+       created TEXT,
+       description TEXT,
+       userFavorite INTEGER,
+       followers INTEGER,
+       friend INTEGER,
+       userId INTEGER,
+       lang TEXT,
+       location TEXT,
+       name TEXT,
+       profileBackgroundColor TEXT,
+       profileBackgroundImageURL TEXT,
+       profileImageURL TEXT,
+       profileSidebarBorderColor TEXT,
+       profileSidebarFillColor TEXT,
+       profileTextColor TEXT,
+       screenName TEXT,
+       statusesCount INTEGER,
+       timeZone TEXT,
+       url TEXT,
+       utc INTEGER,
+       contributorsEnable TEXT,
+       geoEnable TEXT,
+       profileBackgroundTiled TEXT,
+       isProtected TEXT,
+       verified TEXT,
+       source TEXT,
+       favorite TEXT,
+       retweet TEXT,
+       truncated TEXT
+);
+
+       
diff --git a/src/twitter/log/TweetDBObject.java b/src/twitter/log/TweetDBObject.java
new file mode 100644 (file)
index 0000000..ed8f152
--- /dev/null
@@ -0,0 +1,271 @@
+package twitter.log;
+
+public class TweetDBObject {
+       
+       private long id;
+
+       private String following;
+       private String date;
+       private long replyStatusID;
+       private long replyUserID;
+       private String text;
+       private String created;
+       private long userFavorite;
+       private long followers;
+       private long friend;
+       private long userId;
+       private String lang;
+       private String location;
+       private String name;
+       private String profileBackgroundColor;
+       private String profileBackgroundImageURL;
+       private String profileImageURL;
+       private String profileSidebarBorderColor;
+       private String profileSidebarFillColor;
+       private String profileTextColor;
+       private String screenName;
+       private long statusesCount;
+       private String timeZone;
+       private String url;
+       private long utc;
+       private String contributorsEnable;
+       private String geoEnable;
+       private String profileBackgroundTiled;
+       private String isProtected;
+       private String verified;
+       private String source;
+       private String favorite;
+       private String retweet;
+       private String truncated;
+       
+       public String getContributorsEnable() {
+               return contributorsEnable;
+       }
+       public String getCreated() {
+               return created;
+       }
+       public String getDate() {
+               return date;
+       }
+       public String getFavorite() {
+               return favorite;
+       }
+       public long getFollowers() {
+               return followers;
+       }
+       public String getFollowing() {
+               return following;
+       }
+       public long getFriend() {
+               return friend;
+       }
+       public String getGeoEnable() {
+               return geoEnable;
+       }
+       public long getId() {
+               return id;
+       }
+       public String getIsProtected() {
+               return isProtected;
+       }
+       public String getLang() {
+               return lang;
+       }
+       public String getLocation() {
+               return location;
+       }
+       public String getName() {
+               return name;
+       }
+       public String getProfileBackgroundColor() {
+               return profileBackgroundColor;
+       }
+       public String getProfileBackgroundImageURL() {
+               return profileBackgroundImageURL;
+       }
+       public String getProfileBackgroundTiled() {
+               return profileBackgroundTiled;
+       }
+       public String getProfileImageURL() {
+               return profileImageURL;
+       }
+       public String getProfileSidebarBorderColor() {
+               return profileSidebarBorderColor;
+       }
+       public String getProfileSidebarFillColor() {
+               return profileSidebarFillColor;
+       }
+       public String getProfileTextColor() {
+               return profileTextColor;
+       }
+       public long getReplyStatusID() {
+               return replyStatusID;
+       }
+       public long getReplyUserID() {
+               return replyUserID;
+       }
+       public String getRetweet() {
+               return retweet;
+       }
+       public String getScreenName() {
+               return screenName;
+       }
+       public String getSource() {
+               return source;
+       }
+       public long getStatusesCount() {
+               return statusesCount;
+       }
+       public String getText() {
+               return text;
+       }
+       public String getTimeZone() {
+               return timeZone;
+       }
+       public String getTruncated() {
+               return truncated;
+       }
+       public String getUrl() {
+               return url;
+       }
+       public long getUserFavorite() {
+               return userFavorite;
+       }
+       public long getUserId() {
+               return userId;
+       }
+       public long getUtc() {
+               return utc;
+       }
+       public String getVerified() {
+               return verified;
+       }
+       public void setContributorsEnable(String contributorsEnable) {
+               this.contributorsEnable = contributorsEnable;
+       }
+       public void setCreated(String created) {
+               this.created = created;
+       }
+       public void setDate(String date) {
+               this.date = date;
+       }
+       public void setFavorite(String favorite) {
+               this.favorite = favorite;
+       }
+       public void setFollowers(long followers) {
+               this.followers = followers;
+       }
+       public void setFollowing(String following) {
+               this.following = following;
+       }
+       public void setFriend(long friend) {
+               this.friend = friend;
+       }
+       public void setGeoEnable(String geoEnable) {
+               this.geoEnable = geoEnable;
+       }
+       public void setId(long id) {
+               this.id = id;
+       }
+       public void setIsProtected(String isProtected) {
+               this.isProtected = isProtected;
+       }
+       public void setLang(String lang) {
+               this.lang = lang;
+       }
+       public void setLocation(String location) {
+               this.location = location;
+       }
+       public void setName(String name) {
+               this.name = name;
+       }
+       public void setProfileBackgroundColor(String profileBackgroundColor) {
+               this.profileBackgroundColor = profileBackgroundColor;
+       }
+       public void setProfileBackgroundImageURL(String profileBackgroundImageURL) {
+               this.profileBackgroundImageURL = profileBackgroundImageURL;
+       }
+       public void setProfileBackgroundTiled(String profileBackgroundTiled) {
+               this.profileBackgroundTiled = profileBackgroundTiled;
+       }
+       public void setProfileImageURL(String profileImageURL) {
+               this.profileImageURL = profileImageURL;
+       }
+       public void setProfileSidebarBorderColor(String profileSidebarBorderColor) {
+               this.profileSidebarBorderColor = profileSidebarBorderColor;
+       }
+       public void setProfileSidebarFillColor(String profileSidebarFillColor) {
+               this.profileSidebarFillColor = profileSidebarFillColor;
+       }
+       public void setProfileTextColor(String profileTextColor) {
+               this.profileTextColor = profileTextColor;
+       }
+       public void setReplyStatusID(long replyStatusID) {
+               this.replyStatusID = replyStatusID;
+       }
+       public void setReplyUserID(long replyUserID) {
+               this.replyUserID = replyUserID;
+       }
+       public void setRetweet(String retweet) {
+               this.retweet = retweet;
+       }
+       public void setScreenName(String screenName) {
+               this.screenName = screenName;
+       }
+       public void setSource(String source) {
+               this.source = source;
+       }
+       public void setStatusesCount(long statusesCount) {
+               this.statusesCount = statusesCount;
+       }
+       public void setText(String text) {
+               this.text = text;
+       }
+       public void setTimeZone(String timeZone) {
+               this.timeZone = timeZone;
+       }
+       public void setTruncated(String truncated) {
+               this.truncated = truncated;
+       }
+       public void setUrl(String url) {
+               this.url = url;
+       }
+       public void setUserFavorite(long userFavorite) {
+               this.userFavorite = userFavorite;
+       }
+       public void setUserId(long userId) {
+               this.userId = userId;
+       }
+       public void setUtc(long utc) {
+               this.utc = utc;
+       }
+       public void setVerified(String verified) {
+               this.verified = verified;
+       }
+       @Override
+       public String toString() {
+               return "TweetDBObject [contributorsEnable=" + contributorsEnable
+                               + ", created=" + created + ", date=" + date + ", favorite="
+                               + favorite + ", followers=" + followers + ", following="
+                               + following + ", friend=" + friend + ", geoEnable=" + geoEnable
+                               + ", id=" + id + ", isProtected=" + isProtected + ", lang="
+                               + lang + ", location=" + location + ", name=" + name
+                               + ", profileBackgroundColor=" + profileBackgroundColor
+                               + ", profileBackgroundImageURL=" + profileBackgroundImageURL
+                               + ", profileBackgroundTiled=" + profileBackgroundTiled
+                               + ", profileImageURL=" + profileImageURL
+                               + ", profileSidebarBorderColor=" + profileSidebarBorderColor
+                               + ", profileSidebarFillColor=" + profileSidebarFillColor
+                               + ", profileTextColor=" + profileTextColor + ", replyStatusID="
+                               + replyStatusID + ", replyUserID=" + replyUserID + ", retweet="
+                               + retweet + ", screenName=" + screenName + ", source=" + source
+                               + ", statusesCount=" + statusesCount + ", text=" + text
+                               + ", timeZone=" + timeZone + ", truncated=" + truncated
+                               + ", url=" + url + ", userFavorite=" + userFavorite
+                               + ", userId=" + userId + ", utc=" + utc + ", verified="
+                               + verified + "]";
+       }
+       
+       public TweetDBObject() {
+       }
+}
diff --git a/src/twitter/log/TwitterLogDao.java b/src/twitter/log/TwitterLogDao.java
new file mode 100644 (file)
index 0000000..3d5646c
--- /dev/null
@@ -0,0 +1,118 @@
+package twitter.log;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import twitter.manage.TweetConfiguration;
+
+/**
+ * Tweetログ保存用データベースへのアクセス
+ * @author nishio
+ *
+ */
+public class TwitterLogDao {
+       //データベース接続文字列
+       private static final String DATABASE = TweetConfiguration.DATABASE;
+       private static final String DATABASE_CONNECTION = TweetConfiguration.DATABASE_CONNECTION;
+       
+       //データベース接続
+       private Connection databaseConnection = null;
+       
+       //データベーステーブルの定義
+       private static final String createTableSql =
+               "CREATE TABLE IF NOT EXISTS TWEET(" +
+               "               id INTEGER PRIMARY KEY,"    +
+               "               following TEXT," +
+               "               date TEXT," + 
+               "               replyStatusID INTEGER," + 
+               "               replyUserID INTEGER," + 
+               "               text TEXT," + 
+               "               created TEXT," + 
+               "               description TEXT," + 
+               "               userFavorite INTEGER," + 
+               "               followers INTEGER," + 
+               "               friend INTEGER," + 
+               "               userId INTEGER," + 
+               "               lang TEXT," + 
+               "               location TEXT," + 
+               "               name TEXT," + 
+               "               profileBackgroundColor TEXT," + 
+               "               profileBackgroundImageURL TEXT," + 
+               "               profileImageURL TEXT," + 
+               "               profileSidebarBorderColor TEXT," + 
+               "               profileSidebarFillColor TEXT," + 
+               "               profileTextColor TEXT," + 
+               "               screenName TEXT," + 
+               "               statusesCount INTEGER," + 
+               "               timeZone TEXT," + 
+               "               url TEXT," + 
+               "               utc INTEGER," + 
+               "               contributorsEnable TEXT," + 
+               "               geoEnable TEXT," + 
+               "               profileBackgroundTiled TEXT," + 
+               "               isProtected TEXT," + 
+               "               verified TEXT," + 
+               "               source TEXT," + 
+               "               favorite TEXT," + 
+               "               retweet TEXT," + 
+               "               truncated TEXT)"  ;
+       
+       //データ挿入SQL
+       private static final String insertDataSql = 
+               "INSERT INTO TWEET VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
+       
+       //データ取得SQL
+       private static final String selectDataSql = 
+               "SELECT * FROM TWEET;";
+       
+       /**
+        * データベース接続
+        */
+       public void connectDB() {
+        try {
+                       Class.forName( DATABASE );
+               this.databaseConnection = DriverManager.getConnection( DATABASE_CONNECTION );
+               } catch (ClassNotFoundException e) {
+                       e.printStackTrace();
+               } catch (SQLException e) {
+                       e.printStackTrace();
+               }
+       }
+       
+       /**
+        * データベースの接続を終了する
+        */
+       public void closeDB() {
+               if( this.databaseConnection != null ) {
+                       try {
+                               this.databaseConnection.close();
+                       } catch (SQLException e) {
+                               e.printStackTrace();
+                       }
+               }
+       }
+       
+       /**
+        * テーブルを作成する
+        */
+       public void createTable() {
+               Statement statement;
+               try {
+                       statement = this.databaseConnection.createStatement();
+                       statement.execute( createTableSql );
+               } catch (SQLException e) {
+                       e.printStackTrace();
+               }
+       }
+       
+       public static void main(String[] args) {
+               TwitterLogDao dao = new TwitterLogDao();
+               dao.connectDB();
+               
+               dao.createTable();
+               
+               dao.closeDB();
+       }
+}
index 7b429a4..cd55c09 100644 (file)
@@ -27,4 +27,8 @@ public class TweetConfiguration {
        public static final String ACCOUNT_INFORMATION_FILENAME = "account.properties";
        // search twitterのURL
        public static final String SEARCH_TWITTER_HOSTNAME = "search.twitter.com";
+       //データベース接続文字列
+       public static final String DATABASE = "org.sqlite.JDBC";
+       //ツイートを保存するデータベース名
+       public static final String DATABASE_CONNECTION = "jdbc:sqlite:" + LOG_DIRECTORY + "/tweet.db";
 }