Search in sources :

Example 16 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext 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 17 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext 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 18 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext 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)

Example 19 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.

the class EmbedConnection method checkIsDBOwner.

/**
 * Check if actual authenticationId is equal to the database owner's.
 *
 * @param operation attempted operation which needs database owner powers
 * @throws SQLException if actual authenticationId is different
 * from authenticationId of database owner.
 */
private void checkIsDBOwner(int operation) throws SQLException {
    final LanguageConnectionContext lcc = privilegedGetLCC();
    final String actualId = lcc.getSessionUserId();
    final String dbOwnerId = lcc.getDataDictionary().getAuthorizationDatabaseOwner();
    if (!actualId.equals(dbOwnerId)) {
        switch(operation) {
            case OP_ENCRYPT:
                throw newSQLException(SQLState.AUTH_ENCRYPT_NOT_DB_OWNER, actualId, tr.getDBName());
            case OP_DECRYPT:
                throw newSQLException(SQLState.AUTH_DECRYPT_NOT_DB_OWNER, actualId, tr.getDBName());
            case OP_SHUTDOWN:
                throw newSQLException(SQLState.AUTH_SHUTDOWN_NOT_DB_OWNER, actualId, tr.getDBName());
            case OP_HARD_UPGRADE:
                throw newSQLException(SQLState.AUTH_HARD_UPGRADE_NOT_DB_OWNER, actualId, tr.getDBName());
            case OP_REPLICATION:
                throw newSQLException(SQLState.AUTH_REPLICATION_NOT_DB_OWNER, actualId, tr.getDBName());
            default:
                if (SanityManager.DEBUG) {
                    SanityManager.THROWASSERT("illegal checkIsDBOwner operation");
                }
                throw newSQLException(SQLState.AUTH_DATABASE_CONNECTION_REFUSED);
        }
    }
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext)

Example 20 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.

the class EmbedDatabaseMetaData method prepareSPS.

/*
	** Given a SPS name and a query text it returns a 
	** java.sql.PreparedStatement for the SPS. If the SPS
	** doeesn't exist is created.
	** 
	*/
private PreparedStatement prepareSPS(String spsName, String spsText, boolean net) throws StandardException, SQLException {
    LanguageConnectionContext lcc = getLanguageConnectionContext();
    /* We now need to do this in sub transaction because we could possibly recompile SPS
		 * later, and the recompile is in a sub transaction, and will update the SYSSTATEMENTS
		 * entry.  Don't want to block.
		 */
    lcc.beginNestedTransaction(true);
    DataDictionary dd = getLanguageConnectionContext().getDataDictionary();
    SPSDescriptor spsd = dd.getSPSDescriptor(spsName, net ? dd.getSysIBMSchemaDescriptor() : dd.getSystemSchemaDescriptor());
    lcc.commitNestedTransaction();
    if (spsd == null) {
        throw Util.notImplemented(spsName);
    }
    /* manish:
		   There should be a nicer way of getting a 
		   java.sql.PreparedStatement from an SPS descriptor!
		*/
    /*
		** It is unnecessarily expensive to get the
		** the statement, and then send an EXECUTE
		** statement, but we have no (easy) way of turning
		** the statement into a java.sql.PreparedStatement.
		*/
    String queryText = "EXECUTE STATEMENT " + (net ? "SYSIBM" : "SYS") + ".\"" + spsName + "\"";
    return getEmbedConnection().prepareMetaDataStatement(queryText);
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) SPSDescriptor(org.apache.derby.iapi.sql.dictionary.SPSDescriptor)

Aggregations

LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)126 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)57 TransactionController (org.apache.derby.iapi.store.access.TransactionController)47 StandardException (org.apache.derby.shared.common.error.StandardException)36 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)20 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)20 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)20 UUID (org.apache.derby.catalog.UUID)14 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)13 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)10 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)7 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)7 RoleGrantDescriptor (org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)7 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)6 SQLException (java.sql.SQLException)5 Iterator (java.util.Iterator)5 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)5 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)5 ArrayList (java.util.ArrayList)4