use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class SelectQueryPlan method addColumn.
/**
* The addColumn method is used to specify a field for which data needs to
* be retrieved and therefore for which we need to select a column.
*
* @param fieldDesc The field for which we need to retrieve data and therefore
* for which we need to select a column.
* @param add Specifies if the field will be added to {@link ResultDesc}.
* @param projection Pass the projection information for this field
* to {@link ResultDesc}.
*/
private void addColumn(LocalFieldDesc fieldDesc, boolean add, boolean projection) {
//
for (Iterator iter = fieldDesc.getColumnElements(); iter.hasNext(); ) {
ColumnElement columnElement = (ColumnElement) iter.next();
QueryTable table = findQueryTable(columnElement.getDeclaringTable());
if (table == null)
table = addQueryTable(columnElement.getDeclaringTable(), null);
SelectStatement statement = (SelectStatement) getStatement(table);
if (statement == null)
statement = (SelectStatement) addStatement(table);
if (add) {
ColumnRef columnRef = statement.addColumn(columnElement, table);
// initialize the resultDesc
if (resultDesc == null) {
resultDesc = new ResultDesc(config, aggregateResultType);
}
resultDesc.addField(fieldDesc, columnRef, projection);
}
}
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class SelectStatement method generateForUpdateClause.
private StringBuffer generateForUpdateClause(boolean updateLockRequired) {
StringBuffer forUpdateClause = new StringBuffer();
if (updateLockRequired) {
// Check if vendor actually supports updatelock
if (!vendorType.isUpdateLockSupported()) {
// But vendor is not supporting it. Do not allow user to proceed
throw new JDOFatalDataStoreException(I18NHelper.getMessage(messages, // NOI18N
"sqlstore.selectstatement.noupdatelocksupport"));
}
// generating the ForUpdate Clause
String vendorForUpdate = vendorType.getForUpdate().trim();
boolean vendorHasForUpdateClause = (vendorForUpdate.length() != 0);
if (vendorHasForUpdateClause) {
forUpdateClause.append(" ").append(vendorForUpdate).append(" ");
if (vendorType.isLockColumnListSupported()) {
for (int i = 0; i < tableList.size(); i++) {
QueryTable queryTable = (QueryTable) tableList.get(i);
if (isUpdateLockRequired(queryTable)) {
TableDesc tableDesc = queryTable.getTableDesc();
// Get the first column of primary key
ColumnElement ce = (ColumnElement) tableDesc.getKey().getColumns().get(0);
// NOI18N
forUpdateClause.append("t").append(i).append(".");
appendQuotedText(forUpdateClause, ce.getName().getName());
// NOI18N
forUpdateClause.append(", ");
}
}
// Remove trailing ", "
forUpdateClause.delete(forUpdateClause.length() - 2, forUpdateClause.length());
}
}
}
return forUpdateClause;
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class SelectStatement method generateJoin.
/**
* Generate a "regular" join. The columns for the join condition
* end up in the where clause. The corresponding tables are added
* directly to the member variable tableList.
* Note that this method is normally called to process EQUI- joins
* only. For databases that are marked for native join sematics,
* this method will be called to process both EQUI- and OUTER- joins.
*
* @param jnode Join constraint.
* @param whereText String buffer taking the join condition. Generated
* join condition is appended to this string buffer.
* @param opCode Join operation.
*/
private void generateJoin(ConstraintJoin jnode, StringBuffer whereText, int opCode) {
for (int i = 0; i < jnode.fromColumns.size(); i++) {
ColumnElement fromColumn = (ColumnElement) jnode.fromColumns.get(i);
ColumnElement toColumn = (ColumnElement) jnode.toColumns.get(i);
QueryTable fromTable = findQueryTable(jnode.fromPlan, fromColumn);
QueryTable toTable = findQueryTable(jnode.toPlan, toColumn);
addQueryTable(fromTable);
addQueryTable(toTable);
toTable.prevTable = null;
appendJoinCondition(whereText, fromTable, toTable, fromColumn, toColumn, getJoinOperator(opCode));
if (opCode == ActionDesc.OP_LEFTJOIN) {
// Append oracle style (+) or similar.
whereText.append(vendorType.getLeftJoinPost());
}
}
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class Statement method getColumnElementForValueNode.
/**
* Gets the column information for the field to which <code>node</code>
* is bound.
* @param node The input node.
* @return Returns null if the node isn't bound to a field. Otherwise
* returns ColumnElement for the primary column of the field to which the
* node is bound.
*/
private static ColumnElement getColumnElementForValueNode(ConstraintValue node) {
ColumnElement columnElement = null;
LocalFieldDesc field = node.getLocalField();
if (field != null) {
// For fields mapped to multiple columns, we assume
// that all the columns have the same value in the database.
// Hence we only use the primary column in where clause.
columnElement = field.getPrimaryColumn();
}
return columnElement;
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class Statement method generateColumnText.
/**
* Generates the column text for field <code>desc</code>.
* The column has to be associated to the corresponding query table
* from the list <code>tableList</code>.
* For fields mapped to multiple columns choose one column to be included,
* as all mapped columns should have the same value.
*
* @param desc Local field descriptor to be included in the constraint text.
* @param thePlan Query plan corresponding to <code>desc</code>.
* @param sb String buffer taking the resulting text.
*/
protected void generateColumnText(LocalFieldDesc desc, QueryPlan thePlan, StringBuffer sb) {
QueryTable table = null;
ColumnElement column = null;
Iterator iter = desc.getColumnElements();
while (iter.hasNext() && table == null) {
column = (ColumnElement) iter.next();
// from the query plan to find the table matching the column.
if (action == QueryPlan.ACT_SELECT) {
table = thePlan.findQueryTable(column.getDeclaringTable());
} else {
table = findQueryTable(column.getDeclaringTable());
}
}
if (table == null) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
"core.configuration.fieldnotable", desc.getName()));
}
// Qualify the column with the table index.
if (action == QueryPlan.ACT_SELECT) {
// NOI18N
sb.append("t").append(table.getTableIndex()).append(".");
}
appendQuotedText(sb, column.getName().getName());
}
Aggregations