use of org.apache.derby.iapi.sql.execute.ExecPreparedStatement in project derby by apache.
the class SYSSTATEMENTSRowFactory method makeSYSSTATEMENTSrow.
// ///////////////////////////////////////////////////////////////////////////
//
// METHODS
//
// ///////////////////////////////////////////////////////////////////////////
/**
* Make a SYSSTATEMENTS row.
* <p>
* <B>WARNING</B>: When empty row is true, this method takes
* a snapshot of the SPSD and creates a row. It is imperative
* that that row remain consistent with the descriptor (the
* valid and StorablePreparedStatement fields must be in sync).
* If this row is to be written out and valid is true, then
* this call and the insert should be synchronized on the
* SPSD. This method has <B>NO</B> synchronization.
*
* @param compileMe passed into SPSDescriptorImpl.getPreparedStatement().
* if true, we (re)compile the stmt
* @param spsDescriptor In-memory tuple to be converted to a disk row.
*
* @return Row suitable for inserting into SYSSTATEMENTS.
*
* @exception StandardException thrown on failure
*/
public ExecRow makeSYSSTATEMENTSrow(boolean compileMe, SPSDescriptor spsDescriptor) throws StandardException {
DataTypeDescriptor dtd;
ExecRow row;
DataValueDescriptor col;
String name = null;
UUID uuid = null;
String uuidStr = null;
// schema
String suuidStr = null;
// compilation schema
String compUuidStr = null;
String text = null;
String usingText = null;
ExecPreparedStatement preparedStatement = null;
String typeStr = null;
boolean valid = true;
Timestamp time = null;
boolean initiallyCompilable = true;
if (spsDescriptor != null) {
name = spsDescriptor.getName();
uuid = spsDescriptor.getUUID();
suuidStr = spsDescriptor.getSchemaDescriptor().getUUID().toString();
uuidStr = uuid.toString();
text = spsDescriptor.getText();
valid = spsDescriptor.isValid();
time = spsDescriptor.getCompileTime();
typeStr = spsDescriptor.getTypeAsString();
initiallyCompilable = spsDescriptor.initiallyCompilable();
preparedStatement = spsDescriptor.getPreparedStatement(compileMe);
compUuidStr = (spsDescriptor.getCompSchemaId() != null) ? spsDescriptor.getCompSchemaId().toString() : null;
usingText = spsDescriptor.getUsingText();
}
/* Build the row to insert */
row = getExecutionFactory().getValueRow(SYSSTATEMENTS_COLUMN_COUNT);
/* 1st column is STMTID */
row.setColumn(1, new SQLChar(uuidStr));
/* 2nd column is STMTNAME */
row.setColumn(2, new SQLVarchar(name));
/* 3rd column is SCHEMAID */
row.setColumn(3, new SQLChar(suuidStr));
/* 4th column is TYPE */
row.setColumn(4, new SQLChar(typeStr));
/* 5th column is VALID */
row.setColumn(5, new SQLBoolean(valid));
/* 6th column is TEXT */
row.setColumn(6, dvf.getLongvarcharDataValue(text));
/* 7th column is LASTCOMPILED */
row.setColumn(7, new SQLTimestamp(time));
/* 8th column is COMPILATIONSCHEMAID */
row.setColumn(8, new SQLChar(compUuidStr));
/* 9th column is USINGTEXT */
row.setColumn(9, dvf.getLongvarcharDataValue(usingText));
/*
** 10th column is CONSTANTSTATE
**
** CONSTANTSTATE is really a formatable StorablePreparedStatement.
*/
row.setColumn(10, new UserType(preparedStatement));
/* 11th column is INITIALLY_COMPILABLE */
row.setColumn(11, new SQLBoolean(initiallyCompilable));
return row;
}
use of org.apache.derby.iapi.sql.execute.ExecPreparedStatement in project derby by apache.
the class SPSDescriptor method compileStatement.
/**
* Compiles this SPS.
* <p>
* <em>Note:</em> This SPS may still be marked as invalid after this method
* has completed, because an invalidation request may have been received
* while compiling.
*
* @param lcc connection
* @param triggerTable subject table (may be {@code null})
* @param tc transaction controller to use (may be {@code null})
* @throws StandardException if something fails
*/
// @GuardedBy("this")
private void compileStatement(LanguageConnectionContext lcc, TableDescriptor triggerTable, TransactionController tc) throws StandardException {
ContextManager cm = lcc.getContextManager();
LanguageConnectionFactory lcf = lcc.getLanguageConnectionFactory();
DataDictionary dd = getDataDictionary();
/*
** If we are a trigger, then we have to go ahead
** and locate the trigger's table descriptor and
** push it on the lcc. This is expensive, but
** pretty atypical since trigger actions aren't
** likely to be invalidated too often. Also, when
** possible, we already have the triggerTable.
*/
if (type == SPS_TYPE_TRIGGER && triggerTable == null) {
// 49 because name consists of (see CreateTriggerConstantAction):
// TRIGGER<ACTN|WHEN>_<UUID:36>_<UUID:36>
String uuidStr = name.substring(49);
triggerTable = dd.getTableDescriptor(recreateUUID(uuidStr));
if (SanityManager.DEBUG) {
if (triggerTable == null) {
SanityManager.THROWASSERT("couldn't find trigger table for trigger sps " + name);
}
}
}
if (triggerTable != null) {
lcc.pushTriggerTable(triggerTable);
}
// stored statements always stored as unicode.
Statement stmt = lcf.getStatement(dd.getSchemaDescriptor(compSchemaId, null), text, true);
try {
preparedStatement = (ExecPreparedStatement) stmt.prepareStorable(lcc, preparedStatement, getParameterDefaults(), getSchemaDescriptor(), type == SPS_TYPE_TRIGGER);
} finally {
if (triggerTable != null) {
lcc.popTriggerTable(triggerTable);
}
}
// when the query is getting compiled.
if (preparedStatement.referencesSessionSchema())
throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES);
setCompileTime();
setParams(preparedStatement.getParameterTypes());
if (!dd.isReadOnlyUpgrade()) {
/*
** Indicate that we are going to write the data
** dictionary. We have probably already done this
** but it is ok to call startWriting more than once.
*/
dd.startWriting(lcc);
DependencyManager dm = dd.getDependencyManager();
/*
** Clear out all the dependencies that exist
** before we recreate them so we don't grow
** SYS.SYSDEPENDS forever.
*/
dm.clearDependencies(lcc, this, tc);
/*
** Copy over all the dependencies to me
*/
// from
dm.copyDependencies(// from
preparedStatement, // to
this, // persistent only
false, cm, tc);
// between this sps and the trigger table DERBY-5120
if (triggerTable != null)
dm.addDependency(this, triggerTable, lcc.getContextManager());
}
// mark it as valid
valid = true;
}
use of org.apache.derby.iapi.sql.execute.ExecPreparedStatement in project derby by apache.
the class EmbedPreparedStatement method getMetaData.
/**
* JDBC 2.0
*
* The number, types and properties of a ResultSet's columns
* are provided by the getMetaData method.
*
* @return the description of a ResultSet's columns
* @exception SQLException Feature not implemented for now.
*/
public java.sql.ResultSetMetaData getMetaData() throws SQLException {
checkExecStatus();
synchronized (getConnectionSynchronization()) {
// reason for casting is getActivationClass is not available on PreparedStatement
ExecPreparedStatement execp = (ExecPreparedStatement) preparedStatement;
// make sure there's context
setupContextStack();
try {
// bug 4579 - gcDuringGetMetaData will be null if this is the first time
// getMetaData call is made.
// Second check - if the statement was revalidated since last getMetaData call,
// then gcDuringGetMetaData wouldn't match with current generated class name
GeneratedClass currAc = null;
ResultDescription resd = null;
synchronized (execp) {
// DERBY-3823 Some other thread may be repreparing
do {
while (!execp.upToDate()) {
execp.rePrepare(lcc);
}
currAc = execp.getActivationClass();
resd = execp.getResultDescription();
} while (currAc == null);
}
if (gcDuringGetMetaData == null || !gcDuringGetMetaData.equals(currAc.getName())) {
rMetaData = null;
gcDuringGetMetaData = currAc.getName();
}
if (rMetaData == null && resd != null) {
// Internally, the result description has information
// which is used for insert, update and delete statements
// Externally, we decided that statements which don't
// produce result sets such as insert, update and delete
// should not return ResultSetMetaData. This is enforced
// here
String statementType = resd.getStatementType();
if (statementType.equals("INSERT") || statementType.equals("UPDATE") || statementType.equals("DELETE"))
rMetaData = null;
else
rMetaData = newEmbedResultSetMetaData(resd);
}
InterruptStatus.restoreIntrFlagIfSeen(lcc);
} catch (Throwable t) {
throw handleException(t);
} finally {
restoreContextStack();
}
}
return rMetaData;
}
Aggregations