OSDN Git Service

自分のタイムラインのツイートをSQLiteに書きだすプログラムを実装
authorspark_xp <spark_xp@d8c9ecd3-d47d-4367-8645-de82c00e513f>
Sun, 26 Jun 2011 15:29:36 +0000 (15:29 +0000)
committerspark_xp <spark_xp@d8c9ecd3-d47d-4367-8645-de82c00e513f>
Sun, 26 Jun 2011 15:29:36 +0000 (15:29 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/nt-manager/NishioTweetManager/trunk@149 d8c9ecd3-d47d-4367-8645-de82c00e513f

src/twitter/log/StatusDBObjectConverter.java
src/twitter/log/TweetDBObject.java
src/twitter/log/TwitterLogDao.java

index 5f868fc..8e477b8 100644 (file)
@@ -20,7 +20,6 @@ public class StatusDBObjectConverter {
                TweetDBObject result = new TweetDBObject();
                
                result.setId( s.getId() );
-               result.setFollowing(following + "");
                
                String date = null;
                if (s.getCreatedAt() != null) {
@@ -43,8 +42,40 @@ public class StatusDBObjectConverter {
                                userCreated = sdf.format(s.getCreatedAt());
                        }
                        result.setCreated( userCreated );
-                       
+                       result.setDescription( u.getDescription() );
+                       result.setUserFavorite( u.getFavouritesCount() );
+                       result.setFollowers( u.getFollowersCount() );
+                       result.setFriend( u.getFriendsCount() );
+                       result.setUserId( u.getId() );
+                       result.setLang( u.getLang() );
+                       result.setLocation( u.getLocation() );
+                       result.setName( u.getName() );
+                       result.setProfileBackgroundColor( u.getProfileBackgroundColor() );
+                       result.setProfileBackgroundImageURL( u.getProfileBackgroundImageUrl() );
+                       result.setProfileImageURL( u.getProfileImageURL().toString() );
+                       result.setProfileSidebarBorderColor( u.getProfileSidebarBorderColor() );
+                       result.setProfileSidebarFillColor( u.getProfileSidebarFillColor() );
+                       result.setProfileTextColor( u.getProfileTextColor() );
+                       result.setScreenName( u.getScreenName() );
+                       result.setStatusesCount( u.getStatusesCount() );
+                       result.setTimeZone( u.getTimeZone() );
+                       if( u.getURL() != null ) {
+                               result.setUrl( u.getURL().toString() );
+                       }else {
+                               result.setUrl("");
+                       }
+                       result.setUtc( u.getUtcOffset() );
+                       result.setContributorsEnable( u.isContributorsEnabled() + "" );
+                       result.setGeoEnable( u.isGeoEnabled() + "");
+                       result.setProfileBackgroundTiled( u.isProfileBackgroundTiled() + "");
+                       result.setIsProtected( u.isProtected() + "");
+                       result.setVerified( u.isVerified() + "");
                }
+               result.setSource( s.getSource() );
+               result.setFavorite( s.isFavorited() + "");
+               result.setRetweet( s.isRetweet() + "");
+               result.setTruncated( s.isTruncated() + "");
+               
                return result;
        }
 }
index a65ac7e..8e1575e 100644 (file)
@@ -4,7 +4,6 @@ public class TweetDBObject {
        
        private long id;
 
-       private String following;
        private String date;
        private long replyStatusID;
        private long replyUserID;
@@ -54,9 +53,6 @@ public class TweetDBObject {
        public long getFollowers() {
                return followers;
        }
-       public String getFollowing() {
-               return following;
-       }
        public long getFriend() {
                return friend;
        }
@@ -156,9 +152,6 @@ public class TweetDBObject {
        public void setFollowers(long followers) {
                this.followers = followers;
        }
-       public void setFollowing(String following) {
-               this.following = following;
-       }
        public void setFriend(long friend) {
                this.friend = friend;
        }
@@ -247,8 +240,8 @@ public class TweetDBObject {
        public String toString() {
                return "TweetDBObject [contributorsEnable=" + contributorsEnable
                                + ", created=" + created + ", date=" + date + ", favorite="
-                               + favorite + ", followers=" + followers + ", following="
-                               + following + ", friend=" + friend + ", geoEnable=" + geoEnable
+                               + favorite + ", followers=" + followers 
+                               +  ", friend=" + friend + ", geoEnable=" + geoEnable
                                + ", id=" + id + ", isProtected=" + isProtected + ", lang="
                                + lang + ", location=" + location + ", name=" + name
                                + ", profileBackgroundColor=" + profileBackgroundColor
index 72179f5..6f2daa3 100644 (file)
@@ -26,10 +26,9 @@ public class TwitterLogDao {
        private Connection databaseConnection = null;
        
        //データベーステーブルの定義
-       private static final String createTableSql =
+       private static final String createTweetTableSql =
                "CREATE TABLE IF NOT EXISTS TWEET(" +
                "               id INTEGER PRIMARY KEY,"    +
-               "               following TEXT," +
                "               date TEXT," + 
                "               replyStatusID INTEGER," + 
                "               replyUserID INTEGER," + 
@@ -65,11 +64,11 @@ public class TwitterLogDao {
                "               truncated TEXT)"  ;
        
        //データ挿入SQL
-       private static final String insertDataSql = 
-               "INSERT INTO TWEET VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
+       private static final String insertTweetDataSql = 
+               "INSERT INTO TWEET VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
        
        //データ取得SQL
-       private static final String selectDataSql = 
+       private static final String selectTweetDataSql = 
                "SELECT * FROM TWEET;";
        
        /**
@@ -106,7 +105,7 @@ public class TwitterLogDao {
                Statement statement;
                try {
                        statement = this.databaseConnection.createStatement();
-                       statement.execute( createTableSql );
+                       statement.execute( createTweetTableSql );
                } catch (SQLException e) {
                        e.printStackTrace();
                }
@@ -122,9 +121,8 @@ public class TwitterLogDao {
                QueryRunner qr = new QueryRunner();
                //データ挿入
                try {
-                       qr.update(con, insertDataSql, 
+                       qr.update(con, insertTweetDataSql, 
                                        o.getId(),
-                                       o.getFollowing(),
                                        o.getDate(),
                                        o.getReplyStatusID(),
                                        o.getReplyUserID(),
@@ -160,16 +158,8 @@ public class TwitterLogDao {
                                        o.getTruncated() );
                }catch(SQLException e) {
                        //挿入ではなく更新にする
+                       e.printStackTrace();
                }
                con.close();
        }
-       
-       public static void main(String[] args) {
-               TwitterLogDao dao = new TwitterLogDao();
-               dao.connectDB();
-               
-               dao.createTable();
-               
-               dao.closeDB();
-       }
 }