Search in sources :

Example 36 with LanguageConnectionContext

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;
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

Example 37 with LanguageConnectionContext

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());
    }
}
Also used : StatementPermission(org.apache.derby.iapi.sql.dictionary.StatementPermission) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Authorizer(org.apache.derby.iapi.sql.conn.Authorizer) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) ArrayList(java.util.ArrayList) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) StatementRoutinePermission(org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission)

Example 38 with LanguageConnectionContext

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;
}
Also used : ExecPreparedStatement(org.apache.derby.iapi.sql.execute.ExecPreparedStatement) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DMLWriteResultSet(org.apache.derby.impl.sql.execute.DMLWriteResultSet) UUID(org.apache.derby.catalog.UUID)

Example 39 with LanguageConnectionContext

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;
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) Stack(java.util.Stack) StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) TransactionInfo(org.apache.derby.iapi.store.access.TransactionInfo) List(java.util.List) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 40 with LanguageConnectionContext

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();
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) StandardException(org.apache.derby.shared.common.error.StandardException) Date(java.util.Date)

Aggregations

LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)126 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)57 TransactionController (org.apache.derby.iapi.store.access.TransactionController)47 StandardException (org.apache.derby.shared.common.error.StandardException)36 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)20 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)20 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)20 UUID (org.apache.derby.catalog.UUID)14 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)13 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)10 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)7 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)7 RoleGrantDescriptor (org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)7 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)6 SQLException (java.sql.SQLException)5 Iterator (java.util.Iterator)5 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)5 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)5 ArrayList (java.util.ArrayList)4