use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class EmbedConnection method resetFromPool.
/**
* Reset the connection before it is returned from a PooledConnection
* to a new application request (wrapped by a BrokeredConnection).
* Examples of reset covered here is dropping session temporary tables
* and reseting IDENTITY_VAL_LOCAL.
* Most JDBC level reset is handled by calling standard java.sql.Connection
* methods from EmbedPooledConnection.
*/
public void resetFromPool() throws SQLException {
synchronized (getConnectionSynchronization()) {
setupContextStack();
try {
LanguageConnectionContext lcc = privilegedGetLCC();
lcc.resetFromPool();
InterruptStatus.restoreIntrFlagIfSeen(lcc);
} catch (StandardException t) {
throw handleException(t);
} finally {
restoreContextStack();
}
}
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class EmbedConnection method setReadOnly.
/**
* You can put a connection in read-only mode as a hint to enable
* database optimizations.
*
* <P><B>Note:</B> setReadOnly cannot be called while in the
* middle of a transaction.
*
* @param readOnly true enables read-only mode; false disables
* read-only mode.
* @exception SQLException if a database-access error occurs.
*/
public final void setReadOnly(boolean readOnly) throws SQLException {
synchronized (getConnectionSynchronization()) {
setupContextStack();
try {
LanguageConnectionContext lcc = privilegedGetLCC();
lcc.setReadOnly(readOnly);
InterruptStatus.restoreIntrFlagIfSeen(lcc);
} catch (StandardException e) {
throw handleException(e);
} finally {
restoreContextStack();
}
}
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class EmbedConnection method setTransactionIsolation.
/**
* You can call this method to try to change the transaction
* isolation level using one of the TRANSACTION_* values.
*
* <P><B>Note:</B> setTransactionIsolation causes the current
* transaction to commit if the isolation level is changed. Otherwise, if
* the requested isolation level is the same as the current isolation
* level, this method is a no-op.
*
* @param level one of the TRANSACTION_* isolation values with the
* exception of TRANSACTION_NONE; some databases may not support
* other values
* @exception SQLException if a database-access error occurs.
* @see DatabaseMetaData#supportsTransactionIsolationLevel
*/
public void setTransactionIsolation(int level) throws SQLException {
if (level == getTransactionIsolation())
return;
// Convert the isolation level to the internal one
int iLevel;
switch(level) {
case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED:
iLevel = TransactionControl.READ_UNCOMMITTED_ISOLATION_LEVEL;
break;
case java.sql.Connection.TRANSACTION_READ_COMMITTED:
iLevel = TransactionControl.READ_COMMITTED_ISOLATION_LEVEL;
break;
case java.sql.Connection.TRANSACTION_REPEATABLE_READ:
iLevel = TransactionControl.REPEATABLE_READ_ISOLATION_LEVEL;
break;
case java.sql.Connection.TRANSACTION_SERIALIZABLE:
iLevel = TransactionControl.SERIALIZABLE_ISOLATION_LEVEL;
break;
default:
throw newSQLException(SQLState.UNIMPLEMENTED_ISOLATION_LEVEL, level);
}
synchronized (getConnectionSynchronization()) {
setupContextStack();
try {
LanguageConnectionContext lcc = privilegedGetLCC();
lcc.setIsolationLevel(iLevel);
InterruptStatus.restoreIntrFlagIfSeen(lcc);
} catch (StandardException e) {
throw handleException(e);
} finally {
restoreContextStack();
}
}
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class EmbedConnection method setClientInfo.
/**
* <code>setClientInfo</code> will throw a
* <code>SQLClientInfoException</code> unless the <code>properties</code>
* parameter is empty, since Derby does not support any
* properties. All the property keys in the
* <code>properties</code> parameter are added to failedProperties
* of the exception thrown, with REASON_UNKNOWN_PROPERTY as the
* value.
*
* @param properties a <code>Properties</code> object with the
* properties to set
* @exception SQLClientInfoException unless properties parameter
* is null or empty
*/
public void setClientInfo(Properties properties) throws SQLClientInfoException {
FailedProperties40 fp = new FailedProperties40(properties);
try {
checkIfClosed();
} catch (SQLException se) {
throw new SQLClientInfoException(se.getMessage(), se.getSQLState(), se.getErrorCode(), fp.getProperties());
}
// An empty properties object is meaningless, but allowed
if (properties == null || properties.isEmpty()) {
return;
}
StandardException se = StandardException.newException(SQLState.PROPERTY_UNSUPPORTED_CHANGE, fp.getFirstKey(), fp.getFirstValue());
throw new SQLClientInfoException(se.getMessage(), se.getSQLState(), se.getErrorCode(), fp.getProperties());
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class EmbedConnection method checkUserIsNotARole.
/**
* If applicable, check that we don't connect with a user name
* that equals a role.
*
* @exception SQLException Will throw if the current authorization
* id in {@code lcc} (which is already normalized to
* case normal form - CNF) equals an existing role name
* (which is also stored in CNF).
*/
private void checkUserIsNotARole() throws SQLException {
TransactionResourceImpl tr = getTR();
try {
tr.startTransaction();
LanguageConnectionContext lcc = tr.getLcc();
String username = lcc.getSessionUserId();
DataDictionary dd = lcc.getDataDictionary();
// introduced in 10.4):
if (lcc.usesSqlAuthorization() && dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_4, null)) {
TransactionController tc = lcc.getTransactionExecute();
String failedString = MessageService.getTextMessage(MessageId.AUTH_INVALID);
if (dd.getRoleDefinitionDescriptor(username) != null) {
throw newSQLException(SQLState.NET_CONNECT_AUTH_FAILED, failedString);
}
}
tr.rollback();
InterruptStatus.restoreIntrFlagIfSeen(lcc);
} catch (StandardException e) {
try {
tr.rollback();
} catch (StandardException ee) {
}
throw handleException(e);
}
}
Aggregations