Search in sources :

Example 96 with LanguageConnectionContext

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

the class NewOptimizerOverridesTest method getLastQueryPlan.

/**
 * Get an xml-based picture of the plan chosen for the last query. The query is identified by its JDBC ResultSet
 */
public static Document getLastQueryPlan(Connection conn, ResultSet rs) throws Exception {
    LanguageConnectionContext lcc = ConstraintCharacteristicsTest.getLCC(conn);
    org.apache.derby.iapi.sql.ResultSet derbyRS = lcc.getLastActivation().getResultSet();
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    Element root = doc.createElement("planTrace");
    doc.appendChild(root);
    derbyRS.toXML(root, "top");
    return doc;
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 97 with LanguageConnectionContext

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

the class ClassLoadingTest method test_01_6654.

/**
 * Test that you can't use Derby's custom class loader to load arbitrary
 * class files. See DERBY-6654.
 */
public void test_01_6654() throws Exception {
    ByteArray classBytes = new ByteArray(new byte[] { (byte) 1 });
    Connection conn = getConnection();
    LanguageConnectionContext lcc = ConstraintCharacteristicsTest.getLCC(conn);
    ClassFactory classFactory = lcc.getLanguageConnectionFactory().getClassFactory();
    String className1 = "BadClassName";
    String className2 = "bad.class.Name";
    vet6654(classFactory, className1, classBytes);
    vet6654(classFactory, className2, classBytes);
}
Also used : ClassFactory(org.apache.derby.iapi.services.loader.ClassFactory) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Connection(java.sql.Connection) EmbedConnection(org.apache.derby.impl.jdbc.EmbedConnection) ByteArray(org.apache.derby.iapi.util.ByteArray)

Example 98 with LanguageConnectionContext

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

the class ConstraintCharacteristicsTest method testAlterConstraintInvalidation.

/**
 * Check that altering constraint characteristics invalidates prepared
 * statements.
 * @throws SQLException
 */
public void testAlterConstraintInvalidation() throws SQLException {
    if (usingDerbyNetClient()) {
        // Skip, since we need to see inside an embedded connection here
        return;
    }
    final Connection c = getConnection();
    final Statement s = createStatement();
    s.executeUpdate("create table t(i int, constraint c primary key(i))");
    final PreparedStatement ps = c.prepareStatement("insert into t values 3");
    ps.execute();
    s.executeUpdate("alter table t alter constraint c enforced ");
    final LanguageConnectionContext lcc = getLCC(c);
    final GenericPreparedStatement derbyPs = (GenericPreparedStatement) lcc.getLastActivation().getPreparedStatement();
    assertFalse(derbyPs.isValid());
    rollback();
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) GenericPreparedStatement(org.apache.derby.impl.sql.GenericPreparedStatement) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) EmbedConnection(org.apache.derby.impl.jdbc.EmbedConnection) GenericPreparedStatement(org.apache.derby.impl.sql.GenericPreparedStatement) PreparedStatement(java.sql.PreparedStatement) GenericPreparedStatement(org.apache.derby.impl.sql.GenericPreparedStatement)

Example 99 with LanguageConnectionContext

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

the class BaseJDBCTestCase method checkEstimatedRowCount.

/**
 * Return estimated row count for runtime statistics.
 * Requires caller first turned on RuntimeStatistics, executed a query and closed the ResultSet.
 *
 * For client calls we just return as we can't find out this information.
 * @param conn
 * @param expectedCount
 * @throws SQLException
 */
public static void checkEstimatedRowCount(Connection conn, double expectedCount) throws SQLException {
    if (!(conn instanceof EmbedConnection)) {
        return;
    }
    EmbedConnection econn = (EmbedConnection) conn;
    LanguageConnectionContext lcc = (LanguageConnectionContext) getLanguageConnectionContext(econn);
    RunTimeStatistics rts = lcc.getRunTimeStatisticsObject();
    assertNotNull(" RuntimeStatistics is null. Did you call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)?", rts);
    assertEquals((long) expectedCount, (long) rts.getEstimatedRowCount());
}
Also used : RunTimeStatistics(org.apache.derby.iapi.sql.execute.RunTimeStatistics) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) EmbedConnection(org.apache.derby.impl.jdbc.EmbedConnection)

Example 100 with LanguageConnectionContext

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

the class SystemProcedures method SYSCS_DROP_USER.

/**
 * Drop a user.
 */
public static void SYSCS_DROP_USER(String userName) throws SQLException {
    userName = normalizeUserName(userName);
    try {
        // make sure that application code doesn't bypass security checks
        // by calling this public entry point
        SecurityUtil.authorize(Securable.DROP_USER);
        LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
        DataDictionary dd = lcc.getDataDictionary();
        String dbo = dd.getAuthorizationDatabaseOwner();
        // you can't drop the credentials of the dbo
        if (dbo.equals(userName)) {
            throw StandardException.newException(SQLState.CANT_DROP_DBO);
        }
        checkLegalUser(dd, userName);
        /*
            ** Inform the data dictionary that we are about to write to it.
            ** There are several calls to data dictionary "get" methods here
            ** that might be done in "read" mode in the data dictionary, but
            ** it seemed safer to do this whole operation in "write" mode.
            **
            ** We tell the data dictionary we're done writing at the end of
            ** the transaction.
            */
        dd.startWriting(lcc);
        dd.dropUser(userName, lcc.getTransactionExecute());
    } catch (StandardException se) {
        throw PublicAPI.wrapStandardException(se);
    }
}
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)

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