use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class SYSTABLESRowFactory method getTableName.
/**
* Get the table name out of this SYSTABLES row
*
* @param row a SYSTABLES row
*
* @return string, the table name
*
* @exception StandardException thrown on failure
*/
protected String getTableName(ExecRow row) throws StandardException {
DataValueDescriptor col;
col = row.getColumn(SYSTABLES_TABLENAME);
return col.getString();
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class SYSTABLESRowFactory method buildDescriptorBody.
public TupleDescriptor buildDescriptorBody(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd, int isolationLevel) throws StandardException {
if (SanityManager.DEBUG)
SanityManager.ASSERT(row.nColumns() == SYSTABLES_COLUMN_COUNT, "Wrong number of columns for a SYSTABLES row");
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
String tableUUIDString;
String schemaUUIDString;
int tableTypeEnum;
String lockGranularity;
String tableName, tableType;
DataValueDescriptor col;
UUID tableUUID;
UUID schemaUUID;
SchemaDescriptor schema;
TableDescriptor tabDesc;
/* 1st column is TABLEID (UUID - char(36)) */
col = row.getColumn(SYSTABLES_TABLEID);
tableUUIDString = col.getString();
tableUUID = getUUIDFactory().recreateUUID(tableUUIDString);
/* 2nd column is TABLENAME (varchar(128)) */
col = row.getColumn(SYSTABLES_TABLENAME);
tableName = col.getString();
/* 3rd column is TABLETYPE (char(1)) */
col = row.getColumn(SYSTABLES_TABLETYPE);
tableType = col.getString();
if (SanityManager.DEBUG) {
SanityManager.ASSERT(tableType.length() == 1, "Fourth column type incorrect");
}
switch(tableType.charAt(0)) {
case 'T':
tableTypeEnum = TableDescriptor.BASE_TABLE_TYPE;
break;
case 'S':
tableTypeEnum = TableDescriptor.SYSTEM_TABLE_TYPE;
break;
case 'V':
tableTypeEnum = TableDescriptor.VIEW_TYPE;
break;
case 'A':
tableTypeEnum = TableDescriptor.SYNONYM_TYPE;
break;
default:
if (SanityManager.DEBUG)
SanityManager.THROWASSERT("Fourth column value invalid");
tableTypeEnum = -1;
}
/* 4th column is SCHEMAID (UUID - char(36)) */
col = row.getColumn(SYSTABLES_SCHEMAID);
schemaUUIDString = col.getString();
schemaUUID = getUUIDFactory().recreateUUID(schemaUUIDString);
schema = dd.getSchemaDescriptor(schemaUUID, isolationLevel, null);
/* 5th column is LOCKGRANULARITY (char(1)) */
col = row.getColumn(SYSTABLES_LOCKGRANULARITY);
lockGranularity = col.getString();
if (SanityManager.DEBUG) {
SanityManager.ASSERT(lockGranularity.length() == 1, "Fifth column type incorrect");
}
// RESOLVE - Deal with lock granularity
tabDesc = ddg.newTableDescriptor(tableName, schema, tableTypeEnum, lockGranularity.charAt(0));
tabDesc.setUUID(tableUUID);
return tabDesc;
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class SYSTRIGGERSRowFactory method buildDescriptor.
// /////////////////////////////////////////////////////////////////////////
//
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
//
// /////////////////////////////////////////////////////////////////////////
/**
* Make an Tuple Descriptor out of a SYSTRIGGERS row
*
* @param row a SYSTRIGGERS row
* @param parentTupleDescriptor unused
* @param dd dataDictionary
*
* @return a descriptor equivalent to a SYSTRIGGERS row
*
* @exception StandardException thrown on failure
*/
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
DataValueDescriptor col;
String name;
char theChar;
String uuidStr;
String triggerDefinition;
String oldReferencingName;
String newReferencingName;
UUID uuid;
// schema
UUID suuid;
// referenced table
UUID tuuid;
// action sps uuid string
UUID actionSPSID = null;
// when clause sps uuid string
UUID whenSPSID = null;
Timestamp createTime;
int eventMask = 0;
boolean isBefore;
boolean isRow;
boolean isEnabled;
boolean referencingOld;
boolean referencingNew;
ReferencedColumns rcd;
TriggerDescriptor descriptor;
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
if (SanityManager.DEBUG) {
// The expected number of columns depends on the version of the
// data dictionary. The WHENCLAUSETEXT column was added in version
// 10.11 (DERBY-534).
int expectedCols = dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_11, null) ? SYSTRIGGERS_COLUMN_COUNT : (SYSTRIGGERS_COLUMN_COUNT - 1);
SanityManager.ASSERT(row.nColumns() == expectedCols, "Wrong number of columns for a SYSTRIGGERS row");
}
// 1st column is TRIGGERID (UUID - char(36))
col = row.getColumn(1);
uuidStr = col.getString();
uuid = getUUIDFactory().recreateUUID(uuidStr);
// 2nd column is TRIGGERNAME (varchar(128))
col = row.getColumn(2);
name = col.getString();
// 3rd column is SCHEMAID (UUID - char(36))
col = row.getColumn(3);
uuidStr = col.getString();
suuid = getUUIDFactory().recreateUUID(uuidStr);
// 4th column is CREATIONTIMESTAMP (TIMESTAMP)
col = row.getColumn(4);
createTime = col.getTimestamp(getCalendarForCreationTimestamp());
// 5th column is EVENT (char(1))
col = row.getColumn(5);
theChar = col.getString().charAt(0);
switch(theChar) {
case 'U':
eventMask = TriggerDescriptor.TRIGGER_EVENT_UPDATE;
break;
case 'I':
eventMask = TriggerDescriptor.TRIGGER_EVENT_INSERT;
break;
case 'D':
eventMask = TriggerDescriptor.TRIGGER_EVENT_DELETE;
break;
default:
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("bad event mask: " + theChar);
}
}
// 6th column is FIRINGTIME (char(1))
isBefore = getCharBoolean(row.getColumn(6), 'B', 'A');
// 7th column is TYPE (char(1))
isRow = getCharBoolean(row.getColumn(7), 'R', 'S');
// 8th column is STATE (char(1))
isEnabled = getCharBoolean(row.getColumn(8), 'E', 'D');
// 9th column is TABLEID (UUID - char(36))
col = row.getColumn(9);
uuidStr = col.getString();
tuuid = getUUIDFactory().recreateUUID(uuidStr);
// 10th column is WHENSTMTID (UUID - char(36))
col = row.getColumn(10);
uuidStr = col.getString();
if (uuidStr != null)
whenSPSID = getUUIDFactory().recreateUUID(uuidStr);
// 11th column is ACTIONSTMTID (UUID - char(36))
col = row.getColumn(11);
uuidStr = col.getString();
if (uuidStr != null)
actionSPSID = getUUIDFactory().recreateUUID(uuidStr);
// 12th column is REFERENCEDCOLUMNS user type org.apache.derby.catalog.ReferencedColumns
col = row.getColumn(12);
rcd = (ReferencedColumns) col.getObject();
// 13th column is TRIGGERDEFINITION (longvarchar)
col = row.getColumn(13);
triggerDefinition = col.getString();
// 14th column is REFERENCINGOLD (boolean)
col = row.getColumn(14);
referencingOld = col.getBoolean();
// 15th column is REFERENCINGNEW (boolean)
col = row.getColumn(15);
referencingNew = col.getBoolean();
// 16th column is REFERENCINGNAME (varchar(128))
col = row.getColumn(16);
oldReferencingName = col.getString();
// 17th column is REFERENCINGNAME (varchar(128))
col = row.getColumn(17);
newReferencingName = col.getString();
// 18th column is WHENCLAUSETEXT (longvarchar)
String whenClauseText = null;
if (row.nColumns() >= 18) {
// This column is present only if the data dictionary version is
// 10.11 or higher.
col = row.getColumn(18);
whenClauseText = col.getString();
}
descriptor = ddg.newTriggerDescriptor(dd.getSchemaDescriptor(suuid, null), uuid, name, eventMask, isBefore, isRow, isEnabled, dd.getTableDescriptor(tuuid), whenSPSID, actionSPSID, createTime, (rcd == null) ? (int[]) null : rcd.getReferencedColumnPositions(), (rcd == null) ? (int[]) null : rcd.getTriggerActionReferencedColumnPositions(), triggerDefinition, referencingOld, referencingNew, oldReferencingName, newReferencingName, whenClauseText);
return descriptor;
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class SYSVIEWSRowFactory method buildDescriptor.
// /////////////////////////////////////////////////////////////////////////
//
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
//
// /////////////////////////////////////////////////////////////////////////
/**
* Make a ViewDescriptor out of a SYSVIEWS row
*
* @param row a SYSVIEWS 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 {
ViewDescriptor vd = null;
if (SanityManager.DEBUG) {
SanityManager.ASSERT(row.nColumns() == SYSVIEWS_COLUMN_COUNT, "Wrong number of columns for a SYSVIEWS row");
}
DataValueDescriptor col;
DataDescriptorGenerator ddg;
int checkIType;
String checkSType;
String tableID;
String compSchemaId;
String viewDefinition;
UUID tableUUID;
UUID compSchemaUUID = null;
ddg = dd.getDataDescriptorGenerator();
/* 1st column is TABLEID (UUID - char(36)) */
col = row.getColumn(SYSVIEWS_TABLEID);
tableID = col.getString();
tableUUID = getUUIDFactory().recreateUUID(tableID);
/* 2nd column is VIEWDEFINITION */
col = row.getColumn(SYSVIEWS_VIEWDEFINITION);
viewDefinition = col.getString();
/* 3rd column is CHECKOPTION (char(1)) */
col = row.getColumn(SYSVIEWS_CHECKOPTION);
checkSType = col.getString();
if (SanityManager.DEBUG) {
if (!checkSType.equals("N")) {
SanityManager.THROWASSERT("checkSType expected to be 'N', not " + checkSType);
}
}
/* RESOLVE - no check options for now */
checkIType = ViewDescriptor.NO_CHECK_OPTION;
/* 4th column is COMPILATIONSCHEMAID (UUID - char(36)) */
col = row.getColumn(SYSVIEWS_COMPILATION_SCHEMAID);
compSchemaId = col.getString();
if (compSchemaId != null) {
compSchemaUUID = getUUIDFactory().recreateUUID(compSchemaId);
}
/* now build and return the descriptor */
vd = ddg.newViewDescriptor(tableUUID, null, viewDefinition, checkIType, compSchemaUUID);
return vd;
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class SYSVIEWSRowFactory method makeRow.
// ///////////////////////////////////////////////////////////////////////////
//
// METHODS
//
// ///////////////////////////////////////////////////////////////////////////
/**
* Make a SYSVIEWS row
*
* @return Row suitable for inserting into SYSVIEWS.
*
* @exception StandardException thrown on failure
*/
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
DataValueDescriptor col;
ExecRow row;
String tableID = null;
String compSchemaId = null;
String viewText = null;
String checkSType = null;
int checkIType;
if (td != null) {
UUID tableUUID;
ViewDescriptor vd = (ViewDescriptor) td;
/*
** We only allocate a new UUID if the descriptor doesn't already have one.
** For descriptors replicated from a Source system, we already have an UUID.
*/
tableUUID = vd.getUUID();
if (tableUUID == null) {
tableUUID = getUUIDFactory().createUUID();
vd.setUUID(tableUUID);
}
tableID = tableUUID.toString();
viewText = vd.getViewText();
/* RESOLVE - check constraints not supported yet */
checkIType = vd.getCheckOptionType();
if (SanityManager.DEBUG) {
if (checkIType != ViewDescriptor.NO_CHECK_OPTION) {
SanityManager.THROWASSERT("checkIType expected to be " + ViewDescriptor.NO_CHECK_OPTION + ", not " + checkIType);
}
}
checkSType = "N";
UUID tmpId = vd.getCompSchemaId();
compSchemaId = (tmpId == null) ? null : tmpId.toString();
}
/* Insert info into sysviews */
/* RESOLVE - It would be nice to require less knowledge about sysviews
* and have this be more table driven.
*/
/* Build the row to insert */
row = getExecutionFactory().getValueRow(SYSVIEWS_COLUMN_COUNT);
/* 1st column is TABLEID (UUID - char(36)) */
row.setColumn(SYSVIEWS_TABLEID, new SQLChar(tableID));
/* 2nd column is VIEWDEFINITION */
row.setColumn(SYSVIEWS_VIEWDEFINITION, dvf.getLongvarcharDataValue(viewText));
/* 3rd column is CHECKOPTION (char(1)) */
row.setColumn(SYSVIEWS_CHECKOPTION, new SQLChar(checkSType));
/* 4th column is COMPILATIONSCHEMAID (UUID - char(36)) */
row.setColumn(SYSVIEWS_COMPILATION_SCHEMAID, new SQLChar(compSchemaId));
return row;
}
Aggregations