diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/WLDataModel.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/WLDataModel.java index 84b667ebec..866fc627f4 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/WLDataModel.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/WLDataModel.java @@ -13,9 +13,7 @@ import uk.ac.ic.wlgitbridge.writelatex.model.db.Database; import java.io.File; import java.io.IOException; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * Created by Winston on 06/11/14. @@ -23,13 +21,13 @@ import java.util.Map; public class WLDataModel implements CandidateSnapshotCallback { private final Database db; - private final Map projects; + private final WLProjectStore projectStore; private final WLFileStore fileStore; public WLDataModel(String rootGitDirectoryPath) { File rootGitDirectory = initRootGitDirectory(rootGitDirectoryPath); db = new Database(rootGitDirectory); - projects = new HashMap(); + projectStore = new WLProjectStore(); fileStore = new WLFileStore(rootGitDirectory); } @@ -38,14 +36,7 @@ public class WLDataModel implements CandidateSnapshotCallback { } public WLProject getProjectWithName(String name) { - WLProject project; - if (projects.containsKey(name)) { - project = projects.get(name); - } else { - project = new WLProject(name); - projects.put(name, project); - } - return project; + return projectStore.getProjectWithName(name); } public CandidateSnapshot createCandidateSnapshotFromProjectWithContents(String projectName, RawDirectoryContents directoryContents, String hostname) throws SnapshotPostException, IOException, FailedConnectionException { diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/WLProjectStore.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/WLProjectStore.java new file mode 100644 index 0000000000..8532fae3cc --- /dev/null +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/WLProjectStore.java @@ -0,0 +1,28 @@ +package uk.ac.ic.wlgitbridge.writelatex.model; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by Winston on 17/11/14. + */ +public class WLProjectStore { + + private final Map projects; + + public WLProjectStore() { + projects = new HashMap(); + } + + public WLProject getProjectWithName(String name) { + WLProject project; + if (projects.containsKey(name)) { + project = projects.get(name); + } else { + project = new WLProject(name); + projects.put(name, project); + } + return project; + } + +} diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/db/Database.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/db/Database.java index e0d86bfa52..d64d8b9033 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/db/Database.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/db/Database.java @@ -11,12 +11,13 @@ import java.sql.Statement; public class Database { public Database(File rootGitDirectory) { + File databaseFile = new File(rootGitDirectory, "/.wlgb/wlgb.db"); System.out.println("Loading data..."); Connection c = null; Statement stmt = null; try { Class.forName("org.sqlite.JDBC"); - c = DriverManager.getConnection("jdbc:sqlite:" + rootGitDirectory.getAbsolutePath() + "/.wlgb/wlgb.db"); + c = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getAbsolutePath()); stmt = c.createStatement(); String sql = "CREATE TABLE IF NOT EXISTS COMPANY " +