Search in sources :

Example 6 with SequenceDescriptor

use of org.apache.derby.iapi.sql.dictionary.SequenceDescriptor in project derby by apache.

the class DropSequenceConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 * This is the guts of the Execution-time logic for DROP SEQUENCE.
 *
 * @see org.apache.derby.iapi.sql.execute.ConstantAction#executeConstantAction
 */
public void executeConstantAction(Activation activation) throws StandardException {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    TransactionController tc = lcc.getTransactionExecute();
    /*
        ** Inform the data dictionary that we are about to write to it.
        ** There are several calls to data dictionary "get" methods here
        ** that might be done in "read" mode in the data dictionary, but
        ** it seemed safer to do this whole operation in "write" mode.
        **
        ** We tell the data dictionary we're done writing at the end of
        ** the transaction.
        */
    dd.startWriting(lcc);
    dd.clearSequenceCaches();
    SequenceDescriptor sequenceDescriptor = dd.getSequenceDescriptor(schemaDescriptor, sequenceName);
    if (sequenceDescriptor == null) {
        throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND_DURING_EXECUTION, "SEQUENCE", (schemaDescriptor.getObjectName() + "." + sequenceName));
    }
    sequenceDescriptor.drop(lcc);
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) SequenceDescriptor(org.apache.derby.iapi.sql.dictionary.SequenceDescriptor)

Example 7 with SequenceDescriptor

use of org.apache.derby.iapi.sql.dictionary.SequenceDescriptor in project derby by apache.

the class SYSSEQUENCESRowFactory method buildDescriptor.

/**
 * Make an  Tuple Descriptor out of a SYSSEQUENCES row
 *
 * @param row                   a SYSSEQUENCES row
 * @param parentTupleDescriptor unused
 * @param dd                    dataDictionary
 * @return a  descriptor equivalent to a SYSSEQUENCES row
 * @throws org.apache.derby.shared.common.error.StandardException
 *          thrown on failure
 */
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
    DataValueDescriptor col;
    SequenceDescriptor descriptor;
    UUID ouuid;
    String sequenceName;
    UUID suuid;
    Long currentValue;
    long startValue;
    long minimumValue;
    long maximumValue;
    long increment;
    String cycleOption;
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(row.nColumns() == SYSSEQUENCES_COLUMN_COUNT, "Wrong number of columns for a SYSSEQUENCES row");
    }
    // first column is uuid of this sequence descriptor (char(36))
    col = row.getColumn(SYSSEQUENCES_SEQUENCEID);
    String oidString = col.getString();
    ouuid = getUUIDFactory().recreateUUID(oidString);
    // second column is sequenceName (varchar(128))
    col = row.getColumn(SYSSEQUENCES_SEQUENCENAME);
    sequenceName = col.getString();
    // third column is uuid of this sequence descriptors schema (char(36))
    col = row.getColumn(SYSSEQUENCES_SCHEMAID);
    String schemaIdString = col.getString();
    suuid = getUUIDFactory().recreateUUID(schemaIdString);
    // fourth column is the data type of this sequene generator
    /*
          ** What is stored in the column is a TypeDescriptorImpl, which
          ** points to a BaseTypeIdImpl.  These are simple types that are
          ** intended to be movable to the client, so they don't have
          ** the entire implementation.  We need to wrap them in DataTypeServices
          ** and TypeId objects that contain the full implementations for
          ** language processing.
          */
    TypeDescriptor catalogType = (TypeDescriptor) row.getColumn(SYSSEQUENCES_SEQUENCEDATATYPE).getObject();
    DataTypeDescriptor dataTypeServices = DataTypeDescriptor.getType(catalogType);
    col = row.getColumn(SYSSEQUENCES_CURRENT_VALUE);
    if (col.isNull()) {
        currentValue = null;
    } else {
        currentValue = col.getLong();
    }
    col = row.getColumn(SYSSEQUENCES_START_VALUE);
    startValue = col.getLong();
    col = row.getColumn(SYSSEQUENCES_MINIMUM_VALUE);
    minimumValue = col.getLong();
    col = row.getColumn(SYSSEQUENCES_MAXIMUM_VALUE);
    maximumValue = col.getLong();
    col = row.getColumn(SYSSEQUENCES_INCREMENT);
    increment = col.getLong();
    col = row.getColumn(SYSSEQUENCES_CYCLE_OPTION);
    cycleOption = col.getString();
    descriptor = ddg.newSequenceDescriptor(dd.getSchemaDescriptor(suuid, null), ouuid, sequenceName, dataTypeServices, currentValue, startValue, minimumValue, maximumValue, increment, cycleOption.equals("Y") ? true : false);
    return descriptor;
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SequenceDescriptor(org.apache.derby.iapi.sql.dictionary.SequenceDescriptor) UUID(org.apache.derby.catalog.UUID)

Example 8 with SequenceDescriptor

