use of java.sql.PreparedStatement in project playn by threerings.
the class RoboStorage method getItem.
@Override
public String getItem(String key) {
try {
String sql = "select DataValue from Data where DataKey = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, key);
ResultSet rs = stmt.executeQuery();
String result = null;
while (rs.next()) {
result = rs.getString(1);
}
return result;
}
} catch (SQLException sqe) {
throw new RuntimeException("getItem(" + key + ") failed", sqe);
}
}
use of java.sql.PreparedStatement in project syncany by syncany.
the class MultiChunkSqlDao method writeMultiChunks.
public void writeMultiChunks(Connection connection, long databaseVersionId, Collection<MultiChunkEntry> multiChunks) throws SQLException {
for (MultiChunkEntry multiChunk : multiChunks) {
PreparedStatement preparedStatement = getStatement(connection, "multichunk.insert.all.writeMultiChunks.sql");
preparedStatement.setString(1, multiChunk.getId().toString());
preparedStatement.setLong(2, databaseVersionId);
preparedStatement.setLong(3, multiChunk.getSize());
preparedStatement.executeUpdate();
preparedStatement.close();
writeMultiChunkRefs(connection, multiChunk);
}
}
use of java.sql.PreparedStatement in project syncany by syncany.
the class MultiChunkSqlDao method writeMuddyMultiChunks.
public void writeMuddyMultiChunks(Map<DatabaseVersionHeader, Collection<MultiChunkEntry>> muddyMultiChunksPerDatabaseVersion) throws SQLException {
PreparedStatement preparedStatement = getStatement("multichunk_muddy.insert.muddy.writeMuddyMultiChunks.sql");
for (DatabaseVersionHeader muddyDatabaseVersionHeader : muddyMultiChunksPerDatabaseVersion.keySet()) {
Collection<MultiChunkEntry> muddyMultiChunks = muddyMultiChunksPerDatabaseVersion.get(muddyDatabaseVersionHeader);
for (MultiChunkEntry muddyMultiChunk : muddyMultiChunks) {
String multiChunkIdStr = muddyMultiChunk.getId().toString();
String clientName = muddyDatabaseVersionHeader.getClient();
Long clientVersion = muddyDatabaseVersionHeader.getVectorClock().getClock(clientName);
preparedStatement.setString(1, multiChunkIdStr);
preparedStatement.setString(2, clientName);
preparedStatement.setLong(3, clientVersion);
preparedStatement.addBatch();
}
}
preparedStatement.executeBatch();
preparedStatement.close();
}
use of java.sql.PreparedStatement in project syncany by syncany.
the class MultiChunkSqlDao method removeUnreferencedMultiChunkChunkRefs.
private void removeUnreferencedMultiChunkChunkRefs() throws SQLException {
PreparedStatement preparedStatement = getStatement("multichunk.delete.all.removeUnreferencedMultiChunkChunkRefs.sql");
preparedStatement.executeUpdate();
preparedStatement.close();
}
use of java.sql.PreparedStatement in project syncany by syncany.
the class FileHistorySqlDao method getFileHistoriesWithLastVersion.
public List<PartialFileHistory> getFileHistoriesWithLastVersion() {
List<PartialFileHistory> fileHistories = new ArrayList<PartialFileHistory>();
try (PreparedStatement preparedStatement = getStatement("filehistory.select.master.getFileHistoriesWithLastVersion.sql")) {
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id"));
FileVersion lastFileVersion = fileVersionDao.createFileVersionFromRow(resultSet);
PartialFileHistory fileHistory = new PartialFileHistory(fileHistoryId);
fileHistory.addFileVersion(lastFileVersion);
fileHistories.add(fileHistory);
}
}
return fileHistories;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Aggregations