Browse Source

EveApi no longer depends on a SQL connection

master
Chris Smith 15 years ago
parent
commit
6c7b81e4bf
2 changed files with 21 additions and 23 deletions
  1. 9
    23
      src/uk/co/md87/evetool/api/EveApi.java
  2. 12
    0
      src/uk/co/md87/evetool/api/io/DBCache.java

+ 9
- 23
src/uk/co/md87/evetool/api/EveApi.java View File

@@ -22,18 +22,16 @@
22 22
 
23 23
 package uk.co.md87.evetool.api;
24 24
 
25
-import java.sql.Connection;
26 25
 import java.util.HashMap;
27 26
 import java.util.Map;
28 27
 import java.util.logging.Level;
29 28
 import java.util.logging.Logger;
30 29
 
30
+import uk.co.md87.evetool.api.io.ApiCache;
31 31
 import uk.co.md87.evetool.api.io.ApiDownloader;
32
-import uk.co.md87.evetool.api.io.DBCache;
33 32
 import uk.co.md87.evetool.api.parser.ApiElement;
34 33
 import uk.co.md87.evetool.api.parser.ApiParser;
35 34
 import uk.co.md87.evetool.api.parser.ApiResult;
36
-import uk.co.md87.evetool.api.util.TableCreator;
37 35
 import uk.co.md87.evetool.api.wrappers.CertificateTree;
38 36
 import uk.co.md87.evetool.api.wrappers.CharacterList;
39 37
 import uk.co.md87.evetool.api.wrappers.CharacterSheet;
@@ -50,23 +48,17 @@ import uk.co.md87.evetool.api.wrappers.SkillList;
50 48
  */
51 49
 public class EveApi implements Cloneable {
52 50
 
53
-    /** SQL tables required by the API. */
54
-    private static final String[] TABLES = {"PageCache"};
55
-
56
-    /** Whether or not tables have been checked. */
57
-    private static boolean checkedTables = false;
58
-
59 51
     /** Logger to use for this class. */
60 52
     private static final Logger LOGGER = Logger.getLogger(EveApi.class.getName());
61 53
 
62 54
     /** Date format for dates returned by the API. */
63 55
     public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
64 56
 
65
-    /** The database connection to use. */
66
-    private final Connection conn;
67
-
68 57
     /** The downloader to use. */
69 58
     private final ApiDownloader downloader;
59
+
60
+    /** The cache to use. */
61
+    private final ApiCache cache;
70 62
     
71 63
     /** The client's user ID, if specified. */
72 64
     private int userID;
@@ -81,17 +73,11 @@ public class EveApi implements Cloneable {
81 73
      * Creates a new instance of the EVE API client using the specified database
82 74
      * connection.
83 75
      *
84
-     * @param sqlConnection A connection to a database to use
76
+     * @param cache The Cache implementation to use.
85 77
      */
86
-    public EveApi(final Connection sqlConnection) {
87
-        this.conn = sqlConnection;
88
-
89
-        if (!checkedTables) {
90
-            new TableCreator(conn, "/uk/co/md87/evetool/api/db/", TABLES).checkTables();
91
-            checkedTables = true;
92
-        }
93
-
94
-        this.downloader = new ApiDownloader(new DBCache(conn), new ApiParser());
78
+    public EveApi(final ApiCache cache) {
79
+        this.cache = cache;
80
+        this.downloader = new ApiDownloader(cache, new ApiParser());
95 81
     }
96 82
 
97 83
     /**
@@ -247,7 +233,7 @@ public class EveApi implements Cloneable {
247 233
     /** {@inheritDoc} */
248 234
     @Override
249 235
     public EveApi clone() {
250
-        final EveApi copy = new EveApi(conn);
236
+        final EveApi copy = new EveApi(cache);
251 237
         copy.setApiKey(apiKey);
252 238
         copy.setUserID(userID);
253 239
         copy.setCharID(charID);

+ 12
- 0
src/uk/co/md87/evetool/api/io/DBCache.java View File

@@ -33,6 +33,7 @@ import java.util.Map;
33 33
 import java.util.logging.Level;
34 34
 import java.util.logging.Logger;
35 35
 import javax.sql.rowset.serial.SerialClob;
36
+import uk.co.md87.evetool.api.util.TableCreator;
36 37
 
37 38
 /**
38 39
  * Implements a cache for the API using a SQL database.
@@ -44,6 +45,12 @@ public class DBCache implements ApiCache {
44 45
     /** A logger for this class. */
45 46
     private static final Logger LOGGER = Logger.getLogger(DBCache.class.getName());
46 47
 
48
+    /** SQL tables required by the API. */
49
+    private static final String[] TABLES = {"PageCache"};
50
+
51
+    /** Whether or not tables have been checked. */
52
+    private static boolean checkedTables = false;
53
+
47 54
     /** The database connection to use. */
48 55
     private final Connection conn;
49 56
 
@@ -64,6 +71,11 @@ public class DBCache implements ApiCache {
64 71
      */
65 72
     public DBCache(final Connection conn) {
66 73
         this.conn = conn;
74
+
75
+        if (!checkedTables) {
76
+            new TableCreator(conn, "/uk/co/md87/evetool/api/db/", TABLES).checkTables();
77
+            checkedTables = true;
78
+        }
67 79
         
68 80
         try {
69 81
             conn.setAutoCommit(false);

Loading…
Cancel
Save