use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class MaxMinAggregateDefinition method getAggregator.
/**
* Determines the result datatype. Accept NumberDataValues
* only.
* <P>
* <I>Note</I>: In the future you should be able to do
* a sum user data types. One option would be to run
* sum on anything that implements divide().
*
* @param inputType the input type, either a user type or a java.lang object
*
* @return the output Class (null if cannot operate on
* value expression of this type.
*/
public final DataTypeDescriptor getAggregator(DataTypeDescriptor inputType, StringBuffer aggregatorClass) {
LanguageConnectionContext lcc = (LanguageConnectionContext) QueryTreeNode.getContext(LanguageConnectionContext.CONTEXT_ID);
/*
** MIN and MAX may return null
*/
DataTypeDescriptor dts = inputType.getNullabilityType(true);
TypeId compType = dts.getTypeId();
/*
** If the class implements NumberDataValue, then we
** are in business. Return type is same as input
** type.
*/
if (compType.orderable(lcc.getLanguageConnectionFactory().getClassFactory())) {
aggregatorClass.append(ClassName.MaxMinAggregator);
return dts;
}
return null;
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class SecurityUtil method authorize.
/**
* Raise an exception if the current user does not have permission
* to perform the indicated operation.
*/
public static void authorize(Securable operation) throws StandardException {
LanguageConnectionContext lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
if (lcc.usesSqlAuthorization()) {
Authorizer authorizer = lcc.getAuthorizer();
DataDictionary dd = lcc.getDataDictionary();
AliasDescriptor ad = dd.getRoutineList(operation.routineSchemaID, operation.routineName, operation.routineType).get(0);
ArrayList<StatementPermission> requiredPermissions = new ArrayList<StatementPermission>();
StatementRoutinePermission executePermission = new StatementRoutinePermission(ad.getObjectID());
requiredPermissions.add(executePermission);
authorizer.authorize(requiredPermissions, lcc.getLastActivation());
}
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class SQLBoolean method throwExceptionIfImmediateAndFalse.
public BooleanDataValue throwExceptionIfImmediateAndFalse(String sqlState, String tableName, String constraintName, Activation a, int savedUUIDIdx) throws StandardException {
if (!isNull() && (value == false)) {
final ExecPreparedStatement ps = a.getPreparedStatement();
final UUID constrId = (UUID) ps.getSavedObject(savedUUIDIdx);
final LanguageConnectionContext lcc = a.getLanguageConnectionContext();
final boolean isDeferred = lcc.isEffectivelyDeferred(lcc.getCurrentSQLSessionContext(a), constrId);
if (!isDeferred) {
throw StandardException.newException(sqlState, tableName, constraintName);
} else {
// Just return the false value and validate later,
// cf NoRowsResultSetImpl#evaluateCheckConstraints.
// and InsertResultSet#evaluateCheckConstraints
DMLWriteResultSet rs = (DMLWriteResultSet) a.getResultSet();
rs.rememberConstraint(constrId);
}
}
return this;
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class Deadlock method buildException.
/**
* Build an exception that describes a deadlock.
*
* @param factory the lock factory requesting the exception
* @param data an array with information about who's involved in
* a deadlock (as returned by {@link #handle})
* @return a deadlock exception
*/
static StandardException buildException(AbstractPool factory, Object[] data) {
Stack chain = (Stack) data[0];
Dictionary waiters = (Dictionary) data[1];
LanguageConnectionContext lcc = (LanguageConnectionContext) getContext(LanguageConnectionContext.CONTEXT_ID);
TableNameInfo tabInfo = null;
TransactionInfo[] tt = null;
TransactionController tc = null;
if (lcc != null) {
try {
tc = lcc.getTransactionExecute();
tabInfo = new TableNameInfo(lcc, false);
tt = tc.getAccessManager().getTransactionInfo();
} catch (StandardException se) {
// just don't get any table info.
}
}
StringBuffer sb = new StringBuffer(200);
Hashtable<String, Object> attributes = new Hashtable<String, Object>(17);
String victimXID = null;
for (int i = 0; i < chain.size(); i++) {
Object space = chain.elementAt(i);
if (space instanceof List) {
List grants = (List) space;
if (grants.size() != 0) {
sb.append(" Granted XID : ");
for (int j = 0; j < grants.size(); j++) {
if (j != 0)
sb.append(", ");
Lock gl = (Lock) grants.get(j);
sb.append("{");
sb.append(gl.getCompatabilitySpace().getOwner());
sb.append(", ");
sb.append(gl.getQualifier());
sb.append("} ");
}
sb.append('\n');
}
continue;
}
// Information about the lock we are waiting on
// TYPE |TABLENAME |LOCKNAME
Lock lock = ((Lock) waiters.get(space));
// see if this lockable object wants to participate
lock.getLockable().lockAttributes(VirtualLockTable.ALL, attributes);
addInfo(sb, "Lock : ", attributes.get(VirtualLockTable.LOCKTYPE));
if (tabInfo != null) {
Long conglomId = (Long) attributes.get(VirtualLockTable.CONGLOMID);
if (conglomId == null) {
Long containerId = (Long) attributes.get(VirtualLockTable.CONTAINERID);
try {
conglomId = tc.findConglomid(containerId.longValue());
} catch (StandardException se) {
}
}
addInfo(sb, ", ", tabInfo.getTableName(conglomId));
}
addInfo(sb, ", ", attributes.get(VirtualLockTable.LOCKNAME));
sb.append('\n');
String xid = String.valueOf(lock.getCompatabilitySpace().getOwner());
if (i == 0)
victimXID = xid;
addInfo(sb, " Waiting XID : {", xid);
addInfo(sb, ", ", lock.getQualifier());
sb.append("} ");
if (tt != null) {
for (int tti = tt.length - 1; tti >= 0; tti--) {
TransactionInfo ti = tt[tti];
// ti.getTransactionIdString() or ti can return null.
if (ti != null) {
String idString = ti.getTransactionIdString();
if (idString != null && idString.equals(xid)) {
addInfo(sb, ", ", ti.getUsernameString());
addInfo(sb, ", ", ti.getStatementTextString());
break;
}
}
}
}
sb.append('\n');
attributes.clear();
}
StandardException se = StandardException.newException(SQLState.DEADLOCK, sb.toString(), victimXID);
se.setReport(factory.deadlockMonitor);
return se;
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class Timeout method buildLockTableString.
/**
* buildLockTableString creates a LockTable info String
*/
private String buildLockTableString() throws StandardException {
sb = new StringBuffer(8192);
outputRow = new char[LENGTHOFTABLE];
// counter
int i;
// need language here to print out tablenames
LanguageConnectionContext lcc = (LanguageConnectionContext) Deadlock.getContext(LanguageConnectionContext.CONTEXT_ID);
if (lcc != null)
tc = lcc.getTransactionExecute();
try {
tabInfo = new TableNameInfo(lcc, true);
} catch (Exception se) {
// just don't do anything
}
sb.append(newline);
sb.append(new Date(currentTime));
sb.append(newline);
for (i = 0; i < column.length; i++) {
sb.append(column[i]);
sb.append(SEPARATOR);
}
sb.append(newline);
for (i = 0; i < LENGTHOFTABLE; i++) sb.append(LINE);
sb.append(newline);
// get the timeout lock info
if (currentLock != null) {
dumpLock();
if (timeoutInfoHash()) {
sb.append("*** The following row is the victim ***");
sb.append(newline);
sb.append(outputRow);
sb.append(newline);
sb.append("*** The above row is the victim ***");
sb.append(newline);
} else {
sb.append("*** A victim was chosen, but it cannot be printed because the lockable object, " + currentLock + ", does not want to participate ***");
sb.append(newline);
}
}
// get lock info from the rest of the table
if (lockTable != null) {
while (lockTable.hasMoreElements()) {
currentLock = (Latch) lockTable.nextElement();
dumpLock();
if (timeoutInfoHash()) {
sb.append(outputRow);
sb.append(newline);
} else {
sb.append("*** A latch/lock, " + currentLock + ", exist in the lockTable that cannot be printed ***");
sb.append(newline);
}
}
for (i = 0; i < LENGTHOFTABLE; i++) sb.append(LINE);
sb.append(newline);
}
return sb.toString();
}
Aggregations