use of org.apache.derby.catalog.UUID in project derby by apache.
the class UpdateNode method addGeneratedColumns.
/**
* Add generated columns to the update list as necessary. We add
* any column whose generation clause mentions columns already
* in the update list. We fill in a list of all generated columns affected
* by this update. We also fill in a list of all generated columns which we
* added to the update list.
*/
private void addGeneratedColumns(TableDescriptor baseTable, ResultSetNode updateSet, ColumnDescriptorList affectedGeneratedColumns, ColumnDescriptorList addedGeneratedColumns) throws StandardException {
ResultColumnList updateColumnList = updateSet.getResultColumns();
ColumnDescriptorList generatedColumns = baseTable.getGeneratedColumns();
HashSet<String> updatedColumns = new HashSet<String>();
UUID tableID = baseTable.getObjectID();
for (ResultColumn rc : updateColumnList) {
updatedColumns.add(rc.getName());
}
for (ColumnDescriptor gc : generatedColumns) {
DefaultInfo defaultInfo = gc.getDefaultInfo();
String[] mentionedColumnNames = defaultInfo.getReferencedColumnNames();
int mentionedColumnCount = mentionedColumnNames.length;
// literal
if (updatedColumns.contains(gc.getColumnName())) {
affectedGeneratedColumns.add(tableID, gc);
}
// update
for (String mcn : mentionedColumnNames) {
if (updatedColumns.contains(mcn)) {
// Yes, we are updating one of the columns mentioned in
// this generation clause.
affectedGeneratedColumns.add(tableID, gc);
// add it.
if (!updatedColumns.contains(gc.getColumnName())) {
addedGeneratedColumns.add(tableID, gc);
// we will fill in the real value later on in parseAndBindGenerationClauses();
ValueNode dummy = new UntypedNullConstantNode(getContextManager());
ResultColumn newResultColumn = new ResultColumn(gc.getType(), dummy, getContextManager());
newResultColumn.setColumnDescriptor(baseTable, gc);
newResultColumn.setName(gc.getColumnName());
updateColumnList.addResultColumn(newResultColumn);
}
break;
}
}
// done looping through mentioned columns
}
// done looping through generated columns
}
use of org.apache.derby.catalog.UUID in project derby by apache.
the class SYSCONSTRAINTSRowFactory method buildDescriptor.
// /////////////////////////////////////////////////////////////////////////
//
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
//
// /////////////////////////////////////////////////////////////////////////
/**
* Make a ConstraintDescriptor out of a SYSCONSTRAINTS row
*
* @param row a SYSCONSTRAINTS row
* @param parentTupleDescriptor Subconstraint descriptor with auxiliary info.
* @param dd dataDictionary
*
* @exception StandardException thrown on failure
*/
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
ConstraintDescriptor constraintDesc = null;
if (SanityManager.DEBUG) {
SanityManager.ASSERT(row.nColumns() == SYSCONSTRAINTS_COLUMN_COUNT, "Wrong number of columns for a SYSCONSTRAINTS row");
}
DataValueDescriptor col;
ConglomerateDescriptor conglomDesc;
DataDescriptorGenerator ddg;
TableDescriptor td = null;
int constraintIType = -1;
int[] keyColumns = null;
UUID constraintUUID;
UUID schemaUUID;
UUID tableUUID;
UUID referencedConstraintId = null;
SchemaDescriptor schema;
String tableUUIDString;
String constraintName;
String constraintSType;
String constraintStateStr;
boolean deferrable = ConstraintDefinitionNode.DEFERRABLE_DEFAULT;
boolean initiallyDeferred = ConstraintDefinitionNode.INITIALLY_DEFERRED_DEFAULT;
boolean enforced = ConstraintDefinitionNode.ENFORCED_DEFAULT;
int referenceCount;
String constraintUUIDString;
String schemaUUIDString;
SubConstraintDescriptor scd;
if (SanityManager.DEBUG) {
if (!(parentTupleDescriptor instanceof SubConstraintDescriptor)) {
SanityManager.THROWASSERT("parentTupleDescriptor expected to be instanceof " + "SubConstraintDescriptor, not " + parentTupleDescriptor.getClass().getName());
}
}
scd = (SubConstraintDescriptor) parentTupleDescriptor;
ddg = dd.getDataDescriptorGenerator();
/* 1st column is CONSTRAINTID (UUID - char(36)) */
col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTID);
constraintUUIDString = col.getString();
constraintUUID = getUUIDFactory().recreateUUID(constraintUUIDString);
/* 2nd column is TABLEID (UUID - char(36)) */
col = row.getColumn(SYSCONSTRAINTS_TABLEID);
tableUUIDString = col.getString();
tableUUID = getUUIDFactory().recreateUUID(tableUUIDString);
/* Get the TableDescriptor.
* It may be cached in the SCD,
* otherwise we need to go to the
* DD.
*/
if (scd != null) {
td = scd.getTableDescriptor();
}
if (td == null) {
td = dd.getTableDescriptor(tableUUID);
}
/* 3rd column is NAME (varchar(128)) */
col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTNAME);
constraintName = col.getString();
/* 4th column is TYPE (char(1)) */
col = row.getColumn(SYSCONSTRAINTS_TYPE);
constraintSType = col.getString();
if (SanityManager.DEBUG) {
SanityManager.ASSERT(constraintSType.length() == 1, "Fourth column type incorrect");
}
boolean typeSet = false;
switch(constraintSType.charAt(0)) {
case 'P':
constraintIType = DataDictionary.PRIMARYKEY_CONSTRAINT;
typeSet = true;
case 'U':
if (!typeSet) {
constraintIType = DataDictionary.UNIQUE_CONSTRAINT;
typeSet = true;
}
case 'F':
if (!typeSet)
constraintIType = DataDictionary.FOREIGNKEY_CONSTRAINT;
if (SanityManager.DEBUG) {
if (!(parentTupleDescriptor instanceof SubKeyConstraintDescriptor)) {
SanityManager.THROWASSERT("parentTupleDescriptor expected to be instanceof " + "SubKeyConstraintDescriptor, not " + parentTupleDescriptor.getClass().getName());
}
}
conglomDesc = td.getConglomerateDescriptor(((SubKeyConstraintDescriptor) parentTupleDescriptor).getIndexId());
/* Take care the rare case of conglomDesc being null. The
* reason is that our "td" is out of date. Another thread
* which was adding a constraint committed between the moment
* we got the table descriptor (conglomerate list) and the
* moment we scanned and got the constraint desc list. Since
* that thread just added a new row to SYSCONGLOMERATES,
* SYSCONSTRAINTS, etc. We wouldn't have wanted to lock the
* system tables just to prevent other threads from adding new
* rows.
*/
if (conglomDesc == null) {
// we can't be getting td from cache because if we are
// here, we must have been in dd's ddl mode (that's why
// the ddl thread went through), we are not done yet, the
// dd ref count is not 0, hence it couldn't have turned
// into COMPILE_ONLY mode
td = dd.getTableDescriptor(tableUUID);
if (scd != null)
scd.setTableDescriptor(td);
// try again now
conglomDesc = td.getConglomerateDescriptor(((SubKeyConstraintDescriptor) parentTupleDescriptor).getIndexId());
}
if (SanityManager.DEBUG) {
SanityManager.ASSERT(conglomDesc != null, "conglomDesc is expected to be non-null for backing index");
}
keyColumns = conglomDesc.getIndexDescriptor().baseColumnPositions();
referencedConstraintId = ((SubKeyConstraintDescriptor) parentTupleDescriptor).getKeyConstraintId();
keyColumns = conglomDesc.getIndexDescriptor().baseColumnPositions();
break;
case 'C':
constraintIType = DataDictionary.CHECK_CONSTRAINT;
if (SanityManager.DEBUG) {
if (!(parentTupleDescriptor instanceof SubCheckConstraintDescriptor)) {
SanityManager.THROWASSERT("parentTupleDescriptor expected to be instanceof " + "SubCheckConstraintDescriptor, not " + parentTupleDescriptor.getClass().getName());
}
}
break;
default:
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("Fourth column value invalid");
}
}
/* 5th column is SCHEMAID (UUID - char(36)) */
col = row.getColumn(SYSCONSTRAINTS_SCHEMAID);
schemaUUIDString = col.getString();
schemaUUID = getUUIDFactory().recreateUUID(schemaUUIDString);
schema = dd.getSchemaDescriptor(schemaUUID, null);
/* 6th column is STATE (char(1)) */
col = row.getColumn(SYSCONSTRAINTS_STATE);
constraintStateStr = col.getString();
if (SanityManager.DEBUG) {
SanityManager.ASSERT(constraintStateStr.length() == 1, "Sixth column (state) type incorrect");
}
//
switch(constraintStateStr.charAt(0)) {
case 'E':
deferrable = false;
initiallyDeferred = false;
enforced = true;
break;
case 'D':
deferrable = false;
initiallyDeferred = false;
enforced = false;
break;
case 'e':
deferrable = true;
initiallyDeferred = true;
enforced = true;
break;
case 'd':
deferrable = true;
initiallyDeferred = true;
enforced = false;
break;
case 'i':
deferrable = true;
initiallyDeferred = false;
enforced = true;
break;
case 'j':
deferrable = true;
initiallyDeferred = false;
enforced = false;
break;
default:
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("Invalidate state value '" + constraintStateStr + "' for constraint");
}
}
/* 7th column is REFERENCECOUNT, boolean */
col = row.getColumn(SYSCONSTRAINTS_REFERENCECOUNT);
referenceCount = col.getInt();
switch(constraintIType) {
case DataDictionary.PRIMARYKEY_CONSTRAINT:
constraintDesc = ddg.newPrimaryKeyConstraintDescriptor(td, constraintName, deferrable, initiallyDeferred, // genReferencedColumns(dd, td), //int referencedColumns[],
keyColumns, constraintUUID, ((SubKeyConstraintDescriptor) parentTupleDescriptor).getIndexId(), schema, enforced, referenceCount);
break;
case DataDictionary.UNIQUE_CONSTRAINT:
constraintDesc = ddg.newUniqueConstraintDescriptor(td, constraintName, deferrable, initiallyDeferred, // genReferencedColumns(dd, td), //int referencedColumns[],
keyColumns, constraintUUID, ((SubKeyConstraintDescriptor) parentTupleDescriptor).getIndexId(), schema, enforced, referenceCount);
break;
case DataDictionary.FOREIGNKEY_CONSTRAINT:
if (SanityManager.DEBUG) {
SanityManager.ASSERT(referenceCount == 0, "REFERENCECOUNT column is nonzero for fk constraint");
}
constraintDesc = ddg.newForeignKeyConstraintDescriptor(td, constraintName, deferrable, initiallyDeferred, // genReferencedColumns(dd, td), //int referencedColumns[],
keyColumns, constraintUUID, ((SubKeyConstraintDescriptor) parentTupleDescriptor).getIndexId(), schema, referencedConstraintId, enforced, ((SubKeyConstraintDescriptor) parentTupleDescriptor).getRaDeleteRule(), ((SubKeyConstraintDescriptor) parentTupleDescriptor).getRaUpdateRule());
break;
case DataDictionary.CHECK_CONSTRAINT:
if (SanityManager.DEBUG) {
SanityManager.ASSERT(referenceCount == 0, "REFERENCECOUNT column is nonzero for check constraint");
}
constraintDesc = ddg.newCheckConstraintDescriptor(td, constraintName, deferrable, initiallyDeferred, constraintUUID, ((SubCheckConstraintDescriptor) parentTupleDescriptor).getConstraintText(), ((SubCheckConstraintDescriptor) parentTupleDescriptor).getReferencedColumnsDescriptor(), schema, enforced);
break;
}
return constraintDesc;
}
use of org.apache.derby.catalog.UUID in project derby by apache.
the class SYSDEPENDSRowFactory method buildDescriptor.
// /////////////////////////////////////////////////////////////////////////
//
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
//
// /////////////////////////////////////////////////////////////////////////
/**
* Make a ConstraintDescriptor out of a SYSDEPENDS row
*
* @param row a SYSDEPENDSS row
* @param parentTupleDescriptor Null for this kind of descriptor.
* @param dd dataDictionary
*
* @exception StandardException thrown on failure
*/
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
DependencyDescriptor dependencyDesc = null;
if (SanityManager.DEBUG) {
SanityManager.ASSERT(row.nColumns() == SYSDEPENDS_COLUMN_COUNT, "Wrong number of columns for a SYSDEPENDS row");
}
DataValueDescriptor col;
String dependentIDstring;
UUID dependentUUID;
DependableFinder dependentBloodhound;
String providerIDstring;
UUID providerUUID;
DependableFinder providerBloodhound;
/* 1st column is DEPENDENTID (UUID - char(36)) */
col = row.getColumn(SYSDEPENDS_DEPENDENTID);
dependentIDstring = col.getString();
dependentUUID = getUUIDFactory().recreateUUID(dependentIDstring);
/* 2nd column is DEPENDENTTYPE */
col = row.getColumn(SYSDEPENDS_DEPENDENTTYPE);
dependentBloodhound = (DependableFinder) col.getObject();
/* 3rd column is PROVIDERID (UUID - char(36)) */
col = row.getColumn(SYSDEPENDS_PROVIDERID);
providerIDstring = col.getString();
providerUUID = getUUIDFactory().recreateUUID(providerIDstring);
/* 4th column is PROVIDERTYPE */
col = row.getColumn(SYSDEPENDS_PROVIDERTYPE);
providerBloodhound = (DependableFinder) col.getObject();
/* now build and return the descriptor */
return new DependencyDescriptor(dependentUUID, dependentBloodhound, providerUUID, providerBloodhound);
}
use of org.apache.derby.catalog.UUID in project derby by apache.
the class SYSFOREIGNKEYSRowFactory method buildDescriptor.
// /////////////////////////////////////////////////////////////////////////
//
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
//
// /////////////////////////////////////////////////////////////////////////
/**
* Make a ViewDescriptor out of a SYSFOREIGNKEYS row
*
* @param row a SYSFOREIGNKEYS row
* @param parentTupleDescriptor Null for this kind of descriptor.
* @param dd dataDictionary
*
* @exception StandardException thrown on failure
*/
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
if (SanityManager.DEBUG) {
SanityManager.ASSERT(row.nColumns() == SYSFOREIGNKEYS_COLUMN_COUNT, "Wrong number of columns for a SYSKEYS row");
}
DataValueDescriptor col;
DataDescriptorGenerator ddg;
UUID constraintUUID;
UUID conglomerateUUID;
UUID keyConstraintUUID;
String constraintUUIDString;
String conglomerateUUIDString;
String raRuleString;
int raDeleteRule;
int raUpdateRule;
ddg = dd.getDataDescriptorGenerator();
/* 1st column is CONSTRAINTID (UUID - char(36)) */
col = row.getColumn(SYSFOREIGNKEYS_CONSTRAINTID);
constraintUUIDString = col.getString();
constraintUUID = getUUIDFactory().recreateUUID(constraintUUIDString);
/* 2nd column is CONGLOMERATEID (UUID - char(36)) */
col = row.getColumn(SYSFOREIGNKEYS_CONGLOMERATEID);
conglomerateUUIDString = col.getString();
conglomerateUUID = getUUIDFactory().recreateUUID(conglomerateUUIDString);
/* 3rd column is KEYCONSTRAINTID (UUID - char(36)) */
col = row.getColumn(SYSFOREIGNKEYS_KEYCONSTRAINTID);
constraintUUIDString = col.getString();
keyConstraintUUID = getUUIDFactory().recreateUUID(constraintUUIDString);
/* 4th column is DELETERULE char(1) */
col = row.getColumn(SYSFOREIGNKEYS_DELETERULE);
raRuleString = col.getString();
raDeleteRule = getRefActionAsInt(raRuleString);
/* 5th column is UPDATERULE char(1) */
col = row.getColumn(SYSFOREIGNKEYS_UPDATERULE);
raRuleString = col.getString();
raUpdateRule = getRefActionAsInt(raRuleString);
/* now build and return the descriptor */
return new SubKeyConstraintDescriptor(constraintUUID, conglomerateUUID, keyConstraintUUID, raDeleteRule, raUpdateRule);
}
use of org.apache.derby.catalog.UUID in project derby by apache.
the class SYSKEYSRowFactory method buildDescriptor.
// /////////////////////////////////////////////////////////////////////////
//
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
//
// /////////////////////////////////////////////////////////////////////////
/**
* Make a SubConstraintDescriptor out of a SYSKEYS row
*
* @param row a SYSKEYS row
* @param parentTupleDescriptor Null for this kind of descriptor.
* @param dd dataDictionary
*
* @exception StandardException thrown on failure
*/
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
SubKeyConstraintDescriptor keyDesc = null;
if (SanityManager.DEBUG) {
SanityManager.ASSERT(row.nColumns() == SYSKEYS_COLUMN_COUNT, "Wrong number of columns for a SYSKEYS row");
}
DataValueDescriptor col;
DataDescriptorGenerator ddg;
UUID constraintUUID;
UUID conglomerateUUID;
String constraintUUIDString;
String conglomerateUUIDString;
ddg = dd.getDataDescriptorGenerator();
/* 1st column is CONSTRAINTID (UUID - char(36)) */
col = row.getColumn(SYSKEYS_CONSTRAINTID);
constraintUUIDString = col.getString();
constraintUUID = getUUIDFactory().recreateUUID(constraintUUIDString);
/* 2nd column is CONGLOMERATEID (UUID - char(36)) */
col = row.getColumn(SYSKEYS_CONGLOMERATEID);
conglomerateUUIDString = col.getString();
conglomerateUUID = getUUIDFactory().recreateUUID(conglomerateUUIDString);
/* now build and return the descriptor */
keyDesc = new SubKeyConstraintDescriptor(constraintUUID, conglomerateUUID);
return keyDesc;
}
Aggregations