use of org.datanucleus.store.rdbms.SQLController in project datanucleus-rdbms by datanucleus.
the class SequenceTable method deleteSequence.
/**
* Method to delete a sequence.
* @param sequenceName Name of the sequence
* @param conn Connection to the datastore
* @throws SQLException Thrown when an error occurs deleting the schema.
*/
public void deleteSequence(String sequenceName, ManagedConnection conn) throws SQLException {
PreparedStatement ps = null;
SQLController sqlControl = storeMgr.getSQLController();
try {
ps = sqlControl.getStatementForUpdate(conn, deleteStmt, false);
ps.setString(1, sequenceName);
sqlControl.executeStatementUpdate(null, conn, deleteStmt, ps, true);
// TODO : handle any warning messages
} finally {
if (ps != null) {
sqlControl.closeStatement(conn, ps);
}
}
}
use of org.datanucleus.store.rdbms.SQLController in project datanucleus-rdbms by datanucleus.
the class SchemaTable method deleteAllClasses.
/**
* Method to delete all classes from the SchemaTable.
* This is called when DataNucleus is required to clean out its supported classes
* (and hence DB table).
*
* @param conn Connection to the datastore
* @throws SQLException Thrown when an error occurs deleting the schema.
*/
public void deleteAllClasses(ManagedConnection conn) throws SQLException {
SQLController sqlControl = storeMgr.getSQLController();
PreparedStatement ps = sqlControl.getStatementForUpdate(conn, deleteAllStmt, false);
try {
sqlControl.executeStatementUpdate(null, conn, deleteAllStmt, ps, true);
// TODO : handle any warning messages
} finally {
sqlControl.closeStatement(conn, ps);
}
}
use of org.datanucleus.store.rdbms.SQLController in project datanucleus-rdbms by datanucleus.
the class SchemaTable method deleteClass.
/**
* Method to delete a class from the SchemaTable.
* This is called when DataNucleus is required to clean out support for a particular class.
* @param class_name Name of class to delete
* @param conn Connection to the datastore
* @throws SQLException Thrown when an error occurs deleting the schema.
*/
public void deleteClass(String class_name, ManagedConnection conn) throws SQLException {
SQLController sqlControl = storeMgr.getSQLController();
PreparedStatement ps = sqlControl.getStatementForUpdate(conn, deleteStmt, false);
try {
ps.setString(1, class_name);
sqlControl.executeStatementUpdate(null, conn, deleteStmt, ps, true);
// TODO : handle any warning messages
} finally {
sqlControl.closeStatement(conn, ps);
}
}
use of org.datanucleus.store.rdbms.SQLController in project datanucleus-rdbms by datanucleus.
the class DatastoreUUIDHexGenerator method reserveBlock.
/**
* Reserve a block of ids.
* @param size Block size
* @return The reserved block
*/
protected synchronized ValueGenerationBlock<String> reserveBlock(long size) {
if (size < 1) {
return null;
}
List<String> oids = new ArrayList<>();
try {
ManagedConnection mconn = connectionProvider.retrieveConnection();
PreparedStatement ps = null;
ResultSet rs = null;
RDBMSStoreManager rdbmsMgr = (RDBMSStoreManager) storeMgr;
SQLController sqlControl = rdbmsMgr.getSQLController();
try {
// Find the next ID from the database
DatastoreAdapter dba = rdbmsMgr.getDatastoreAdapter();
String stmt = dba.getSelectNewUUIDStmt();
ps = sqlControl.getStatementForQuery(mconn, stmt);
for (int i = 1; i < size; i++) {
rs = sqlControl.executeStatementQuery(null, mconn, stmt, ps);
if (rs.next()) {
oids.add(rs.getString(1));
}
}
} catch (SQLException e) {
throw new ValueGenerationException(Localiser.msg("040008", e.getMessage()));
} finally {
try {
if (rs != null) {
rs.close();
}
if (ps != null) {
sqlControl.closeStatement(mconn, ps);
}
} catch (SQLException e) {
// non-recoverable error
}
}
} finally {
connectionProvider.releaseConnection();
}
return new ValueGenerationBlock(oids);
}
use of org.datanucleus.store.rdbms.SQLController in project datanucleus-rdbms by datanucleus.
the class SequenceTable method incrementSequence.
/**
* Method to increment a sequence
* @param conn Connection to the datastore
* @throws SQLException Thrown when an error occurs incrementing the sequence.
*/
private void incrementSequence(String sequenceName, long incrementBy, ManagedConnection conn) throws SQLException {
PreparedStatement ps = null;
SQLController sqlControl = storeMgr.getSQLController();
try {
ps = sqlControl.getStatementForUpdate(conn, incrementByStmt, false);
nextValMapping.setLong(null, ps, new int[] { 1 }, incrementBy);
sequenceNameMapping.setString(null, ps, new int[] { 2 }, sequenceName);
sqlControl.executeStatementUpdate(null, conn, incrementByStmt, ps, true);
// TODO : handle any warning messages
} finally {
if (ps != null) {
sqlControl.closeStatement(conn, ps);
}
}
}
Aggregations