mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-12 00:35:03 +00:00
Redesigned SQL interface.
This commit is contained in:
parent
4d98159398
commit
4110dcc2a9
33 changed files with 215 additions and 648 deletions
|
@ -38,7 +38,7 @@ public class SnapshotFetcher implements PersistentStoreSource {
|
|||
SortedSet<Snapshot> newSnapshots = new TreeSet<Snapshot>();
|
||||
while (getNew(newSnapshots));
|
||||
for (Snapshot snapshot : newSnapshots) {
|
||||
persistentStore.addSnapshot(projectName, snapshot.getVersionID());
|
||||
// persistentStore.addSnapshot(projectName, snapshot.getVersionID());
|
||||
}
|
||||
Util.sout("Fetched snapshots: " + newSnapshots);
|
||||
return newSnapshots;
|
||||
|
@ -58,10 +58,10 @@ public class SnapshotFetcher implements PersistentStoreSource {
|
|||
@Override
|
||||
public void initFromPersistentStore(PersistentStoreAPI persistentStore) {
|
||||
this.persistentStore = persistentStore;
|
||||
for (Integer savedVersionID : persistentStore.getVersionIDsForProjectName(projectName)) {
|
||||
snapshots.put(savedVersionID, new Snapshot(savedVersionID));
|
||||
versions.add(savedVersionID);
|
||||
}
|
||||
// for (Integer savedVersionID : persistentStore.getVersionIDsForProjectName(projectName)) {
|
||||
// snapshots.put(savedVersionID, new Snapshot(savedVersionID));
|
||||
// versions.add(savedVersionID);
|
||||
// }
|
||||
}
|
||||
|
||||
private boolean getNew(SortedSet<Snapshot> newSnapshots) throws FailedConnectionException, InvalidProjectException {
|
||||
|
|
|
@ -21,7 +21,7 @@ public class ByteBlob extends Blob {
|
|||
|
||||
@Override
|
||||
public void updatePersistentStore(PersistentStoreAPI persistentStore, AttachmentNode node) {
|
||||
persistentStore.addFileNodeBlob(node.getProjectName(), node.getFilePath(), node.isChanged(), contents);
|
||||
// persistentStore.addFileNodeBlob(node.getProjectName(), node.getFilePath(), node.isChanged(), contents);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class ExternalBlob extends Blob {
|
|||
|
||||
@Override
|
||||
public void updatePersistentStore(PersistentStoreAPI persistentStore, AttachmentNode node) {
|
||||
persistentStore.addFileNodeExternal(node.getProjectName(), node.getFilePath(), node.isChanged(), node.getURL());
|
||||
// persistentStore.addFileNodeExternal(node.getProjectName(), node.getFilePath(), node.isChanged(), node.getURL());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,11 +47,11 @@ public class BlobNode extends FileNode {
|
|||
|
||||
@Override
|
||||
public void updatePersistentStore(PersistentStoreAPI persistentStore, String projectName) {
|
||||
try {
|
||||
persistentStore.addFileNodeBlob(projectName, getFilePath(), isChanged(), getBlob().getContents());
|
||||
} catch (FailedConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// try {
|
||||
// persistentStore.addFileNodeBlob(projectName, getFilePath(), isChanged(), getBlob().getContents());
|
||||
// } catch (FailedConnectionException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
}
|
||||
|
||||
private void writeChanged(File projectAttDirectory) throws FailedConnectionException, IOException {
|
||||
|
|
|
@ -50,9 +50,9 @@ public class WLDirectoryNode implements PersistentStoreSource, PersistentStoreUp
|
|||
public void initFromPersistentStore(PersistentStoreAPI persistentStore) {
|
||||
fileIndexStore = new FileIndexStore(projectName, persistentStore);
|
||||
fileNodeTable = new HashMap<String, FileNode>();
|
||||
for (FileNode fileNode : persistentStore.getFileNodesForProjectName(projectName, fileIndexStore)) {
|
||||
fileNodeTable.put(fileNode.getFilePath(), fileNode);
|
||||
}
|
||||
// for (FileNode fileNode : persistentStore.getFileNodesForProjectName(projectName, fileIndexStore)) {
|
||||
// fileNodeTable.put(fileNode.getFilePath(), fileNode);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,7 +62,7 @@ public class WLDirectoryNode implements PersistentStoreSource, PersistentStoreUp
|
|||
}
|
||||
|
||||
private void updateFileNodeTableInPersistentStore(PersistentStoreAPI persistentStore) {
|
||||
persistentStore.deleteFileNodesForProjectName(projectName);
|
||||
// persistentStore.deleteFileNodesForProjectName(projectName);
|
||||
for (FileNode fileNode : fileNodeTable.values()) {
|
||||
fileNode.updatePersistentStore(persistentStore, projectName);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.filestore.store;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.AttachmentNode;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.BlobNode;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode;
|
||||
|
@ -50,7 +49,7 @@ public class FileIndexStore implements FileNodeIndexer, PersistentStoreSource, P
|
|||
|
||||
@Override
|
||||
public void initFromPersistentStore(PersistentStoreAPI persistentStore) {
|
||||
urlMappings = persistentStore.getURLIndexTableForProjectName(projectName);
|
||||
// urlMappings = persistentStore.getURLIndexTableForProjectName(projectName);
|
||||
}
|
||||
|
||||
public boolean hasAttachmentWithURL(String url) {
|
||||
|
@ -63,13 +62,13 @@ public class FileIndexStore implements FileNodeIndexer, PersistentStoreSource, P
|
|||
|
||||
@Override
|
||||
public void updatePersistentStore(PersistentStoreAPI persistentStore, String projectName) {
|
||||
persistentStore.deleteURLIndexesForProjectName(projectName);
|
||||
// persistentStore.deleteURLIndexesForProjectName(projectName);
|
||||
for (Entry<String, FileNode> urlMapping : urlMappings.entrySet()) {
|
||||
try {
|
||||
persistentStore.addURLIndex(projectName, urlMapping.getKey(), urlMapping.getValue().getContents());
|
||||
} catch (FailedConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// try {
|
||||
// persistentStore.addURLIndex(projectName, urlMapping.getKey(), urlMapping.getValue().getContents());
|
||||
// } catch (FailedConnectionException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,9 +42,9 @@ public class WLFileStore implements PersistentStoreSource {
|
|||
@Override
|
||||
public void initFromPersistentStore(PersistentStoreAPI persistentStore) {
|
||||
this.persistentStore = persistentStore;
|
||||
for (String projectName : persistentStore.getProjectNames()) {
|
||||
fileStore.put(projectName, new WLDirectoryNode(projectName, attDirectory, rootGitDirectory, persistentStore));
|
||||
}
|
||||
// for (String projectName : persistentStore.getProjectNames()) {
|
||||
// fileStore.put(projectName, new WLDirectoryNode(projectName, attDirectory, rootGitDirectory, persistentStore));
|
||||
// }
|
||||
}
|
||||
|
||||
public static void deleteInDirectory(File directory) {
|
||||
|
|
|
@ -11,7 +11,7 @@ import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProje
|
|||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.WLFileStore;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.PersistentStoreAPI;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.WLGBPersistentStore;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.PersistentStore;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -28,10 +28,10 @@ public class WLDataModel implements CandidateSnapshotCallback {
|
|||
|
||||
public WLDataModel(String rootGitDirectoryPath) {
|
||||
File rootGitDirectory = initRootGitDirectory(rootGitDirectoryPath);
|
||||
persistentStore = new WLGBPersistentStore(rootGitDirectory);
|
||||
projectStore = persistentStore.loadProjectStore();
|
||||
persistentStore = new PersistentStore(rootGitDirectory);
|
||||
projectStore = null;//persistentStore.loadProjectStore();
|
||||
Util.sout("Loaded projects: " + projectStore.getProjectNames().size() + ".");
|
||||
fileStore = persistentStore.loadFileStore();
|
||||
fileStore = null;//persistentStore.loadFileStore();
|
||||
Util.sout("Loaded file store and index tables.");
|
||||
List<String> excludedFromDeletion = projectStore.getProjectNames();
|
||||
excludedFromDeletion.add(".wlgb");
|
||||
|
|
|
@ -61,7 +61,7 @@ public class WLProject implements PersistentStoreSource {
|
|||
snapshots.put(versionID, new Snapshot(versionID));
|
||||
snapshotFetcher.putLatestVersion(versionID);
|
||||
latestSnapshotID = versionID;
|
||||
persistentStore.addSnapshot(name, versionID);
|
||||
// persistentStore.addSnapshot(name, versionID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,7 +32,7 @@ public class WLProjectStore implements PersistentStoreSource {
|
|||
} else {
|
||||
project = new WLProject(name, persistentStore);
|
||||
projects.put(name, project);
|
||||
persistentStore.addProject(name);
|
||||
// persistentStore.addProject(name);
|
||||
}
|
||||
return project;
|
||||
}
|
||||
|
@ -44,9 +44,9 @@ public class WLProjectStore implements PersistentStoreSource {
|
|||
@Override
|
||||
public void initFromPersistentStore(PersistentStoreAPI persistentStore) {
|
||||
this.persistentStore = persistentStore;
|
||||
for (String projectName : persistentStore.getProjectNames()) {
|
||||
projects.put(projectName, new WLProject(projectName, persistentStore));
|
||||
}
|
||||
// for (String projectName : persistentStore.getProjectNames()) {
|
||||
// projects.put(projectName, new WLProject(projectName, persistentStore));
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLiteWLDatabase;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 19/11/14.
|
||||
*/
|
||||
public class PersistentStore {
|
||||
|
||||
private final SQLiteWLDatabase database;
|
||||
|
||||
public PersistentStore(File rootGitDirectory) {
|
||||
try {
|
||||
database = new SQLiteWLDatabase(rootGitDirectory);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public void setLatestVersionForProject(String project, int versionID) {
|
||||
try {
|
||||
database.setVersionIDForProject(project, versionID);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteFilesForProject(String project, String... files) {
|
||||
try {
|
||||
database.deleteFilesForProject(project, files);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addURLIndexesForProject(String projectName, String url, String path) {
|
||||
try {
|
||||
database.addURLIndex(projectName, url, path);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getLatestVersionForProject(String project) {
|
||||
try {
|
||||
return database.getVersionIDForProjectName(project);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getPathForURLInProject(String projectName, String url) {
|
||||
try {
|
||||
return database.getPathForURLInProject(projectName, url);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.FileIndexStore;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.WLFileStore;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.WLProjectStore;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Winston on 17/11/14.
|
||||
*/
|
||||
public interface PersistentStoreAPI {
|
||||
|
||||
public WLProjectStore loadProjectStore();
|
||||
public WLFileStore loadFileStore();
|
||||
|
||||
public void addProject(String name);
|
||||
public void addSnapshot(String projectName, int versionID);
|
||||
public void addFileNodeBlob(String projectName, String fileName, boolean changed, byte[] blob);
|
||||
public void addFileNodeExternal(String projectName, String fileName, boolean changed, String url);
|
||||
public void addURLIndex(String projectName, String url, byte[] blob);
|
||||
|
||||
public List<String> getProjectNames();
|
||||
public List<Integer> getVersionIDsForProjectName(String projectName);
|
||||
public List<FileNode> getFileNodesForProjectName(String projectName, FileIndexStore fileIndexStore);
|
||||
public Map<String, FileNode> getURLIndexTableForProjectName(String projectName);
|
||||
|
||||
public void deleteFileNodesForProjectName(String projectName);
|
||||
public void deleteURLIndexesForProjectName(String projectName);
|
||||
|
||||
}
|
|
@ -5,6 +5,6 @@ package uk.ac.ic.wlgitbridge.writelatex.model.db;
|
|||
*/
|
||||
public interface PersistentStoreSource {
|
||||
|
||||
public void initFromPersistentStore(PersistentStoreAPI persistentStore);
|
||||
public void initFromPersistentStore(PersistentStore persistentStore);
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,6 @@ package uk.ac.ic.wlgitbridge.writelatex.model.db;
|
|||
*/
|
||||
public interface PersistentStoreUpdater<T> {
|
||||
|
||||
public void updatePersistentStore(PersistentStoreAPI persistentStore, T info);
|
||||
public void updatePersistentStore(PersistentStore persistentStore, T info);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,143 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.util.Util;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.FileIndexStore;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.WLFileStore;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.WLProjectStore;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLiteWLDatabase;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Winston on 19/11/14.
|
||||
*/
|
||||
public class WLGBPersistentStore implements PersistentStoreAPI {
|
||||
|
||||
private final File rootGitDirectory;
|
||||
private final SQLiteWLDatabase database;
|
||||
|
||||
public WLGBPersistentStore(File rootGitDirectory) {
|
||||
this.rootGitDirectory = rootGitDirectory;
|
||||
try {
|
||||
database = new SQLiteWLDatabase(rootGitDirectory);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WLProjectStore loadProjectStore() {
|
||||
return new WLProjectStore(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WLFileStore loadFileStore() {
|
||||
return new WLFileStore(rootGitDirectory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProject(String name) {
|
||||
try {
|
||||
database.addProject(name);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSnapshot(String projectName, int versionID) {
|
||||
try {
|
||||
database.addSnapshot(projectName, versionID);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFileNodeBlob(String projectName, String fileName, boolean changed, byte[] blob) {
|
||||
try {
|
||||
database.addFileNodeBlob(projectName, fileName, Util.booleanToInt(changed), blob);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFileNodeExternal(String projectName, String fileName, boolean changed, String url) {
|
||||
try {
|
||||
database.addFileNodeExternal(projectName, fileName, Util.booleanToInt(changed), url);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addURLIndex(String projectName, String url, byte[] blob) {
|
||||
try {
|
||||
database.addURLIndex(projectName, url, blob);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getProjectNames() {
|
||||
try {
|
||||
return database.getProjectNames();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getVersionIDsForProjectName(String projectName) {
|
||||
try {
|
||||
return database.getVersionIDsForProjectName(projectName);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileNode> getFileNodesForProjectName(String projectName, FileIndexStore fileIndexStore) {
|
||||
try {
|
||||
return database.getFileNodesForProjectName(projectName, fileIndexStore);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, FileNode> getURLIndexTableForProjectName(String projectName) {
|
||||
try {
|
||||
return database.getURLIndexTableForProjectName(projectName);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFileNodesForProjectName(String projectName) {
|
||||
try {
|
||||
database.deleteFileNodesForProjectName(projectName);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteURLIndexesForProjectName(String projectName) {
|
||||
try {
|
||||
database.deleteURLIndexesForProjectName(projectName);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +1,16 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.util.Util;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.FileIndexStore;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query.GetFileNodesForProjectNameSQLQuery;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query.GetProjectNamesSQLQuery;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query.GetURLIndexTableForProjectNameSQLQuery;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query.GetVersionIDsForProjectNameSQLQuery;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.create.CreateFileNodeTableSQLUpdate;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query.GetPathForURLInProjectSQLQuery;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query.GetLatestVersionForProjectSQLQuery;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.create.CreateProjectsTableSQLUpdate;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.create.CreateSnapshotsTableSQLUpdate;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.create.CreateURLIndexStoreSQLUpdate;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.delete.DeleteFileNodesForProjectNameSQLUpdate;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.delete.DeleteURLIndexesForProjectNameSQLUpdate;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.insert.*;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.delete.DeleteFilesForProjectSQLUpdate;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.insert.AddURLIndexSQLUpdate;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.insert.SetProjectSQLUpdate;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Winston on 17/11/14.
|
||||
|
@ -36,56 +28,29 @@ public class SQLiteWLDatabase {
|
|||
createTables();
|
||||
}
|
||||
|
||||
public void addProject(String projectName) throws SQLException {
|
||||
update(new AddProjectSQLUpdate(projectName));
|
||||
public void setVersionIDForProject(String projectName, int versionID) throws SQLException {
|
||||
update(new SetProjectSQLUpdate(projectName, versionID));
|
||||
}
|
||||
|
||||
public void addSnapshot(String projectName, int versionID) throws SQLException {
|
||||
update(new AddSnapshotSQLUpdate(projectName, versionID));
|
||||
public void addURLIndex(String projectName, String url, String path) throws SQLException {
|
||||
update(new AddURLIndexSQLUpdate(projectName, url, path));
|
||||
}
|
||||
|
||||
public void addFileNodeBlob(String projectName, String fileName, int changed, byte[] blob) throws SQLException {
|
||||
update(new AddFileNodeBlobSQLUpdate(projectName, fileName, changed, blob));
|
||||
public void deleteFilesForProject(String projectName, String... paths) throws SQLException {
|
||||
update(new DeleteFilesForProjectSQLUpdate(projectName, paths));
|
||||
}
|
||||
|
||||
public void addFileNodeExternal(String projectName, String fileName, int changed, String url) throws SQLException {
|
||||
update(new AddFileNodeExternalSQLUpdate(projectName, fileName, changed, url));
|
||||
public int getVersionIDForProjectName(String projectName) throws SQLException {
|
||||
return query(new GetLatestVersionForProjectSQLQuery(projectName));
|
||||
}
|
||||
|
||||
public void addURLIndex(String projectName, String url, byte[] blob) throws SQLException {
|
||||
update(new AddURLIndexSQLUpdate(projectName, url, blob));
|
||||
|
||||
}
|
||||
|
||||
public List<String> getProjectNames() throws SQLException {
|
||||
return query(new GetProjectNamesSQLQuery());
|
||||
}
|
||||
|
||||
public List<Integer> getVersionIDsForProjectName(String projectName) throws SQLException {
|
||||
return query(new GetVersionIDsForProjectNameSQLQuery(projectName));
|
||||
}
|
||||
|
||||
public List<FileNode> getFileNodesForProjectName(String projectName, FileIndexStore fileIndexStore) throws SQLException {
|
||||
return query(new GetFileNodesForProjectNameSQLQuery(projectName, fileIndexStore));
|
||||
}
|
||||
|
||||
public Map<String, FileNode> getURLIndexTableForProjectName(String projectName) throws SQLException {
|
||||
return query(new GetURLIndexTableForProjectNameSQLQuery(projectName));
|
||||
}
|
||||
|
||||
public void deleteFileNodesForProjectName(String projectName) throws SQLException {
|
||||
update(new DeleteFileNodesForProjectNameSQLUpdate(projectName));
|
||||
}
|
||||
|
||||
public void deleteURLIndexesForProjectName(String projectName) throws SQLException {
|
||||
update(new DeleteURLIndexesForProjectNameSQLUpdate(projectName));
|
||||
public String getPathForURLInProject(String projectName, String url) throws SQLException {
|
||||
return query(new GetPathForURLInProjectSQLQuery(projectName, url));
|
||||
}
|
||||
|
||||
private void createTables() throws SQLException {
|
||||
final SQLUpdate[] createTableUpdates = {
|
||||
new CreateProjectsTableSQLUpdate(),
|
||||
new CreateSnapshotsTableSQLUpdate(),
|
||||
new CreateFileNodeTableSQLUpdate(),
|
||||
new CreateURLIndexStoreSQLUpdate()
|
||||
};
|
||||
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.util.Util;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.AttachmentNode;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.BlobNode;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.FileIndexStore;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLQuery;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class GetFileNodesForProjectNameSQLQuery implements SQLQuery<List<FileNode>> {
|
||||
|
||||
private static final String GET_FILE_NODES_FOR_PROJECT_NAME =
|
||||
"SELECT `file_name`, `changed`, `is_blob`, `blob`, `url` FROM `file_node_table` WHERE `project_name` = ?";
|
||||
|
||||
private final String projectName;
|
||||
private final FileIndexStore fileIndexStore;
|
||||
|
||||
public GetFileNodesForProjectNameSQLQuery(String projectName, FileIndexStore fileIndexStore) {
|
||||
this.projectName = projectName;
|
||||
this.fileIndexStore = fileIndexStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileNode> processResultSet(ResultSet resultSet) throws SQLException {
|
||||
List<FileNode> fileNodes = new LinkedList<FileNode>();
|
||||
while (resultSet.next()) {
|
||||
boolean isBlob = Util.intToBoolean(resultSet.getInt("is_blob"));
|
||||
FileNode fileNode;
|
||||
String fileName = resultSet.getString("file_name");
|
||||
boolean changed = Util.intToBoolean(resultSet.getInt("changed"));
|
||||
if (isBlob) {
|
||||
fileNode = new BlobNode(fileName, changed, resultSet.getBytes("blob"));
|
||||
} else {
|
||||
fileNode = new AttachmentNode(fileName, changed, resultSet.getString("url"), fileIndexStore);
|
||||
}
|
||||
fileNodes.add(fileNode);
|
||||
}
|
||||
return fileNodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return GET_FILE_NODES_FOR_PROJECT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParametersToStatement(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, projectName);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,30 +5,28 @@ import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLQuery;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class GetVersionIDsForProjectNameSQLQuery implements SQLQuery<List<Integer>> {
|
||||
public class GetLatestVersionForProjectSQLQuery implements SQLQuery<Integer> {
|
||||
|
||||
private static final String GET_VERSION_IDS_FOR_PROJECT_NAME =
|
||||
"SELECT `version_id` FROM `snapshots` WHERE `project_name` = ?";
|
||||
"SELECT `version_id` FROM `projects` WHERE `project_name` = ?";
|
||||
|
||||
private final String projectName;
|
||||
|
||||
public GetVersionIDsForProjectNameSQLQuery(String projectName) {
|
||||
public GetLatestVersionForProjectSQLQuery(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> processResultSet(ResultSet resultSet) throws SQLException {
|
||||
List<Integer> versionIDs = new LinkedList<Integer>();
|
||||
public Integer processResultSet(ResultSet resultSet) throws SQLException {
|
||||
int versionID = 0;
|
||||
while (resultSet.next()) {
|
||||
versionIDs.add(resultSet.getInt("version_id"));
|
||||
versionID = resultSet.getInt("version_id");
|
||||
}
|
||||
return versionIDs;
|
||||
return versionID;
|
||||
}
|
||||
|
||||
@Override
|
|
@ -0,0 +1,45 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLQuery;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class GetPathForURLInProjectSQLQuery implements SQLQuery<String> {
|
||||
|
||||
private static final String GET_URL_INDEXES_FOR_PROJECT_NAME =
|
||||
"SELECT `path` FROM `url_index_store` WHERE `project_name` = ? AND `url` = ?";
|
||||
|
||||
private final String projectName;
|
||||
private final String url;
|
||||
|
||||
public GetPathForURLInProjectSQLQuery(String projectName, String url) {
|
||||
this.projectName = projectName;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String processResultSet(ResultSet resultSet) throws SQLException {
|
||||
String path = null;
|
||||
while (resultSet.next()) {
|
||||
path = resultSet.getString("path");
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return GET_URL_INDEXES_FOR_PROJECT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParametersToStatement(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, projectName);
|
||||
statement.setString(2, url);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLQuery;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class GetProjectNamesSQLQuery implements SQLQuery<List<String>> {
|
||||
|
||||
private static final String GET_PROJECT_NAMES =
|
||||
"SELECT * FROM `projects`;\n";
|
||||
|
||||
@Override
|
||||
public List<String> processResultSet(ResultSet resultSet) throws SQLException {
|
||||
List<String> projectNames = new LinkedList<String>();
|
||||
while (resultSet.next()) {
|
||||
projectNames.add(resultSet.getString("name"));
|
||||
}
|
||||
return projectNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return GET_PROJECT_NAMES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParametersToStatement(PreparedStatement statement) throws SQLException {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.AttachmentNode;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLQuery;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class GetURLIndexTableForProjectNameSQLQuery implements SQLQuery<Map<String, FileNode>> {
|
||||
|
||||
private static final String GET_URL_INDEXES_FOR_PROJECT_NAME =
|
||||
"SELECT `url`, `blob` FROM `url_index_store` WHERE `project_name` = ?";
|
||||
|
||||
private final String projectName;
|
||||
|
||||
public GetURLIndexTableForProjectNameSQLQuery(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, FileNode> processResultSet(ResultSet resultSet) throws SQLException {
|
||||
Map<String, FileNode> urlIndexTable = new HashMap<String, FileNode>();
|
||||
while (resultSet.next()) {
|
||||
String url = resultSet.getString("url");
|
||||
byte[] blob = resultSet.getBytes("blob");
|
||||
urlIndexTable.put(url, new AttachmentNode(url, blob));
|
||||
}
|
||||
return urlIndexTable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return GET_URL_INDEXES_FOR_PROJECT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParametersToStatement(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, projectName);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.create;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLUpdate;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class CreateFileNodeTableSQLUpdate implements SQLUpdate {
|
||||
|
||||
private static final String CREATE_FILE_NODE_TABLE =
|
||||
"CREATE TABLE IF NOT EXISTS `file_node_table` (\n" +
|
||||
" `project_name` varchar(10) NOT NULL DEFAULT '',\n" +
|
||||
" `file_name` varchar(255) NOT NULL DEFAULT '',\n" +
|
||||
" `changed` tinyint(1) NOT NULL,\n" +
|
||||
" `is_blob` tinyint(1) NOT NULL,\n" +
|
||||
" `blob` blob,\n" +
|
||||
" `url` varchar(128) DEFAULT NULL,\n" +
|
||||
" PRIMARY KEY (`project_name`,`file_name`),\n" +
|
||||
" CONSTRAINT `file_node_table_ibfk_1` FOREIGN KEY (`project_name`) REFERENCES `projects` (`name`) ON DELETE CASCADE ON UPDATE CASCADE\n" +
|
||||
")";
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return CREATE_FILE_NODE_TABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParametersToStatement(PreparedStatement statement) throws SQLException {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -13,6 +13,7 @@ public class CreateProjectsTableSQLUpdate implements SQLUpdate {
|
|||
private static final String CREATE_PROJECTS_TABLE =
|
||||
"CREATE TABLE IF NOT EXISTS `projects` (\n" +
|
||||
" `name` varchar(10) NOT NULL DEFAULT '',\n" +
|
||||
" `version_id` int(11) NOT NULL DEFAULT 0,\n" +
|
||||
" PRIMARY KEY (`name`)\n" +
|
||||
")";
|
||||
@Override
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.create;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLUpdate;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class CreateSnapshotsTableSQLUpdate implements SQLUpdate {
|
||||
|
||||
private static final String CREATE_SNAPSHOTS_TABLE =
|
||||
"CREATE TABLE IF NOT EXISTS `snapshots` (\n" +
|
||||
" `project_name` varchar(10) NOT NULL DEFAULT '',\n" +
|
||||
" `version_id` int(11) NOT NULL,\n" +
|
||||
" PRIMARY KEY (`project_name`,`version_id`),\n" +
|
||||
" CONSTRAINT `snapshots_ibfk_1` FOREIGN KEY (`project_name`) REFERENCES `projects` (`name`) ON DELETE CASCADE ON UPDATE CASCADE\n" +
|
||||
")";
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return CREATE_SNAPSHOTS_TABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParametersToStatement(PreparedStatement statement) throws SQLException {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -11,13 +11,16 @@ import java.sql.SQLException;
|
|||
public class CreateURLIndexStoreSQLUpdate implements SQLUpdate {
|
||||
|
||||
private static final String CREATE_URL_INDEX_STORE =
|
||||
"BEGIN;\n"+
|
||||
"CREATE TABLE IF NOT EXISTS `url_index_store` (\n"+
|
||||
" `project_name` varchar(10) NOT NULL DEFAULT '',\n"+
|
||||
" `url` varchar(128) NOT NULL,\n"+
|
||||
" `blob` blob NOT NULL,\n"+
|
||||
" `url` text NOT NULL,\n"+
|
||||
" `path` text NOT NULL,\n"+
|
||||
" PRIMARY KEY (`project_name`,`url`),\n"+
|
||||
" CONSTRAINT `url_index_store_ibfk_1` FOREIGN KEY (`project_name`) REFERENCES `projects` (`name`) ON DELETE CASCADE ON UPDATE CASCADE\n"+
|
||||
")";
|
||||
");\n"+
|
||||
"CREATE INDEX `project_path_index` ON `url_index_store`(`project_name`, `path`);\n"+
|
||||
"COMMIT;\n";
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.delete;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLUpdate;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class DeleteFileNodesForProjectNameSQLUpdate implements SQLUpdate {
|
||||
|
||||
private static final String DELETE_FILE_NODES_FOR_PROJECT_NAME =
|
||||
"DELETE FROM `file_node_table` WHERE `project_name` = ?";
|
||||
|
||||
private final String projectName;
|
||||
|
||||
public DeleteFileNodesForProjectNameSQLUpdate(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return DELETE_FILE_NODES_FOR_PROJECT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParametersToStatement(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, projectName);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,20 +8,32 @@ import java.sql.SQLException;
|
|||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class DeleteURLIndexesForProjectNameSQLUpdate implements SQLUpdate {
|
||||
public class DeleteFilesForProjectSQLUpdate implements SQLUpdate {
|
||||
|
||||
private static final String DELETE_URL_INDEXES_FOR_PROJECT_NAME =
|
||||
"DELETE FROM `url_index_store` WHERE `project_name` = ?";
|
||||
"DELETE FROM `url_index_store` WHERE `project_name` = ? AND path IN (";
|
||||
|
||||
private final String projectName;
|
||||
private final String[] paths;
|
||||
|
||||
public DeleteURLIndexesForProjectNameSQLUpdate(String projectName) {
|
||||
public DeleteFilesForProjectSQLUpdate(String projectName, String... paths) {
|
||||
this.projectName = projectName;
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return DELETE_URL_INDEXES_FOR_PROJECT_NAME;
|
||||
StringBuilder sb = new StringBuilder(DELETE_URL_INDEXES_FOR_PROJECT_NAME);
|
||||
for (int i = 0; i < paths.length; i++) {
|
||||
sb.append('\'');
|
||||
sb.append(paths[i]);
|
||||
sb.append('\'');
|
||||
if (i < paths.length - 1) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
sb.append(");\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,41 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.insert;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLUpdate;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class AddFileNodeBlobSQLUpdate implements SQLUpdate {
|
||||
|
||||
private static final String ADD_FILE_NODE_BLOB =
|
||||
"INSERT INTO `file_node_table` (`project_name`, `file_name`, `changed`, `is_blob`, `blob`, `url`) VALUES (?, ?, ?, '1', ?, NULL);\n";
|
||||
|
||||
private final String projectName;
|
||||
private final String fileName;
|
||||
private final int changed;
|
||||
private final byte[] blob;
|
||||
|
||||
public AddFileNodeBlobSQLUpdate(String projectName, String fileName, int changed, byte[] blob) {
|
||||
this.projectName = projectName;
|
||||
this.fileName = fileName;
|
||||
this.changed = changed;
|
||||
this.blob = blob;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return ADD_FILE_NODE_BLOB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParametersToStatement(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, projectName);
|
||||
statement.setString(2, fileName);
|
||||
statement.setInt(3, changed);
|
||||
statement.setBytes(4, blob);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.insert;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLUpdate;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class AddFileNodeExternalSQLUpdate implements SQLUpdate {
|
||||
|
||||
private static final String ADD_FILE_NODE_EXTERNAL =
|
||||
"INSERT INTO `file_node_table` (`project_name`, `file_name`, `changed`, `is_blob`, `blob`, `url`) VALUES (?, ?, ?, '0', NULL, ?);\n";
|
||||
|
||||
private final String projectName;
|
||||
private final String fileName;
|
||||
private final int changed;
|
||||
private final String url;
|
||||
|
||||
public AddFileNodeExternalSQLUpdate(String projectName, String fileName, int changed, String url) {
|
||||
this.projectName = projectName;
|
||||
this.fileName = fileName;
|
||||
this.changed = changed;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return ADD_FILE_NODE_EXTERNAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParametersToStatement(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, projectName);
|
||||
statement.setString(2, fileName);
|
||||
statement.setInt(3, changed);
|
||||
statement.setString(4, url);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.insert;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.SQLUpdate;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class AddProjectSQLUpdate implements SQLUpdate {
|
||||
|
||||
private static final String ADD_PROJECT =
|
||||
"INSERT INTO `projects` (`name`) VALUES (?);\n";
|
||||
|
||||
private final String projectName;
|
||||
|
||||
public AddProjectSQLUpdate(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return ADD_PROJECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParametersToStatement(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, projectName);
|
||||
}
|
||||
|
||||
}
|
|
@ -11,16 +11,16 @@ import java.sql.SQLException;
|
|||
public class AddURLIndexSQLUpdate implements SQLUpdate {
|
||||
|
||||
private static final String ADD_URL_INDEX =
|
||||
"INSERT INTO `url_index_store` (`project_name`, `url`, `blob`) VALUES (?, ?, ?);\n";
|
||||
"INSERT INTO `url_index_store` (`project_name`, `url`, `path`) VALUES (?, ?, ?);\n";
|
||||
|
||||
private final String projectName;
|
||||
private final String url;
|
||||
private final byte[] blob;
|
||||
private final String path;
|
||||
|
||||
public AddURLIndexSQLUpdate(String projectName, String url, byte[] blob) {
|
||||
public AddURLIndexSQLUpdate(String projectName, String url, String path) {
|
||||
this.projectName = projectName;
|
||||
this.url = url;
|
||||
this.blob = blob;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +32,7 @@ public class AddURLIndexSQLUpdate implements SQLUpdate {
|
|||
public void addParametersToStatement(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, projectName);
|
||||
statement.setString(2, url);
|
||||
statement.setBytes(3, blob);
|
||||
statement.setString(3, path);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,22 +8,22 @@ import java.sql.SQLException;
|
|||
/**
|
||||
* Created by Winston on 20/11/14.
|
||||
*/
|
||||
public class AddSnapshotSQLUpdate implements SQLUpdate {
|
||||
public class SetProjectSQLUpdate implements SQLUpdate {
|
||||
|
||||
private static final String ADD_SNAPSHOT =
|
||||
"INSERT INTO `snapshots` (`project_name`, `version_id`) VALUES (?, ?);\n";
|
||||
private static final String SET_PROJECT =
|
||||
"INSERT OR REPLACE INTO `projects`(`name`, `version_id`) VALUES (?, ?);\n";
|
||||
|
||||
private final String projectName;
|
||||
private final int versionID;
|
||||
|
||||
public AddSnapshotSQLUpdate(String projectName, int versionID) {
|
||||
public SetProjectSQLUpdate(String projectName, int versionID) {
|
||||
this.projectName = projectName;
|
||||
this.versionID = versionID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQL() {
|
||||
return ADD_SNAPSHOT;
|
||||
return SET_PROJECT;
|
||||
}
|
||||
|
||||
@Override
|
|
@ -0,0 +1,14 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql.update.delete;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DeleteFilesForProjectSQLUpdateTest {
|
||||
|
||||
@Test
|
||||
public void testGetSQL() {
|
||||
DeleteFilesForProjectSQLUpdate update = new DeleteFilesForProjectSQLUpdate("projname", "path1", "path2");
|
||||
assertEquals("DELETE FROM `url_index_store` WHERE `project_name` = ? AND path IN ('path1', 'path2');\n", update.getSQL());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue