use of org.datanucleus.store.valuegenerator.ValueGenerationException in project datanucleus-rdbms by datanucleus.
the class TableGenerator method repositoryExists.
/**
* Method to return if the repository already exists.
* @return Whether the repository exists
*/
protected boolean repositoryExists() {
if (repositoryExists) {
return true;
} else if (storeMgr.getBooleanProperty(RDBMSPropertyNames.PROPERTY_RDBMS_OMIT_DATABASEMETADATA_GETCOLUMNS)) {
// Assumed to exist if ignoring DMD.getColumns()
repositoryExists = true;
return true;
}
try {
if (sequenceTable == null) {
initialiseSequenceTable();
}
sequenceTable.exists((Connection) connection.getConnection(), true);
repositoryExists = true;
return true;
} catch (SQLException sqle) {
throw new ValueGenerationException("Exception thrown calling table.exists() for " + sequenceTable, sqle);
}
}
use of org.datanucleus.store.valuegenerator.ValueGenerationException 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.valuegenerator.ValueGenerationException in project datanucleus-rdbms by datanucleus.
the class TableGenerator method createRepository.
/**
* Method to create the repository for ids to be stored.
* @return Whether it was created successfully.
*/
protected boolean createRepository() {
RDBMSStoreManager srm = (RDBMSStoreManager) storeMgr;
if (!srm.getSchemaHandler().isAutoCreateTables()) {
throw new NucleusUserException(Localiser.msg("040011", sequenceTable));
}
try {
if (sequenceTable == null) {
initialiseSequenceTable();
}
sequenceTable.exists((Connection) connection.getConnection(), true);
repositoryExists = true;
return true;
} catch (SQLException sqle) {
throw new ValueGenerationException("Exception thrown calling table.exists() for " + sequenceTable, sqle);
}
}
Aggregations