use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class SYSROLESRowFactory method buildDescriptor.
// /////////////////////////////////////////////////////////////////////////
//
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
//
// /////////////////////////////////////////////////////////////////////////
/**
* Make an Tuple Descriptor out of a SYSROLES row
*
* @param row a SYSROLES row
* @param parentTupleDescriptor unused
* @param dd dataDictionary
*
* @return a descriptor equivalent to a SYSROLES row
*
* @exception StandardException thrown on failure
*/
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
DataValueDescriptor col;
RoleGrantDescriptor descriptor;
String oid_string;
String roleid;
String grantee;
String grantor;
String wao;
String isdef;
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
if (SanityManager.DEBUG) {
SanityManager.ASSERT(row.nColumns() == SYSROLES_COLUMN_COUNT, "Wrong number of columns for a SYSROLES row");
}
// first column is uuid of this role grant descriptor (char(36))
col = row.getColumn(1);
oid_string = col.getString();
// second column is roleid (varchar(128))
col = row.getColumn(2);
roleid = col.getString();
// third column is grantee (varchar(128))
col = row.getColumn(3);
grantee = col.getString();
// fourth column is grantor (varchar(128))
col = row.getColumn(4);
grantor = col.getString();
// fifth column is withadminoption (char(1))
col = row.getColumn(5);
wao = col.getString();
// sixth column is isdef (char(1))
col = row.getColumn(6);
isdef = col.getString();
descriptor = ddg.newRoleGrantDescriptor(getUUIDFactory().recreateUUID(oid_string), roleid, grantee, grantor, wao.equals("Y") ? true : false, isdef.equals("Y") ? true : false);
return descriptor;
}
use of org.apache.derby.iapi.types.DataValueDescriptor 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.DataValueDescriptor in project derby by apache.
the class GenericParameterValueSet method transferDataValues.
/**
* @see ParameterValueSet#transferDataValues
*/
public void transferDataValues(ParameterValueSet pvstarget) throws StandardException {
// don't take application's values for return output parameters
int firstParam = pvstarget.hasReturnOutputParameter() ? 1 : 0;
for (int i = firstParam; i < parms.length; i++) {
GenericParameter oldp = parms[i];
if (oldp.registerOutType != Types.NULL) {
pvstarget.registerOutParameter(i, oldp.registerOutType, oldp.registerOutScale);
}
if (oldp.isSet) {
DataValueDescriptor dvd = oldp.getValue();
InputStream is = null;
// See if the value type can hold a stream.
if (dvd.hasStream()) {
// DERBY-4455: Don't materialize the stream when
// transferring it. If the stream has been drained already,
// and the user doesn't set a new value before executing
// the prepared statement again, Derby will fail.
pvstarget.getParameterForSet(i).setValue(dvd.getStream(), DataValueDescriptor.UNKNOWN_LOGICAL_LENGTH);
} else {
pvstarget.getParameterForSet(i).setValue(dvd);
}
}
}
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class PredicateList method searchClauseTransitiveClosure.
/**
* Perform transitive closure on search clauses. We build a
* list of search clauses of the form:
* <ColumnReference> <RelationalOperator> [<ConstantNode>]
* We also build a list of equijoin conditions of form:
* <ColumnReference1> = <ColumnReference2>
* where both columns are from different tables in the same query block.
* For each search clause in the list, we search the equijoin list to see
* if there is an equijoin clause on the same column. If so, then we
* search the search clause list for a search condition on the column
* being joined against with the same relation operator and constant. If
* a match is found, then there is no need to add a new predicate.
* Otherwise, we add a new search condition on the column being joined
* with. In either case, if the relational operator in the search
* clause is an "=" then we mark the equijoin clause as being redundant.
* Redundant equijoin clauses will be removed at the end of the search as
* they are * unnecessary.
*
* @param numTables The number of tables in the query
* @param hashJoinSpecified Whether or not user specified a hash join
*
* @exception StandardException Thrown on error
*/
void searchClauseTransitiveClosure(int numTables, boolean hashJoinSpecified) throws StandardException {
PredicateList equijoinClauses = new PredicateList(getContextManager());
PredicateList searchClauses = new PredicateList(getContextManager());
RelationalOperator equalsNode = null;
int size = size();
for (int index = 0; index < size; index++) {
AndNode andNode;
Predicate predicate;
predicate = elementAt(index);
andNode = predicate.getAndNode();
// Skip anything that's not a RelationalOperator
if (!predicate.isRelationalOpPredicate()) {
continue;
}
RelationalOperator operator = (RelationalOperator) andNode.getLeftOperand();
// Is this an equijoin?
if (((ValueNode) operator).isBinaryEqualsOperatorNode()) {
BinaryRelationalOperatorNode equals = (BinaryRelationalOperatorNode) operator;
// Remember any equals node for redundancy check at end
equalsNode = equals;
ValueNode left = equals.getLeftOperand();
ValueNode right = equals.getRightOperand();
if ((left instanceof ColumnReference && right instanceof ColumnReference)) {
ColumnReference leftCR = (ColumnReference) left;
ColumnReference rightCR = (ColumnReference) right;
if (leftCR.getSourceLevel() == rightCR.getSourceLevel() && leftCR.getTableNumber() != rightCR.getTableNumber()) {
equijoinClauses.addElement(predicate);
}
continue;
}
}
// Is this a usable search clause?
if (operator instanceof UnaryComparisonOperatorNode) {
if (((UnaryComparisonOperatorNode) operator).getOperand() instanceof ColumnReference) {
searchClauses.addElement(predicate);
}
continue;
} else if (operator instanceof BinaryComparisonOperatorNode) {
BinaryComparisonOperatorNode bcon = (BinaryComparisonOperatorNode) operator;
ValueNode left = bcon.getLeftOperand();
ValueNode right = bcon.getRightOperand();
// ConstantNode or ParameterNode in the future.
if (left instanceof ColumnReference && isConstantOrParameterNode(right)) {
searchClauses.addElement(predicate);
} else if (isConstantOrParameterNode(left) && right instanceof ColumnReference) {
// put the ColumnReference on the left to simplify things
andNode.setLeftOperand(bcon.getSwappedEquivalent());
searchClauses.addElement(predicate);
}
continue;
}
}
// Nothing to do if no search clauses or equijoin clauses
if (equijoinClauses.size() == 0 || searchClauses.size() == 0) {
return;
}
/* Now we do the real work.
* NOTE: We can append to the searchClauses while walking
* them, thus we cannot cache the value of size().
*/
for (int scIndex = 0; scIndex < searchClauses.size(); scIndex++) {
ColumnReference searchCR;
DataValueDescriptor searchODV = null;
RelationalOperator ro = (RelationalOperator) (searchClauses.elementAt(scIndex).getAndNode()).getLeftOperand();
// Find the ColumnReference and constant value, if any, in the search clause
if (ro instanceof UnaryComparisonOperatorNode) {
searchCR = (ColumnReference) ((UnaryComparisonOperatorNode) ro).getOperand();
} else {
searchCR = (ColumnReference) ((BinaryComparisonOperatorNode) ro).getLeftOperand();
// Don't get value for parameterNode since not known yet.
if (((BinaryComparisonOperatorNode) ro).getRightOperand() instanceof ConstantNode) {
ConstantNode currCN = (ConstantNode) ((BinaryComparisonOperatorNode) ro).getRightOperand();
searchODV = currCN.getValue();
} else
searchODV = null;
}
// Cache the table and column numbers of searchCR
int tableNumber = searchCR.getTableNumber();
int colNumber = searchCR.getColumnNumber();
// Look for any equijoin clauses of interest
for (Predicate predicate : equijoinClauses) {
/* Skip the current equijoin clause if it has already been used
* when adding a new search clause of the same type
* via transitive closure.
* NOTE: We check the type of the search clause instead of just the
* fact that a search clause was added because multiple search clauses
* can get added when preprocessing LIKE and BETWEEN.
*/
if (predicate.transitiveSearchClauseAdded(ro)) {
continue;
}
BinaryRelationalOperatorNode equals = (BinaryRelationalOperatorNode) predicate.getAndNode().getLeftOperand();
ColumnReference leftCR = (ColumnReference) equals.getLeftOperand();
ColumnReference rightCR = (ColumnReference) equals.getRightOperand();
ColumnReference otherCR;
if (leftCR.getTableNumber() == tableNumber && leftCR.getColumnNumber() == colNumber) {
otherCR = rightCR;
} else if (rightCR.getTableNumber() == tableNumber && rightCR.getColumnNumber() == colNumber) {
otherCR = leftCR;
} else {
// this is not a matching equijoin clause
continue;
}
/* At this point we've found a search clause and an equijoin that
* are candidates for adding a new search clause via transitive
* closure. Look to see if a matching search clause already
* exists on the other table. If not, then add one.
* NOTE: In either case we mark the join clause has having added
* a search clause of this type to short circuit any future searches
*/
predicate.setTransitiveSearchClauseAdded(ro);
boolean match = false;
ColumnReference searchCR2;
RelationalOperator ro2;
for (Predicate sc : searchClauses) {
DataValueDescriptor currODV = null;
ro2 = (RelationalOperator) sc.getAndNode().getLeftOperand();
// Find the ColumnReference in the search clause
if (ro2 instanceof UnaryComparisonOperatorNode) {
searchCR2 = (ColumnReference) ((UnaryComparisonOperatorNode) ro2).getOperand();
} else {
searchCR2 = (ColumnReference) ((BinaryComparisonOperatorNode) ro2).getLeftOperand();
if (((BinaryComparisonOperatorNode) ro2).getRightOperand() instanceof ConstantNode) {
ConstantNode currCN = (ConstantNode) ((BinaryComparisonOperatorNode) ro2).getRightOperand();
currODV = currCN.getValue();
} else
currODV = null;
}
/* Is this a match? A match is a search clause with
* the same operator on the same column with a comparison against
* the same value.
*/
if (searchCR2.getTableNumber() == otherCR.getTableNumber() && searchCR2.getColumnNumber() == otherCR.getColumnNumber() && ((currODV != null && searchODV != null && currODV.compare(searchODV) == 0) || (currODV == null && searchODV == null)) && ro2.getOperator() == ro.getOperator() && ro2.getClass().getName().equals(ro.getClass().getName())) {
match = true;
break;
}
}
// Add the new search clause if no match found
if (!match) {
// Build a new predicate
OperatorNode roClone = (OperatorNode) ro.getTransitiveSearchClause((ColumnReference) otherCR.getClone());
/* Set type info for the operator node */
if (roClone instanceof BinaryComparisonOperatorNode) {
((BinaryComparisonOperatorNode) roClone).bindComparisonOperator();
} else {
((UnaryComparisonOperatorNode) roClone).bindComparisonOperator();
}
// Convert the roClone into CNF:
//
// AND
// / \
// roClone true
//
ValueNode trueNode = new BooleanConstantNode(true, getContextManager());
AndNode newAnd = new AndNode(roClone, trueNode, getContextManager());
newAnd.postBindFixup();
// Add a new predicate to both the search clauses and this list
JBitSet tableMap = new JBitSet(numTables);
newAnd.categorize(tableMap, false);
Predicate newPred = new Predicate(newAnd, tableMap, getContextManager());
addPredicate(newPred);
searchClauses.addElement(newPred);
}
}
}
/* Finally, we eliminate any equijoin clauses made redundant by
* transitive closure, but only if the user did not specify a hash join
* in the current query block.
*/
if (hashJoinSpecified) {
return;
}
/* Walk list backwards since we can delete while
* traversing the list.
*/
for (int index = size() - 1; index >= 0; index--) {
Predicate predicate = elementAt(index);
if (predicate.transitiveSearchClauseAdded(equalsNode)) {
removeElementAt(index);
}
}
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class QueryTreeNode method bindOffsetFetch.
/**
* Bind the parameters of OFFSET n ROWS and FETCH FIRST n ROWS ONLY, if
* any.
*
* @param offset the OFFSET parameter, if any
* @param fetchFirst the FETCH parameter, if any
*
* @exception StandardException Thrown on error
*/
public static void bindOffsetFetch(ValueNode offset, ValueNode fetchFirst) throws StandardException {
if (offset instanceof ConstantNode) {
DataValueDescriptor dvd = ((ConstantNode) offset).getValue();
long val = dvd.getLong();
if (val < 0) {
throw StandardException.newException(SQLState.LANG_INVALID_ROW_COUNT_OFFSET, Long.toString(val));
}
} else if (offset instanceof ParameterNode) {
offset.setType(new DataTypeDescriptor(TypeId.getBuiltInTypeId(Types.BIGINT), false));
}
if (fetchFirst instanceof ConstantNode) {
DataValueDescriptor dvd = ((ConstantNode) fetchFirst).getValue();
long val = dvd.getLong();
if (val < 1) {
throw StandardException.newException(SQLState.LANG_INVALID_ROW_COUNT_FIRST, Long.toString(val));
}
} else if (fetchFirst instanceof ParameterNode) {
fetchFirst.setType(new DataTypeDescriptor(TypeId.getBuiltInTypeId(Types.BIGINT), false));
}
}
Aggregations