use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class NetworkServerControlImpl method sendSQLMessage.
/**
* Send SQL Exception from server to client after processing a command
*
* @param writer writer to use for sending message
* @param se Derby exception
* @param type type of exception, SQLERROR or SQLWARNING
*
* @throws Exception if a problem occurs sending message
*/
private void sendSQLMessage(DDMWriter writer, SQLException se, int type) throws Exception {
StringBuffer locMsg = new StringBuffer();
// localize message if necessary
while (se != null) {
StandardException ferry = StandardException.getArgumentFerry(se);
if (currentSession != null && currentSession.langUtil != null && ferry != null) {
locMsg.append(se.getSQLState() + ":" + MessageUtils.getLocalizedMessage(currentSession.langUtil.getLocale(), ferry.getMessageId(), ferry.getArguments()));
} else
locMsg.append(se.getSQLState() + ":" + se.getMessage());
se = se.getNextException();
if (se != null)
locMsg.append("\n");
}
sendMessage(writer, type, locMsg.toString());
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class PropertyInfo method setDatabaseProperty.
/**
* Set or delete the value of a property of the database on the current connection.
* For security reasons (see DERBY-6616), this code is duplicated in SystemProcedures.
*
* @param key the property key
* @param value the new value, if null the property is deleted.
*
* @exception SQLException on error
*/
public static void setDatabaseProperty(String key, String value) throws SQLException {
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
try {
SecurityUtil.authorize(Securable.SET_DATABASE_PROPERTY);
Authorizer a = lcc.getAuthorizer();
a.authorize((Activation) null, Authorizer.PROPERTY_WRITE_OP);
// Get the current transaction controller
TransactionController tc = lcc.getTransactionExecute();
tc.setProperty(key, value, false);
} catch (StandardException se) {
throw PublicAPI.wrapStandardException(se);
}
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class SPSDescriptor method getPreparedStatement.
/**
* Get the preparedStatement for this statement.
* Expects the prepared statement to have already
* been added to SYS.SYSSTATEMENTS.
* <p>
* Side Effects: will update SYS.SYSSTATEMENTS with
* the new plan if it needs to be recompiled.
*
* @param recompIfInvalid if false, never recompile even
* if statement is invalid
*
* @return the preparedStatement
*
* @exception StandardException on error
*/
public final synchronized ExecPreparedStatement getPreparedStatement(boolean recompIfInvalid) throws StandardException {
/*
** Recompile if we are invalid, we don't have
** a prepared statement, or the statements activation
** has been cleared and cannot be reconstituted.
*/
if (recompIfInvalid && (!valid || (preparedStatement == null))) {
ContextManager cm = getContextService().getCurrentContextManager();
/*
** Find the language connection context. Get
** it each time in case a connection is dropped.
*/
LanguageConnectionContext lcc = (LanguageConnectionContext) cm.getContext(LanguageConnectionContext.CONTEXT_ID);
if (!lcc.getDataDictionary().isReadOnlyUpgrade()) {
final String savepoint = lcc.getUniqueSavepointName();
// First try compiling in a nested transaction so we can
// release the locks after the compilation, and not have them
// sit around in the parent transaction. But if we get lock
// time out in the nested transaction, then go ahead and do
// the compilation in the user transaction. When doing the
// compilation in the user transaction, the locks acquired for
// recompilation will be released at the end of the user
// transaction (commit or abort).
TransactionController nestedTC;
try {
nestedTC = lcc.getTransactionCompile().startNestedUserTransaction(false, true);
// DERBY-3693: The nested transaction may run into a lock
// conflict with its parent transaction, in which case we
// don't want to wait for a timeout. If a lock timeout is
// detected while we're executing the nested transaction,
// we ignore the error and retry in the user transaction.
// When retrying in the user transaction, we'll wait for
// locks if necessary.
nestedTC.setNoLockWait(true);
// Set a savepoint so that the work in the nested
// transaction can be rolled back on error without
// aborting the parent transaction.
nestedTC.setSavePoint(savepoint, null);
} catch (StandardException se) {
// If I cannot start a Nested User Transaction use the
// parent transaction to do all the work.
nestedTC = null;
}
try {
prepareAndRelease(lcc, null, nestedTC);
updateSYSSTATEMENTS(lcc, RECOMPILE, nestedTC);
} catch (StandardException se) {
if (nestedTC != null) {
// Roll back to savepoint to undo any work done by
// the nested transaction. We cannot abort the nested
// transaction in order to achieve the same, since
// that would also abort the parent transaction.
nestedTC.rollbackToSavePoint(savepoint, false, null);
}
if ((nestedTC != null) && (se.isLockTimeout() || se.isSelfDeadlock())) {
// Locks were set nowait, so a lock timeout here
// means that some lock request in the nested
// transaction immediately conflicted. A conflict
// with a parent lock would lead to a undetected
// deadlock so must give up trying in the nested
// transaction and retry with parent transaction.
nestedTC.commit();
nestedTC.destroy();
nestedTC = null;
// if we couldn't do this with a nested transaction,
// retry with parent-- we need to wait this time!
// Lock conflicts at this point are with other
// transactions, so must wait.
prepareAndRelease(lcc, null, null);
updateSYSSTATEMENTS(lcc, RECOMPILE, null);
} else {
throw se;
}
} finally {
// not abort the parent here.
if (nestedTC != null) {
nestedTC.commit();
nestedTC.destroy();
}
}
}
}
return preparedStatement;
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class EmbedConnection method commonSetSavepointCode.
/**
* Creates a savepoint with the given name (if it is a named
* savepoint else we will generate a name because Derby only
* supports named savepoints internally) in the current
* transaction and returns the new Savepoint object that
* represents it.
*
* @param name A String containing the name of the savepoint. Will
* be null if this is an unnamed savepoint
* @param userSuppliedSavepointName If true means it's a named
* user defined savepoint.
*
* @return The new Savepoint object
*/
private Savepoint commonSetSavepointCode(String name, boolean userSuppliedSavepointName) throws SQLException {
synchronized (getConnectionSynchronization()) {
setupContextStack();
try {
verifySavepointCommandIsAllowed();
// supplied name is not null
if (userSuppliedSavepointName && (name == null)) {
throw newSQLException(SQLState.NULL_NAME_FOR_SAVEPOINT);
}
// supplied name length is not > 128
if (userSuppliedSavepointName && (name.length() > Limits.MAX_IDENTIFIER_LENGTH)) {
throw newSQLException(SQLState.LANG_IDENTIFIER_TOO_LONG, name, String.valueOf(Limits.MAX_IDENTIFIER_LENGTH));
}
// can't start with SYS
if (userSuppliedSavepointName && name.startsWith("SYS")) {
throw newSQLException(SQLState.INVALID_SCHEMA_SYS, "SYS");
}
Savepoint savePt = new EmbedSavepoint(this, name);
return savePt;
} catch (StandardException e) {
throw handleException(e);
} finally {
restoreContextStack();
}
}
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class EmbedConnection method xa_prepare.
/*
** methods to be overridden by subimplementations wishing to insert
** their classes into the mix.
** The reason we need to override them is because we want to create a
** Local20/LocalStatment object (etc) rather than a Local/LocalStatment
** object (etc).
*/
/*
** XA support
*/
/**
* Do not use this method directly use XATransactionState.xa_prepare
* instead because it also maintains/cancels the timeout task which is
* scheduled to cancel/rollback the global transaction.
*
* @return One of {@link org.apache.derby.iapi.store.access.XATransactionController#XA_OK} or
* {@link org.apache.derby.iapi.store.access.XATransactionController#XA_RDONLY}
* @throws java.sql.SQLException
*/
public final int xa_prepare() throws SQLException {
synchronized (getConnectionSynchronization()) {
setupContextStack();
try {
LanguageConnectionContext lcc = privilegedGetLCC();
XATransactionController tc = (XATransactionController) lcc.getTransactionExecute();
try {
lcc.checkIntegrity();
} catch (StandardException e) {
lcc.xaRollback();
throw e;
}
int ret = tc.xa_prepare();
if (ret == XATransactionController.XA_RDONLY) {
// On a prepare call, xa allows an optimization that if the
// transaction is read only, the RM can just go ahead and
// commit it. So if store returns this read only status -
// meaning store has taken the liberty to commit already - we
// needs to turn around and call internalCommit (without
// committing the store again) to make sure the state is
// consistent. Since the transaction is read only, there is
// probably not much that needs to be done.
lcc.internalCommit(false);
}
InterruptStatus.restoreIntrFlagIfSeen(lcc);
return ret;
} catch (StandardException t) {
throw handleException(t);
} finally {
restoreContextStack();
}
}
}
Aggregations