/** * Build the select statement for selecting the locator */ private SQLSelectStatement buildSelectStatementForLocator(WriteObjectQuery writeQuery, DatabaseCall call, AbstractSession session) { SQLSelectStatement selectStatement = new SQLSelectStatement(); Vector tables = writeQuery.getDescriptor().getTables(); selectStatement.setTables(tables); //rather than get ALL fields from the descriptor, only use the LOB-related fields to build the minimal SELECT statement. selectStatement.setFields(call.getContexts().getFields()); //the where clause setting here is sufficient if the object does not map to multiple tables. selectStatement.setWhereClause(writeQuery.getDescriptor().getObjectBuilder().buildPrimaryKeyExpressionFromObject(writeQuery.getObject(), session)); //need pessimistic locking for the locator select selectStatement.setLockingClause(ForUpdateClause.newInstance(ObjectBuildingQuery.LOCK)); if (tables.size() > 1) { //the primary key expression from the primary table Expression expression = selectStatement.getWhereClause(); //additioanl join from the non-primary tables Expression additionalJoin = (Expression)writeQuery.getDescriptor().getQueryManager().getAdditionalJoinExpression(); if (additionalJoin != null) { expression = expression.and(additionalJoin); } //where clause now contains extra joins across all tables selectStatement.setWhereClause(expression); } //normalize the statement at the end, such as assign alias to all tables, and build sorting statement selectStatement.normalize(session, writeQuery.getDescriptor()); return selectStatement; }
Expression keyExpression = first.getDescriptor().getObjectBuilder().buildPrimaryKeyExpressionFromObject(((ConstantExpression)getSecondChild()).getValue(), getSession()); foreignKeyJoin = first.twist(keyExpression, first);