use of org.apache.derby.iapi.types.SQLChar in project derby by apache.
the class SYSKEYSRowFactory method makeRow.
// ///////////////////////////////////////////////////////////////////////////
//
// METHODS
//
// ///////////////////////////////////////////////////////////////////////////
/**
* Make a SYSKEYS row
*
* @return Row suitable for inserting into SYSKEYS.
*
* @exception StandardException thrown on failure
*/
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
DataValueDescriptor col;
ExecRow row;
UUID oid;
String constraintID = null;
String conglomerateID = null;
if (td != null) {
KeyConstraintDescriptor constraint = (KeyConstraintDescriptor) 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.
*/
oid = constraint.getUUID();
constraintID = oid.toString();
conglomerateID = constraint.getIndexUUIDString();
}
/* Insert info into syskeys */
/* RESOLVE - It would be nice to require less knowledge about syskeys
* and have this be more table driven.
*/
/* Build the row to insert */
row = getExecutionFactory().getValueRow(SYSKEYS_COLUMN_COUNT);
/* 1st column is CONSTRAINTID (UUID - char(36)) */
row.setColumn(SYSKEYS_CONSTRAINTID, new SQLChar(constraintID));
/* 2nd column is CONGLOMERATEID (UUID - char(36)) */
row.setColumn(SYSKEYS_CONGLOMERATEID, new SQLChar(conglomerateID));
return row;
}
use of org.apache.derby.iapi.types.SQLChar in project derby by apache.
the class SYSPERMSRowFactory method makeRow.
/**
* Make a SYSPERMS row
*
* @param td a permission descriptor
* @param parent unused
* @return Row suitable for inserting into SYSPERMS.
* @throws org.apache.derby.shared.common.error.StandardException
* thrown on failure
*/
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
ExecRow row;
String permIdString = null;
String objectType = "SEQUENCE";
String objectIdString = null;
String permission = "USAGE";
String grantor = null;
String grantee = null;
boolean grantable = false;
if (td != null) {
PermDescriptor sd = (PermDescriptor) td;
UUID pid = sd.getUUID();
if (pid == null) {
pid = getUUIDFactory().createUUID();
sd.setUUID(pid);
}
permIdString = pid.toString();
objectType = sd.getObjectType();
UUID oid = sd.getPermObjectId();
objectIdString = oid.toString();
permission = sd.getPermission();
grantor = sd.getGrantor();
grantee = sd.getGrantee();
grantable = sd.isGrantable();
}
/* Build the row to insert */
row = getExecutionFactory().getValueRow(SYSPERMS_COLUMN_COUNT);
/* 1st column is UUID */
row.setColumn(1, new SQLChar(permIdString));
/* 2nd column is OBJECTTYPE */
row.setColumn(2, new SQLVarchar(objectType));
/* 3rd column is OBJECTID */
row.setColumn(3, new SQLChar(objectIdString));
/* 4nd column is OBJECTTYPE */
row.setColumn(4, new SQLChar(permission));
/* 5nd column is GRANTOR */
row.setColumn(5, new SQLVarchar(grantor));
/* 6nd column is GRANTEE */
row.setColumn(6, new SQLVarchar(grantee));
/* 7nd column is IS_GRANTABLE */
row.setColumn(7, new SQLChar(grantable ? "Y" : "N"));
return row;
}
use of org.apache.derby.iapi.types.SQLChar in project derby by apache.
the class SYSSCHEMASRowFactory method makeRow.
// ///////////////////////////////////////////////////////////////////////////
//
// METHODS
//
// ///////////////////////////////////////////////////////////////////////////
/**
* Make a SYSSCHEMAS row
*
* @return Row suitable for inserting into SYSSCHEMAS.
*
* @exception StandardException thrown on failure
*/
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
DataTypeDescriptor dtd;
ExecRow row;
DataValueDescriptor col;
String name = null;
UUID oid = null;
String uuid = null;
String aid = null;
if (td != null) {
SchemaDescriptor schemaDescriptor = (SchemaDescriptor) td;
name = schemaDescriptor.getSchemaName();
oid = schemaDescriptor.getUUID();
if (oid == null) {
oid = getUUIDFactory().createUUID();
schemaDescriptor.setUUID(oid);
}
uuid = oid.toString();
aid = schemaDescriptor.getAuthorizationId();
}
/* Build the row to insert */
row = getExecutionFactory().getValueRow(SYSSCHEMAS_COLUMN_COUNT);
/* 1st column is SCHEMAID */
row.setColumn(1, new SQLChar(uuid));
/* 2nd column is SCHEMANAME */
row.setColumn(2, new SQLVarchar(name));
/* 3rd column is SCHEMAAID */
row.setColumn(3, new SQLVarchar(aid));
return row;
}
use of org.apache.derby.iapi.types.SQLChar in project derby by apache.
the class SYSSEQUENCESRowFactory method makeRow.
/**
* Make a SYSSEQUENCES row
*
* @param td a sequence descriptor
* @param parent unused
* @return Row suitable for inserting into SYSSEQUENCES.
* @throws org.apache.derby.shared.common.error.StandardException
* thrown on failure
*/
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
ExecRow row;
String oidString = null;
String sequenceName = null;
String schemaIdString = null;
TypeDescriptor typeDesc = null;
Long currentValue = null;
long startValue = 0;
long minimumValue = 0;
long maximumValue = 0;
long increment = 0;
boolean canCycle = false;
if (td != null) {
SequenceDescriptor sd = (SequenceDescriptor) td;
UUID oid = sd.getUUID();
oidString = oid.toString();
sequenceName = sd.getSequenceName();
UUID schemaId = sd.getSchemaId();
schemaIdString = schemaId.toString();
typeDesc = sd.getDataType().getCatalogType();
currentValue = sd.getCurrentValue();
startValue = sd.getStartValue();
minimumValue = sd.getMinimumValue();
maximumValue = sd.getMaximumValue();
increment = sd.getIncrement();
canCycle = sd.canCycle();
}
/* Build the row to insert */
row = getExecutionFactory().getValueRow(SYSSEQUENCES_COLUMN_COUNT);
/* 1st column is UUID */
row.setColumn(SYSSEQUENCES_SEQUENCEID, new SQLChar(oidString));
/* 2nd column is SEQUENCENAME */
row.setColumn(SYSSEQUENCES_SEQUENCENAME, new SQLVarchar(sequenceName));
/* 3nd column is SCHEMAID */
row.setColumn(SYSSEQUENCES_SCHEMAID, new SQLChar(schemaIdString));
/* 4th column is SEQUENCEDATATYPE */
row.setColumn(SYSSEQUENCES_SEQUENCEDATATYPE, new UserType(typeDesc));
/* 5th column is CURRENTVALUE */
SQLLongint curVal;
if (currentValue == null) {
curVal = new SQLLongint();
} else {
curVal = new SQLLongint(currentValue.longValue());
}
row.setColumn(SYSSEQUENCES_CURRENT_VALUE, curVal);
/* 6th column is STARTVALUE */
row.setColumn(SYSSEQUENCES_START_VALUE, new SQLLongint(startValue));
/* 7th column is MINIMUMVALUE */
row.setColumn(SYSSEQUENCES_MINIMUM_VALUE, new SQLLongint(minimumValue));
/* 8th column is MAXIMUMVALUE */
row.setColumn(SYSSEQUENCES_MAXIMUM_VALUE, new SQLLongint(maximumValue));
/* 9th column is INCREMENT */
row.setColumn(SYSSEQUENCES_INCREMENT, new SQLLongint(increment));
/* 10th column is CYCLEOPTION */
row.setColumn(SYSSEQUENCES_CYCLE_OPTION, new SQLChar(canCycle ? "Y" : "N"));
return row;
}
use of org.apache.derby.iapi.types.SQLChar in project derby by apache.
the class T_AccessFactory method nestedUserTransaction.
protected boolean nestedUserTransaction(TransactionController tc) throws StandardException, T_Fail {
REPORT("(nestedUserTransaction) starting");
// Test of drop conglomerate with abort by doing the following:
// create table
// commit
// drop table
// make sure table is not still there.
// abort
// make sure table is still there.
// Create a heap conglomerate.
long orig_conglomid = tc.createConglomerate(// create a heap conglomerate
"heap", // 1 SQLInteger() column template.
new T_AccessRow(1).getRowArray(), // column sort order not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
// Create a temporary heap conglomerate.
long tmp_conglomid = tc.createConglomerate(// create a heap conglomerate
"heap", // 1 SQLInteger() column template.
new T_AccessRow(1).getRowArray(), // column sort order not required for heap
null, // default collation
null, // default properties
null, TransactionController.IS_TEMPORARY);
TransactionController current_xact = store.getTransaction(getContextService().getCurrentContextManager());
// get a nested user transaction
TransactionController child_tc = tc.startNestedUserTransaction(true, true);
TransactionController current_xact_after_nest = store.getTransaction(getContextService().getCurrentContextManager());
if (current_xact_after_nest != current_xact) {
throw T_Fail.testFailMsg("(nestedUserTransaction) getTransaction() return changed after startNestedUserTransaction()." + "current_xact = " + current_xact + ";current_xact_after_nest = " + current_xact_after_nest);
}
T_Fail.T_ASSERT(tc.getLockSpace() == child_tc.getLockSpace(), "getLockSpace() returned different object for child.");
// the locks of the nested transaction should not conflict, so this
// open should work.
ConglomerateController cc = child_tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Make sure you can access the temporary conglomerate in the
// nested transaction.
ConglomerateController tmp_cc = child_tc.openConglomerate(tmp_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
cc.close();
tmp_cc.close();
child_tc.commit();
child_tc.destroy();
tc.dropConglomerate(orig_conglomid);
// trying to double nest a nested transaction should not work.
child_tc = tc.startNestedUserTransaction(true, true);
try {
child_tc.startNestedUserTransaction(true, true);
throw T_Fail.testFailMsg("(nestedUserTransaction) double nest xact not allowed.");
} catch (StandardException se) {
// expected exception, fall through.
}
child_tc.commit();
child_tc.destroy();
// make sure internal and ntt's work. Just add a bunch of data to
// the table causing page allocation.
String twok_string = new String("0123456789012345");
for (int i = 0; i < 7; i++) {
twok_string += twok_string;
}
T_AccessRow big_row = new T_AccessRow(2);
big_row.setCol(1, new SQLChar(twok_string));
// Create a heap conglomerate.
orig_conglomid = tc.createConglomerate(// create a heap conglomerate
"heap", big_row.getRowArray(), // column sort order not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
child_tc = tc.startNestedUserTransaction(true, true);
// add 20 pages worth of data, causing allocation
// the locks of the nested transaction should not conflict, so this
// open should work.
cc = child_tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
child_tc.abort();
child_tc.destroy();
try {
// the locks of the nested transaction should not conflict, so this
// open should work.
cc = tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
throw T_Fail.testFailMsg("(nestedUserTransaction) conglom should have been aborted.");
} catch (StandardException se) {
// expected exception, fall through.
}
tc.commit();
// same test as above, but this time commit parent xact create to
// make sure it stays around after the child abort.
// Create a heap conglomerate.
orig_conglomid = tc.createConglomerate(// create a heap conglomerate
"heap", big_row.getRowArray(), // column sort order not required for heap
null, // default properties
null, // default collation
null, // not temporary
TransactionController.IS_DEFAULT);
tc.commit();
child_tc = tc.startNestedUserTransaction(true, true);
// add 20 pages worth of data, causing allocation
// the locks of the nested transaction should not conflict, so this
// open should work.
cc = child_tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
/*
for (int i = 0; i < 40; i++)
{
big_row.setCol(0, new SQLInteger(i));
cc.insert(big_row.getRowArray());
}
*/
child_tc.abort();
child_tc.destroy();
try {
// the locks of the nested transaction should not conflict, so this
// open should work.
cc = tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
cc.close();
} catch (StandardException se) {
throw T_Fail.testFailMsg("(nestedUserTransaction) conglom should have not be aborted.");
}
// start an read only nested user transaction.
child_tc = tc.startNestedUserTransaction(true, true);
ConglomerateController child_cc = child_tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
try {
// should not be able to do an update in a read only transaction.
big_row.setCol(0, new SQLInteger(1042));
child_cc.insert(big_row.getRowArray());
throw T_Fail.testFailMsg("(nestedUserTransaction) read only xact does not allow upd.");
} catch (StandardException se) {
// expected exception, fall through.
child_tc.commit();
child_tc.destroy();
}
tc.commit();
// start an update nested user transaction.
child_tc = tc.startNestedUserTransaction(false, true);
child_cc = child_tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
try {
// should be able to do an update in a read only transaction.
big_row.setCol(0, new SQLInteger(1043));
child_cc.insert(big_row.getRowArray());
} catch (StandardException se) {
throw T_Fail.testFailMsg("(nestedUserTransaction) read only xact does not allow upd.");
}
// expected exception, fall through.
child_tc.commit();
child_tc.destroy();
tc.commit();
cc = tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE);
// start an update nested user transaction.
child_tc = tc.startNestedUserTransaction(false, true);
try {
// the following should time out, since locks are not compatible.
child_cc = child_tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
throw T_Fail.testFailMsg("(nestedUserTransaction) lock should have timed out.");
} catch (StandardException se) {
// expected timeout, fall through.
}
// expected exception, fall through.
child_tc.commit();
child_tc.destroy();
tc.commit();
REPORT("(nestedUserTransaction) finishing");
return true;
}
Aggregations