Search in sources :

Example 56 with PreparedStatement

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);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 57 with PreparedStatement

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);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) MultiChunkEntry(org.syncany.database.MultiChunkEntry)

Example 58 with PreparedStatement

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();
}
Also used : PreparedStatement(java.sql.PreparedStatement) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) MultiChunkEntry(org.syncany.database.MultiChunkEntry)

Example 59 with PreparedStatement

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();
}
Also used : PreparedStatement(java.sql.PreparedStatement)

Example 60 with PreparedStatement

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);
    }
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) SQLException(java.sql.SQLException) FileVersion(org.syncany.database.FileVersion) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) PartialFileHistory(org.syncany.database.PartialFileHistory)

Aggregations

PreparedStatement (java.sql.PreparedStatement)6623 ResultSet (java.sql.ResultSet)4065 SQLException (java.sql.SQLException)3538 Connection (java.sql.Connection)2806 Test (org.junit.Test)1103 ArrayList (java.util.ArrayList)963 Properties (java.util.Properties)743 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)345 Statement (java.sql.Statement)273 Timestamp (java.sql.Timestamp)260 DatabaseException (net.jforum.exceptions.DatabaseException)254 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)251 HashMap (java.util.HashMap)209 BigDecimal (java.math.BigDecimal)207 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)174 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)165 List (java.util.List)150 IOException (java.io.IOException)145 Date (java.util.Date)133 Date (java.sql.Date)126