use of org.apache.derby.iapi.sql.dictionary.SequenceDescriptor in project derby by apache.

the class DataDictionaryImpl method getSequenceDescriptor.

/**
 * Get the sequence descriptor given a sequence name and a schema Id.
 *
 * @param sequenceName The sequence name, guaranteed to be unique only within its schema.
 * @param sd           The schema descriptor.
 * @return The SequenceDescriptor for the constraints.
 * @throws StandardException Thrown on failure
 */
public SequenceDescriptor getSequenceDescriptor(SchemaDescriptor sd, String sequenceName) throws StandardException {
    DataValueDescriptor schemaIDOrderable;
    DataValueDescriptor sequenceNameOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSSEQUENCES_CATALOG_NUM);
    /* Use sequenceNameOrderable and schemaIdOrderable in both start
           * and stop position for scan.
           */
    sequenceNameOrderable = new SQLVarchar(sequenceName);
    schemaIDOrderable = getIDValueAsCHAR(sd.getUUID());
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(2);
    keyRow.setColumn(1, schemaIDOrderable);
    keyRow.setColumn(2, sequenceNameOrderable);
    SequenceDescriptor sequenceDescriptor = getDescriptorViaIndex(SYSSEQUENCESRowFactory.SYSSEQUENCES_INDEX2_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, SequenceDescriptor.class, false);
    putSequenceID(sequenceDescriptor);
    return sequenceDescriptor;
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) SequenceDescriptor(org.apache.derby.iapi.sql.dictionary.SequenceDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 9 with SequenceDescriptor

use of org.apache.derby.iapi.sql.dictionary.SequenceDescriptor in project derby by apache.

the class DataDictionaryImpl method getSequenceID.

/**
 * <p>
 * Get the uuid string of a sequence given its schema and sequence name.
 * </p>
 */
private String getSequenceID(String schemaName, String sequenceName) throws StandardException {
    HashMap<String, String> sequencesInSchema = sequenceIDs.get(schemaName);
    if (sequencesInSchema != null) {
        String uuid = (String) sequencesInSchema.get(sequenceName);
        if (uuid != null) {
            return uuid;
        }
    }
    // oops, not saved in the sequenceID map yet. lookup the sequence.
    // this will save the uuid in the sequenceID map.
    SequenceDescriptor desc = getSequenceDescriptor(getSchemaDescriptor(schemaName, getTransactionCompile(), true), sequenceName);
    if (desc == null) {
        return null;
    } else {
        return desc.getUUID().toString();
    }
}
Also used : SequenceDescriptor(org.apache.derby.iapi.sql.dictionary.SequenceDescriptor)

Example 10 with SequenceDescriptor

use of org.apache.derby.iapi.sql.dictionary.SequenceDescriptor in project derby by apache.

the class DataDictionaryImpl method computeSequenceRowLocation.

/**
 * Computes the RowLocation in SYSSEQUENCES for a particular sequence. Also
 * constructs the sequence descriptor.
 *
 * @param tc			Transaction Controller to use.
 * @param sequenceIDstring UUID of the sequence as a string
 * @param rowLocation OUTPUT param for returing the row location
 * @param sequenceDescriptor OUTPUT param for return the sequence descriptor
 *
 * @exception StandardException thrown on failure.
 */
public void computeSequenceRowLocation(TransactionController tc, String sequenceIDstring, RowLocation[] rowLocation, SequenceDescriptor[] sequenceDescriptor) throws StandardException {
    TabInfoImpl ti = getNonCoreTI(SYSSEQUENCES_CATALOG_NUM);
    ExecIndexRow keyRow = null;
    keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow.setColumn(1, new SQLChar(sequenceIDstring));
    rowLocation[0] = ti.getRowLocation(tc, keyRow, SYSSEQUENCESRowFactory.SYSSEQUENCES_INDEX1_ID);
    sequenceDescriptor[0] = getDescriptorViaIndex(SYSSEQUENCESRowFactory.SYSSEQUENCES_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, SequenceDescriptor.class, false, TransactionController.ISOLATION_REPEATABLE_READ, tc);
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) ScanQualifier(org.apache.derby.iapi.sql.execute.ScanQualifier) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ConglomerateDescriptorList(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList) ArrayList(java.util.ArrayList) TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList) List(java.util.List) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) LinkedList(java.util.LinkedList) SequenceDescriptor(org.apache.derby.iapi.sql.dictionary.SequenceDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Aggregations

SequenceDescriptor (org.apache.derby.iapi.sql.dictionary.SequenceDescriptor)11 UUID (org.apache.derby.catalog.UUID)3 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)3 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)3 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)3 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)3 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)3 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)3 TypeDescriptor (org.apache.derby.catalog.TypeDescriptor)2 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)2 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)2 TransactionController (org.apache.derby.iapi.store.access.TransactionController)2 SQLChar (org.apache.derby.iapi.types.SQLChar)2 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)1 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)1 ConglomerateDescriptorList (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList)1