|
|
@@ -1,5 +1,6 @@
|
|
|
package uk.ac.ic.wlgitbridge.data.model.db.sql;
|
|
|
|
|
|
+import com.google.api.client.repackaged.com.google.common.base.Preconditions;
|
|
|
import uk.ac.ic.wlgitbridge.data.model.db.sql.query.GetLatestVersionForProjectSQLQuery;
|
|
|
import uk.ac.ic.wlgitbridge.data.model.db.sql.query.GetPathForURLInProjectSQLQuery;
|
|
|
import uk.ac.ic.wlgitbridge.data.model.db.sql.query.GetProjectNamesSQLQuery;
|
|
|
@@ -9,7 +10,6 @@ import uk.ac.ic.wlgitbridge.data.model.db.sql.update.create.CreateURLIndexStoreS
|
|
|
import uk.ac.ic.wlgitbridge.data.model.db.sql.update.delete.DeleteFilesForProjectSQLUpdate;
|
|
|
import uk.ac.ic.wlgitbridge.data.model.db.sql.update.insert.AddURLIndexSQLUpdate;
|
|
|
import uk.ac.ic.wlgitbridge.data.model.db.sql.update.insert.SetProjectSQLUpdate;
|
|
|
-import uk.ac.ic.wlgitbridge.util.Log;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.sql.*;
|
|
|
@@ -22,36 +22,54 @@ public class SQLiteWLDatabase {
|
|
|
|
|
|
private final Connection connection;
|
|
|
|
|
|
- public SQLiteWLDatabase(File rootGitDirectory) throws SQLException, ClassNotFoundException {
|
|
|
- File databaseFile = new File(rootGitDirectory, "/.wlgb/wlgb.db");
|
|
|
- File dotWlgbDir = databaseFile.getParentFile();
|
|
|
- if (!dotWlgbDir.exists()) {
|
|
|
- if (!dotWlgbDir.mkdirs()) {
|
|
|
- Log.error("{} directory didn't exist, and unable to create. Check your permissions", dotWlgbDir.getAbsolutePath());
|
|
|
- }
|
|
|
- }
|
|
|
+ public SQLiteWLDatabase(
|
|
|
+ File dbFile
|
|
|
+ ) throws SQLException, ClassNotFoundException {
|
|
|
+ File parentDir = dbFile.getParentFile();
|
|
|
+ Preconditions.checkState(
|
|
|
+ parentDir.exists() || parentDir.mkdirs(),
|
|
|
+ parentDir.getAbsolutePath() + " directory didn't exist, " +
|
|
|
+ "and unable to create. Check your permissions."
|
|
|
+ );
|
|
|
Class.forName("org.sqlite.JDBC");
|
|
|
- connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getAbsolutePath());
|
|
|
+ connection = DriverManager.getConnection(
|
|
|
+ "jdbc:sqlite:" + dbFile.getAbsolutePath()
|
|
|
+ );
|
|
|
createTables();
|
|
|
}
|
|
|
|
|
|
- public void setVersionIDForProject(String projectName, int versionID) throws SQLException {
|
|
|
+ public void setVersionIDForProject(
|
|
|
+ String projectName,
|
|
|
+ int versionID
|
|
|
+ ) throws SQLException {
|
|
|
update(new SetProjectSQLUpdate(projectName, versionID));
|
|
|
}
|
|
|
|
|
|
- public void addURLIndex(String projectName, String url, String path) throws SQLException {
|
|
|
+ public void addURLIndex(
|
|
|
+ String projectName,
|
|
|
+ String url,
|
|
|
+ String path
|
|
|
+ ) throws SQLException {
|
|
|
update(new AddURLIndexSQLUpdate(projectName, url, path));
|
|
|
}
|
|
|
|
|
|
- public void deleteFilesForProject(String projectName, String... paths) throws SQLException {
|
|
|
+ public void deleteFilesForProject(
|
|
|
+ String projectName,
|
|
|
+ String... paths
|
|
|
+ ) throws SQLException {
|
|
|
update(new DeleteFilesForProjectSQLUpdate(projectName, paths));
|
|
|
}
|
|
|
|
|
|
- public int getVersionIDForProjectName(String projectName) throws SQLException {
|
|
|
+ public int getVersionIDForProjectName(
|
|
|
+ String projectName
|
|
|
+ ) throws SQLException {
|
|
|
return query(new GetLatestVersionForProjectSQLQuery(projectName));
|
|
|
}
|
|
|
|
|
|
- public String getPathForURLInProject(String projectName, String url) throws SQLException {
|
|
|
+ public String getPathForURLInProject(
|
|
|
+ String projectName,
|
|
|
+ String url
|
|
|
+ ) throws SQLException {
|
|
|
return query(new GetPathForURLInProjectSQLQuery(projectName, url));
|
|
|
}
|
|
|
|
|
|
@@ -59,6 +77,17 @@ public class SQLiteWLDatabase {
|
|
|
return query(new GetProjectNamesSQLQuery());
|
|
|
}
|
|
|
|
|
|
+ public String getOldestUnswappedProject() throws SQLException {
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setLastAccessedTime(
|
|
|
+ String projectName,
|
|
|
+ Timestamp time
|
|
|
+ ) throws SQLException {
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
+ }
|
|
|
+
|
|
|
private void createTables() throws SQLException {
|
|
|
final SQLUpdate[] createTableUpdates = {
|
|
|
new CreateProjectsTableSQLUpdate(),
|