use of org.apache.derby.iapi.services.loader.GeneratedClass in project derby by apache.
the class GenericPreparedStatement method getActivation.
/**
* Get a new activation instance.
*
* @exception StandardException thrown if finished.
*/
public Activation getActivation(LanguageConnectionContext lcc, boolean scrollable) throws StandardException {
Activation ac;
synchronized (this) {
GeneratedClass gc = getActivationClass();
if (gc == null) {
rePrepare(lcc);
gc = getActivationClass();
}
ac = new GenericActivationHolder(lcc, gc, this, scrollable);
inUseCount++;
}
// DERBY-2689. Close unused activations-- this method should be called
// when I'm not holding a lock on a prepared statement to avoid
// deadlock.
lcc.closeUnusedActivations();
Activation parentAct = null;
StatementContext stmctx = lcc.getStatementContext();
if (stmctx != null) {
// If not null, parentAct represents one of 1) the activation of a
// calling statement and this activation corresponds to a statement
// inside a stored procedure or function, and 2) the activation of
// a statement that performs a substatement, e.g. trigger body
// execution.
parentAct = stmctx.getActivation();
}
ac.setParentActivation(parentAct);
return ac;
}
use of org.apache.derby.iapi.services.loader.GeneratedClass in project derby by apache.
the class GenericStorablePreparedStatement method loadGeneratedClass.
// ///////////////////////////////////////////////////////////
//
// STORABLEPREPAREDSTATEMENT INTERFACE
//
// ///////////////////////////////////////////////////////////
/**
* Load up the class from the saved bytes.
*
* @exception StandardException on error
*/
public void loadGeneratedClass() throws StandardException {
LanguageConnectionContext lcc = (LanguageConnectionContext) getContext(LanguageConnectionContext.CONTEXT_ID);
ClassFactory classFactory = lcc.getLanguageConnectionFactory().getClassFactory();
GeneratedClass gc = classFactory.loadGeneratedClass(className, byteCode);
/*
** No special try catch logic to write out bad classes
** here. We don't expect any problems, and in any
** event, we don't have the class builder available
** here.
*/
setActivationClass(gc);
}
use of org.apache.derby.iapi.services.loader.GeneratedClass in project derby by apache.
the class StatementNode method generate.
/**
* Do code generation for this statement.
*
* @param byteCode the generated byte code for this statement.
* if non-null, then the byte code is saved
* here.
*
* @return A GeneratedClass for this statement
*
* @exception StandardException Thrown on error
*/
public GeneratedClass generate(ByteArray byteCode) throws StandardException {
// start the new activation class.
// it starts with the Execute method
// and the appropriate superclass (based on
// statement type, from inspecting the queryTree).
int nodeChoice = activationKind();
/* RESOLVE: Activation hierarchy was way too complicated
* and added no value. Simple thing to do was to simply
* leave calling code alone and to handle here and to
* eliminate unnecessary classes.
*/
String superClass;
switch(nodeChoice) {
case NEED_CURSOR_ACTIVATION:
superClass = ClassName.CursorActivation;
break;
case NEED_DDL_ACTIVATION:
return getClassFactory().loadGeneratedClass("org.apache.derby.impl.sql.execute.ConstantActionActivation", null);
case NEED_NOTHING_ACTIVATION:
case NEED_ROW_ACTIVATION:
case NEED_PARAM_ACTIVATION:
superClass = ClassName.BaseActivation;
break;
default:
throw StandardException.newException(SQLState.LANG_UNAVAILABLE_ACTIVATION_NEED, String.valueOf(nodeChoice));
}
ActivationClassBuilder generatingClass = new ActivationClassBuilder(superClass, getCompilerContext());
// Create the method that generates the ResultSet tree used when
// executing this statement. Implements the abstract method
// BaseActivation.createResultSet().
MethodBuilder mbWorker = generatingClass.getClassBuilder().newMethodBuilder(Modifier.PROTECTED, ClassName.ResultSet, "createResultSet");
mbWorker.addThrownException(ClassName.StandardException);
// Generate the complete ResultSet tree for this statement.
// This step may add statements into the execute method
// for per-execution actions.
generate(generatingClass, mbWorker);
mbWorker.methodReturn();
mbWorker.complete();
// wrap up the activation class definition
// generate on the tree gave us back the newExpr
// for getting a result set on the tree.
// we put it in a return statement and stuff
// it in the execute method of the activation.
// The generated statement is the expression:
// the activation class builder takes care of constructing it
// for us, given the resultSetExpr to use.
// return (this.resultSet = #resultSetExpr);
generatingClass.finishExecuteMethod();
// wrap up the constructor by putting a return at the end of it
generatingClass.finishConstructor();
try {
// cook the completed class into a real class
// and stuff it into activationClass
GeneratedClass activationClass = generatingClass.getGeneratedClass(byteCode);
return activationClass;
} catch (StandardException e) {
String msgId = e.getMessageId();
if (SQLState.GENERATED_CLASS_LIMIT_EXCEEDED.equals(msgId) || SQLState.GENERATED_CLASS_LINKAGE_ERROR.equals(msgId)) {
throw StandardException.newException(SQLState.LANG_QUERY_TOO_COMPLEX, e);
}
throw e;
}
}
use of org.apache.derby.iapi.services.loader.GeneratedClass in project derby by apache.
the class GenericLanguageConnectionContext method lookupStatement.
/**
* See if a given statement has already been compiled for this user, and
* if so use its prepared statement. Returns null if not found.
*
* @exception StandardException thrown if lookup goes wrong.
* @return the prepared statement for the given string, null
* if none was found.
*/
public PreparedStatement lookupStatement(GenericStatement statement) throws StandardException {
CacheManager statementCache = getLanguageConnectionFactory().getStatementCache();
if (statementCache == null)
return null;
// statement caching disable when in DDL mode
if (dataDictionaryInWriteMode()) {
return null;
}
Cacheable cachedItem = statementCache.find(statement);
CachedStatement cs = (CachedStatement) cachedItem;
GenericPreparedStatement ps = cs.getPreparedStatement();
synchronized (ps) {
if (ps.upToDate()) {
GeneratedClass ac = ps.getActivationClass();
// Check to see if the statement was prepared before some change
// in the class loading set. If this is the case then force it to be invalid
int currentClasses = getLanguageConnectionFactory().getClassFactory().getClassLoaderVersion();
if (ac.getClassLoaderVersion() != currentClasses) {
ps.makeInvalid(DependencyManager.INTERNAL_RECOMPILE_REQUEST, this);
}
// note that the PreparedStatement is not kept in the cache. This is because
// having items kept in the cache that ultimately are held onto by
// user code is impossible to manage. E.g. an open ResultSet would hold onto
// a PreparedStatement (through its activation) and the user can allow
// this object to be garbage collected. Pushing a context stack is impossible
// in garbage collection as it may deadlock with the open connection and
// the context manager assumes a singel current thread per context stack
}
}
statementCache.release(cachedItem);
return ps;
}
use of org.apache.derby.iapi.services.loader.GeneratedClass in project derby by apache.
the class ExecSPSNode method generate.
/**
* Do code generation for this statement. Overrides
* the normal generation path in StatementNode.
*
* @param ignored - ignored (he he)
*
* @return A GeneratedClass for this statement
*
* @exception StandardException Thrown on error
*/
@Override
public GeneratedClass generate(ByteArray ignored) throws StandardException {
// table during stale sps recompilation later in the getPreparedstatement() call.
if (spsd.isValid() == false) {
getLanguageConnectionContext().commitNestedTransaction();
getLanguageConnectionContext().beginNestedTransaction(true);
}
/*
** The following does a prepare on the underlying
** statement if necessary. The returned statement
** is valid and its class is loaded up.
*/
ps = spsd.getPreparedStatement();
/*
** Set the saved constants from the prepared statement.
** Put them in the compilation context -- this is where
** they are expected.
*/
getCompilerContext().setSavedObjects(ps.getSavedObjects());
getCompilerContext().setCursorInfo(ps.getCursorInfo());
GeneratedClass gc = ps.getActivationClass();
return gc;
}
Aggregations