Methods Summary |
---|
public void | addColumn(org.netbeans.modules.dbschema.ColumnElement columnElement, java.lang.Object value)
addColumnRef(new ColumnRef(columnElement, value));
|
protected void | addConstraint(org.netbeans.modules.dbschema.ColumnElement columnElement, com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc lf, java.lang.Object value)Batch helper method. Adds the columnElement to the list of
ColumnRefs for the where clause and then calls addConstraint.
columnRefsForWhereClause.add(new ColumnRef(columnElement, value));
addConstraint(lf, value);
|
public void | addForeignConstraints(int action, com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc f, com.sun.jdo.spi.persistence.support.sqlstore.SQLStateManager sm)
for (int i = 0; i < f.foreignFields.size(); i++) {
LocalFieldDesc ff = (LocalFieldDesc) f.foreignFields.get(i);
if (action == QueryPlan.ACT_INSERT) {
// For inserts into the join table, we get the values we are inserting
// for the parent object and the added object.
ColumnElement fc = (ColumnElement) f.assocForeignColumns.get(i);
addColumn(fc, ff.getValue(sm));
} else if (action == QueryPlan.ACT_DELETE) {
LocalFieldDesc aff = (LocalFieldDesc) f.assocForeignFields.get(i);
// For deletes from the join table, we get the constraint values
// from the parent object and the remove object.
addConstraint(aff, ff.getValue(sm));
}
}
|
public void | addLocalConstraints(int action, com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc f, com.sun.jdo.spi.persistence.support.sqlstore.SQLStateManager sm)
for (int i = 0; i < f.localFields.size(); i++) {
LocalFieldDesc lf = (LocalFieldDesc) f.localFields.get(i);
if (action == QueryPlan.ACT_INSERT) {
// For inserts into the join table, we get the values we are inserting
// for the parent object and the added object.
ColumnElement lc = (ColumnElement) f.assocLocalColumns.get(i);
addColumn(lc, lf.getValue(sm));
} else if (action == QueryPlan.ACT_DELETE) {
LocalFieldDesc alf = (LocalFieldDesc) f.assocLocalFields.get(i);
// For deletes from the join table, we get the constraint values
// from the parent object and the remove object.
addConstraint(alf, lf.getValue(sm));
}
}
|
public void | addVersionColumn(org.netbeans.modules.dbschema.ColumnElement versionColumn)
if (versionColumns == null) {
versionColumns = new ArrayList();
}
versionColumns.add(versionColumn);
|
private void | appendVersionColumnUpdateClause(java.lang.StringBuffer setClause)Appends clause to update version column. The generated clause will be of
the following form
versionColumnName = versionColumnNane + 1
if(UPDATE_VERSION_COL) {
if (versionColumns != null)
{
for (int i = 0; i < versionColumns.size(); i++) {
ColumnElement columnElement = (ColumnElement) versionColumns.get(i);
String columnName = columnElement.getName().getName();
setClause.append(", ");
appendQuotedText(setClause, columnName);
setClause.append(" = ");
appendQuotedText(setClause, columnName);
setClause.append(" + ");
setClause.append("1");
}
}
}
|
private void | bindInputColumn(DBStatement stmt, ColumnRef columnRef, com.sun.jdo.spi.persistence.support.sqlstore.sql.UpdateObjectDescImpl updateDesc, boolean getBeforeValue)Binds the value in the specified update descriptor corresponding
with the specified column reference to the specified statement.
Object inputValue = getInputValue(updateDesc, columnRef, getBeforeValue);
stmt.bindInputColumn(columnRef.getIndex(), inputValue,
columnRef.getColumnElement(), vendorType);
|
public void | bindInputColumns(DBStatement s, com.sun.jdo.spi.persistence.support.sqlstore.sql.UpdateObjectDescImpl updateDesc)
// bind set clause (if necessary)
for (Iterator i = getColumnRefs().iterator(); i.hasNext(); ) {
bindInputColumn(s, (ColumnRef)i.next(), updateDesc, false );
}
// bind where clause (if necessary)
for (Iterator i = columnRefsForWhereClause.iterator(); i.hasNext(); ) {
bindInputColumn(s, (ColumnRef) i.next(), updateDesc,
updateDesc.isBeforeImageRequired());
}
|
private void | calculateWhereClauseColumnRefIndexes()Calculates the index of the where clause ColumnRefs
// calculate where clause column ref indexes
// NOTE, the sqlstore processes the constraints in reverse order,
// so start with the last index and decrement
int nextIndex = columns.size() + columnRefsForWhereClause.size();
for (Iterator i = columnRefsForWhereClause.iterator(); i.hasNext(); ) {
ColumnRef columnRef = (ColumnRef)i.next();
columnRef.setIndex(nextIndex--);
}
|
public boolean | exceedsBatchThreshold(com.sun.jdo.spi.persistence.support.sqlstore.Transaction tran)
synchronized (dbStatementCache)
{
DBStatement dbStatement = (DBStatement)dbStatementCache.get(tran);
return (dbStatement != null) && dbStatement.exceedsBatchThreshold();
}
|
private java.lang.StringBuffer | generateColumnText()
StringBuffer columnList = new StringBuffer();
int numValues = -1;
for (int i = 0; i < columns.size(); i++) {
ColumnRef c = (ColumnRef) columns.get(i);
if (columnList.length() > 0) {
columnList.append(", "); // NOI18N
}
switch (action) {
case QueryPlan.ACT_UPDATE:
appendQuotedText(columnList, c.getName());
columnList.append("= ?"); // NOI18N
break;
case QueryPlan.ACT_INSERT:
appendQuotedText(columnList, c.getName());
if (i == 0) {
values = new StringBuffer().append(" ?"); // NOI18N
} else {
values.append(", ?"); // NOI18N
}
break;
}
// Do not create an InputValue in the case of batch update.
// Method bindInputValues will get the value using the ColumnRef.
if (!batch &&
((action == QueryPlan.ACT_UPDATE) ||
(action == QueryPlan.ACT_INSERT))) {
numValues = numValues + 1;
InputValue val = new InputValue(c.getValue(), c.getColumnElement());
inputDesc.values.add(numValues, val);
}
}
appendVersionColumnUpdateClause(columnList);
return columnList;
|
protected void | generateStatementText()
statementText = new StringBuffer();
StringBuffer columnList = generateColumnText();
StringBuffer constraint = processConstraints();
String tableName = ((QueryTable) tableList.get(0)).getTableDesc().getName();
// Create the query filling in the column list, table name, etc.
switch (action) {
case QueryPlan.ACT_UPDATE:
statementText.append("update ");// NOI18N
appendQuotedText(statementText, tableName);
statementText.append(" set ").append(columnList).append(" where ").append(constraint); // NOI18N
break;
case QueryPlan.ACT_DELETE:
statementText.append("delete from ");// NOI18N
appendQuotedText(statementText, tableName);
statementText.append(" where ").append(constraint); // NOI18N
break;
case QueryPlan.ACT_INSERT:
statementText.append("insert into ");// NOI18N
appendQuotedText(statementText, tableName);
statementText.append("(").append(columnList).// NOI18N
append(") values ").append("(").append(values).append(")"); // NOI18N
break;
}
calculateWhereClauseColumnRefIndexes();
|
public DBStatement | getDBStatement(com.sun.jdo.spi.persistence.support.sqlstore.Transaction tran, java.sql.Connection conn)Returns the cached db statement for the specified connection.
If there is not any statement for this connection in the cache,
then a new statement is created.
DBStatement dbStatement = null;
synchronized (dbStatementCache)
{
// dbStatement cachelookup
dbStatement = (DBStatement)dbStatementCache.get(tran);
if (dbStatement == null) {
dbStatement = new DBStatement(conn, getText(),
tran.getUpdateTimeout());
// put dbStatement in cache
dbStatementCache.put(tran, dbStatement);
}
}
return dbStatement;
|
public java.lang.String | getFormattedSQLText(com.sun.jdo.spi.persistence.support.sqlstore.sql.UpdateObjectDescImpl updateDesc)Gets formatted sql text corrsponding to this statement object. The text
also contains values for input to the statement.
return formatSqlText(getText(), getInputValues(updateDesc));
|
private static java.lang.Object | getInputValue(com.sun.jdo.spi.persistence.support.sqlstore.sql.UpdateObjectDescImpl updateDesc, ColumnRef columnRef, boolean getBeforeValue)Gets input value corrsponding to given columnRef from given updateDesc
Object value;
LocalFieldDesc field = (LocalFieldDesc) columnRef.getValue();
if (field.isVersion()) {
// Bind the value from the after image for version fields,
// as they're incremented internally after each flush.
// Version fields must not be modified from "outside".
value = updateDesc.getAfterValue(field);
} else {
value = getBeforeValue ? updateDesc.getBeforeValue(field) :
updateDesc.getAfterValue(field);
}
return value;
|
private java.lang.Object[] | getInputValues(com.sun.jdo.spi.persistence.support.sqlstore.sql.UpdateObjectDescImpl updateDesc)Get Input values to be bound to this statement.
Object[] inputValues =
new Object[getColumnRefs().size() + columnRefsForWhereClause.size()];
for (Iterator i = getColumnRefs().iterator(); i.hasNext(); ) {
ColumnRef columnRef = (ColumnRef)i.next();
// columnRef's index are 1 based.
inputValues[columnRef.getIndex() - 1] = getInputValue(updateDesc, columnRef, false);
}
final boolean getBeforeValue = updateDesc.isBeforeImageRequired();
for (Iterator i = columnRefsForWhereClause.iterator(); i.hasNext(); ) {
ColumnRef columnRef = (ColumnRef)i.next();
inputValues[columnRef.getIndex() - 1] = getInputValue(updateDesc, columnRef, getBeforeValue);
}
return inputValues;
|
public QueryPlan | getQueryPlan()
return plan;
|
public boolean | isConstraintAdded()
return isConstraintAdded;
|
public void | markConstraintAdded()
isConstraintAdded = true;
|
protected void | processConstraintValue(com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint.ConstraintValue node, java.lang.StringBuffer result)Redefines processConstraintValue in order to skip the creation of
an InputValue in the case of batch.
result.append("?"); // NOI18N
if (!batch)
generateInputValueForConstraintValueNode(node);
|
public DBStatement | removeDBStatement(com.sun.jdo.spi.persistence.support.sqlstore.Transaction tran)Removes the db statement for the specified connection from the cache
and closes this statement.
synchronized (dbStatementCache)
{
DBStatement s = (DBStatement)dbStatementCache.remove(tran);
return s;
}
|