mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Moved projects table into WLProjectStore class.
This commit is contained in:
parent
5d1c9d436a
commit
1d4f856832
3 changed files with 33 additions and 13 deletions
|
@ -13,9 +13,7 @@ import uk.ac.ic.wlgitbridge.writelatex.model.db.Database;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Winston on 06/11/14.
|
* Created by Winston on 06/11/14.
|
||||||
|
@ -23,13 +21,13 @@ import java.util.Map;
|
||||||
public class WLDataModel implements CandidateSnapshotCallback {
|
public class WLDataModel implements CandidateSnapshotCallback {
|
||||||
|
|
||||||
private final Database db;
|
private final Database db;
|
||||||
private final Map<String, WLProject> projects;
|
private final WLProjectStore projectStore;
|
||||||
private final WLFileStore fileStore;
|
private final WLFileStore fileStore;
|
||||||
|
|
||||||
public WLDataModel(String rootGitDirectoryPath) {
|
public WLDataModel(String rootGitDirectoryPath) {
|
||||||
File rootGitDirectory = initRootGitDirectory(rootGitDirectoryPath);
|
File rootGitDirectory = initRootGitDirectory(rootGitDirectoryPath);
|
||||||
db = new Database(rootGitDirectory);
|
db = new Database(rootGitDirectory);
|
||||||
projects = new HashMap<String, WLProject>();
|
projectStore = new WLProjectStore();
|
||||||
fileStore = new WLFileStore(rootGitDirectory);
|
fileStore = new WLFileStore(rootGitDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,14 +36,7 @@ public class WLDataModel implements CandidateSnapshotCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
public WLProject getProjectWithName(String name) {
|
public WLProject getProjectWithName(String name) {
|
||||||
WLProject project;
|
return projectStore.getProjectWithName(name);
|
||||||
if (projects.containsKey(name)) {
|
|
||||||
project = projects.get(name);
|
|
||||||
} else {
|
|
||||||
project = new WLProject(name);
|
|
||||||
projects.put(name, project);
|
|
||||||
}
|
|
||||||
return project;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CandidateSnapshot createCandidateSnapshotFromProjectWithContents(String projectName, RawDirectoryContents directoryContents, String hostname) throws SnapshotPostException, IOException, FailedConnectionException {
|
public CandidateSnapshot createCandidateSnapshotFromProjectWithContents(String projectName, RawDirectoryContents directoryContents, String hostname) throws SnapshotPostException, IOException, FailedConnectionException {
|
||||||
|
|
|
@ -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<String, WLProject> projects;
|
||||||
|
|
||||||
|
public WLProjectStore() {
|
||||||
|
projects = new HashMap<String, WLProject>();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -11,12 +11,13 @@ import java.sql.Statement;
|
||||||
public class Database {
|
public class Database {
|
||||||
|
|
||||||
public Database(File rootGitDirectory) {
|
public Database(File rootGitDirectory) {
|
||||||
|
File databaseFile = new File(rootGitDirectory, "/.wlgb/wlgb.db");
|
||||||
System.out.println("Loading data...");
|
System.out.println("Loading data...");
|
||||||
Connection c = null;
|
Connection c = null;
|
||||||
Statement stmt = null;
|
Statement stmt = null;
|
||||||
try {
|
try {
|
||||||
Class.forName("org.sqlite.JDBC");
|
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();
|
stmt = c.createStatement();
|
||||||
String sql = "CREATE TABLE IF NOT EXISTS COMPANY " +
|
String sql = "CREATE TABLE IF NOT EXISTS COMPANY " +
|
||||||
|
|
Loading…
Reference in a new issue