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);
}
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;
}
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;
}
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();
}
}
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);
}
Aggregations