OSDN Git Service

Txxxxx
[traindelaybot/source.git] / workspace / .metadata / .plugins / org.eclipse.core.resources / .history / b1 / 804be6242e7200111835fa7adce7cfd2
diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/b1/804be6242e7200111835fa7adce7cfd2 b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/b1/804be6242e7200111835fa7adce7cfd2
new file mode 100644 (file)
index 0000000..66969d8
--- /dev/null
@@ -0,0 +1,69 @@
+package com.yuji.tdb.db;\r
+\r
+import javax.jdo.PersistenceManager;\r
+\r
+public class KeyValueDao {\r
+       public static final String KEY_CONSUMER_KEY = "CONSUMER_KEY";\r
+       public static final String KEY_CONSUMER_SECRET = "CONSUMER_SECRET";\r
+       public static final String KEY_REQUEST_TOKEN = "REQUEST_TOKEN";\r
+       public static final String KEY_REQUEST_TOKEN_SECRET = "REQUEST_TOKEN_SECRET";\r
+       public static final String KEY_ACCESS_TOKEN = "ACCESS_TOKEN";\r
+       public static final String KEY_ACCESS_TOKEN_SECRET = "ACCESS_TOKEN_SECRET";\r
+\r
+       public static final String KEY_SEARCH_PERIOD = "SEARCH_PERIOD";\r
+       public static final String KEY_TWIT_PERIOD = "TWIT_PERIOD";\r
+       public static final String KEY_TWIT_TIME = "TWIT_TIME_";\r
+\r
+       private static KeyValueDao instance = null;\r
+       private PersistenceManager pm = PMFactory.get().getPersistenceManager();\r
+               \r
+       public static KeyValueDao getInstance(){\r
+               if (instance == null){\r
+                       instance = new KeyValueDao();\r
+               }\r
+               return instance;\r
+       }\r
+       \r
+       private KeyValueDao(){\r
+               \r
+       }\r
+       \r
+       public String get(String key){\r
+               KeyValue keyValue = pm.getObjectById(KeyValue.class, key);\r
+               if (keyValue == null){\r
+                       return null;\r
+               }\r
+               return keyValue.getValue();\r
+       }\r
+       \r
+       public int getInt(String key){\r
+               String value = get(key);\r
+               return Integer.valueOf(value).intValue();\r
+       }\r
+       \r
+       public void put(String key, String value){\r
+               KeyValue keyValue = new KeyValue(key, value);\r
+               pm.makePersistent(keyValue);\r
+       }\r
+\r
+       public void put(String key, int value){\r
+               put(key, String.valueOf(value));\r
+       }\r
+\r
+       public String get(String key, String initValue){\r
+               String value = get(key);\r
+               if (value == null){\r
+                       put(key, initValue);\r
+                       value = initValue;\r
+               }\r
+               return value;\r
+       }\r
+\r
+       public int getInt(String key, int initValue){\r
+               String value = get(key);\r
+               if (value == null){\r
+                       put(key, initValue);\r
+               }\r
+               return Integer.valueOf(value).intValue();\r
+       }\r
+}\r