use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-rdbms by datanucleus.
the class InformixAdapter method initialiseDatastore.
/**
* Creates the auxiliary functions/procedures in the schema
* @param conn the connection to the datastore
*/
public void initialiseDatastore(Connection conn) {
try {
Statement st = conn.createStatement();
try {
st.execute(getSTRPOSDropFunction());
} catch (SQLException e) {
NucleusLogger.DATASTORE.warn(Localiser.msg("051027", e));
}
try {
st.execute(getSTRPOSFunction());
} catch (SQLException e) {
NucleusLogger.DATASTORE.warn(Localiser.msg("051027", e));
}
st.close();
} catch (SQLException e) {
NucleusLogger.DATASTORE_SCHEMA.warn("Exception when trying to initialise datastore", e);
throw new NucleusDataStoreException(e.getMessage(), e);
}
}
use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-rdbms by datanucleus.
the class NuoDBAdapter method getSchemaName.
public String getSchemaName(Connection conn) throws SQLException {
Statement stmt = conn.createStatement();
try {
String stmtText = "SELECT CURRENT_SCHEMA FROM DUAL";
ResultSet rs = stmt.executeQuery(stmtText);
try {
if (!rs.next()) {
throw new NucleusDataStoreException("No result returned from " + stmtText).setFatal();
}
return rs.getString(1);
} finally {
rs.close();
}
} finally {
stmt.close();
}
}
use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-rdbms by datanucleus.
the class OracleAdapter method getSchemaName.
public String getSchemaName(Connection conn) throws SQLException {
Statement stmt = conn.createStatement();
try {
String stmtText = "SELECT SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA') FROM DUAL";
ResultSet rs = stmt.executeQuery(stmtText);
try {
if (!rs.next()) {
throw new NucleusDataStoreException("No result returned from " + stmtText).setFatal();
}
return rs.getString(1);
} finally {
rs.close();
}
} finally {
stmt.close();
}
}
use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-rdbms by datanucleus.
the class AbstractSchemaTransaction method execute.
/**
* Executes the schema transaction.
* A database connection is acquired and the {@link #execute(ClassLoaderResolver)}method is invoked.
* If the selected isolation level is not Connection.TRANSACTION_NONE, then commit() or rollback() is
* called on the connection according to whether the invocation succeeded or not. If the invocation
* failed the sequence is repeated, up to a maximum of <var>maxRetries </var> times, configurable by
* the persistence property "datanucleus.rdbms.classAdditionMaxRetries".
* @param clr the ClassLoaderResolver
* @exception NucleusDataStoreException If a SQL exception occurred even after "maxRetries" attempts.
*/
public final void execute(ClassLoaderResolver clr) {
int attempts = 0;
for (; ; ) {
try {
try {
boolean succeeded = false;
try {
run(clr);
succeeded = true;
} finally {
if (conn != null) {
if (isolationLevel != TransactionIsolation.NONE) {
if (!conn.getAutoCommit()) {
if (succeeded) {
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled()) {
NucleusLogger.DATASTORE_SCHEMA.debug(Localiser.msg("050053", StringUtils.toJVMIDString(conn)));
}
conn.commit();
} else {
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled()) {
NucleusLogger.DATASTORE_SCHEMA.debug(Localiser.msg("050054", StringUtils.toJVMIDString(conn)));
}
conn.rollback();
}
}
}
}
}
} finally {
if (conn != null) {
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled()) {
NucleusLogger.DATASTORE_SCHEMA.debug(Localiser.msg("050055", StringUtils.toJVMIDString(conn)));
}
mconn.release();
conn = null;
}
}
break;
} catch (SQLException e) {
if (++attempts >= maxRetries) {
throw new NucleusDataStoreException(Localiser.msg("050056", this), e);
}
}
}
}
use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-rdbms by datanucleus.
the class DatastoreAdapterFactory method getNewDatastoreAdapter.
/**
* Accessor for the adapter for a specified datastore product.
* @param clr ClassLoader resolver for resolving the adapter class
* @param metadata Database MetaData for the RDBMS
* @param adapterClassName Name of the class of the database adapter (null implies use autodetect)
* @param pluginMgr the Plug-in manager
* @return Instance of the database adapter
*/
protected DatastoreAdapter getNewDatastoreAdapter(ClassLoaderResolver clr, DatabaseMetaData metadata, String adapterClassName, PluginManager pluginMgr) {
if (metadata == null) {
return null;
}
String productName = null;
if (adapterClassName == null) {
// No adapter specified, so use "autodetection" based on the metadata to find the most suitable
try {
productName = metadata.getDatabaseProductName();
if (productName == null) {
NucleusLogger.DATASTORE.error(Localiser.msg("051024"));
return null;
}
} catch (SQLException sqe) {
NucleusLogger.DATASTORE.error(Localiser.msg("051025", sqe));
return null;
}
}
// Instantiate the adapter class
final Object adapter_obj;
try {
Class adapterClass = getAdapterClass(pluginMgr, adapterClassName, productName, clr);
if (adapterClass == null) {
return null;
}
final Object[] ctr_args = new Object[] { metadata };
final Class[] ctr_args_classes = new Class[] { DatabaseMetaData.class };
// Create an instance of the datastore adapter
final Constructor ctr = adapterClass.getConstructor(ctr_args_classes);
try {
adapter_obj = ctr.newInstance(ctr_args);
} catch (InvocationTargetException ite) {
if (ite.getTargetException() != null && ite.getTargetException() instanceof NucleusDataStoreException) {
throw (NucleusDataStoreException) ite.getTargetException();
}
return null;
} catch (Exception e) {
NucleusLogger.DATASTORE.error(Localiser.msg("051026", adapterClassName, e));
return null;
}
} catch (ClassNotResolvedException ex) {
NucleusLogger.DATASTORE.error(Localiser.msg("051026", adapterClassName, ex));
return null;
} catch (NoSuchMethodException nsme) {
NucleusLogger.DATASTORE.error(Localiser.msg("051026", adapterClassName, nsme));
return null;
}
return (DatastoreAdapter) adapter_obj;
}
Aggregations