Search in sources :

Example 6 with ValueGenerationException

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);
    }
}
Also used : SQLException(java.sql.SQLException) ValueGenerationException(org.datanucleus.store.valuegenerator.ValueGenerationException)

Example 7 with ValueGenerationException

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);
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ValueGenerationBlock(org.datanucleus.store.valuegenerator.ValueGenerationBlock) PreparedStatement(java.sql.PreparedStatement) ValueGenerationException(org.datanucleus.store.valuegenerator.ValueGenerationException) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) SQLController(org.datanucleus.store.rdbms.SQLController) ResultSet(java.sql.ResultSet) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) DatastoreAdapter(org.datanucleus.store.rdbms.adapter.DatastoreAdapter)

Example 8 with ValueGenerationException

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);
    }
}
Also used : SQLException(java.sql.SQLException) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) ValueGenerationException(org.datanucleus.store.valuegenerator.ValueGenerationException) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Aggregations

SQLException (java.sql.SQLException)8 ValueGenerationException (org.datanucleus.store.valuegenerator.ValueGenerationException)8 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)6 PreparedStatement (java.sql.PreparedStatement)5 SQLController (org.datanucleus.store.rdbms.SQLController)5 ResultSet (java.sql.ResultSet)4 ValueGenerationBlock (org.datanucleus.store.valuegenerator.ValueGenerationBlock)4 ArrayList (java.util.ArrayList)3 DatastoreAdapter (org.datanucleus.store.rdbms.adapter.DatastoreAdapter)3 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)2 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)2 List (java.util.List)1 NucleusException (org.datanucleus.exceptions.NucleusException)1 DatastoreIdentifier (org.datanucleus.store.rdbms.identifier.DatastoreIdentifier)1