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;
}
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);
}
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();
}
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());
}
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);
}
}
Aggregations