Search in sources :

Example 16 with StandardException

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();
        }
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext)

Example 17 with StandardException

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();
        }
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext)

Example 18 with StandardException

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();
        }
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Savepoint(java.sql.Savepoint)

Example 19 with StandardException

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());
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) SQLClientInfoException(java.sql.SQLClientInfoException) FailedProperties40(org.apache.derby.iapi.jdbc.FailedProperties40) SQLException(java.sql.SQLException)

Example 20 with StandardException

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);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) XATransactionController(org.apache.derby.iapi.store.access.XATransactionController)

Aggregations

StandardException (org.apache.derby.shared.common.error.StandardException)276 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)43 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)37 IOException (java.io.IOException)32 Properties (java.util.Properties)29 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)27 TransactionController (org.apache.derby.iapi.store.access.TransactionController)26 ContextManager (org.apache.derby.iapi.services.context.ContextManager)22 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)20 SQLException (java.sql.SQLException)17 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)17 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)16 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)12 RowLocation (org.apache.derby.iapi.types.RowLocation)11 SQLLongint (org.apache.derby.iapi.types.SQLLongint)11 StorageFile (org.apache.derby.io.StorageFile)10 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)9 ScanController (org.apache.derby.iapi.store.access.ScanController)9 File (java.io.File)8 LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)8