use of org.eclipse.persistence.internal.databaseaccess.DatabaseCall in project eclipselink by eclipse-ee4j.
the class StoredProcedureObjectRelationalParameters method getInsertCall.
public DatabaseCall getInsertCall() {
DatabaseCall call = null;
if (useCustomSQL) {
String sqlString = "BEGIN SProc_Insert_PHolders(#ssn, #occupation, #sex, " + "#firstName, #birthDate, #lastName, #address, #childrenNames, #phones); END;";
SQLCall sqlcall = new SQLCall(sqlString);
// most are not needed unless null it to be passed in
sqlcall.setCustomSQLArgumentType("ssn", Long.class);
sqlcall.setCustomSQLArgumentType("occupation", String.class);
sqlcall.setCustomSQLArgumentType("sex", Character.class);
sqlcall.setCustomSQLArgumentType("firstName", String.class);
sqlcall.setCustomSQLArgumentType("birthDate", java.sql.Date.class);
sqlcall.setCustomSQLArgumentType("lastName", String.class);
// address arg type isn't needed to convert Address to a Struct
sqlcall.setCustomSQLArgumentType("address", Types.STRUCT, "ADDRESS_TYPE");
sqlcall.setCustomSQLArgumentType("childrenNames", Types.ARRAY, "NAMELIST_TYPE");
sqlcall.setCustomSQLArgumentType("phones", Types.ARRAY, "PHONELIST_TYPE");
call = sqlcall;
} else {
StoredProcedureCall spcall = new StoredProcedureCall();
spcall.setProcedureName("SProc_Insert_PHolders");
spcall.addUnamedArgument("ssn", Long.class);
spcall.addUnamedArgument("occupation", String.class);
spcall.addUnamedArgument("sex", Character.class);
spcall.addUnamedArgument("firstName", String.class);
spcall.addUnamedArgument("birthDate", java.sql.Date.class);
spcall.addUnamedArgument("lastName", String.class);
// address arg type isn't needed to convert Address to a Struct
spcall.addUnamedArgument("address", Types.STRUCT, "ADDRESS_TYPE");
// test just passing in array objects (or nulls)
spcall.addUnamedArgument("childrenNames", Types.ARRAY, "NAMELIST_TYPE");
spcall.addUnamedArgument("phones", Types.ARRAY, "PHONELIST_TYPE");
call = spcall;
}
return call;
}
use of org.eclipse.persistence.internal.databaseaccess.DatabaseCall in project eclipselink by eclipse-ee4j.
the class SQLStatement method toString.
/**
* Try to print the SQL.
*/
@Override
public String toString() {
StringWriter writer = new StringWriter();
writer.write(Helper.getShortClassName(getClass()));
writer.write("(");
try {
DatabaseCall call = buildCall(new DatabaseSessionImpl(new org.eclipse.persistence.sessions.DatabaseLogin()));
writer.write(call.getSQLString());
} catch (Exception exception) {
}
writer.write(")");
return writer.toString();
}
use of org.eclipse.persistence.internal.databaseaccess.DatabaseCall in project eclipselink by eclipse-ee4j.
the class LOBValueWriter method buildCallFromSelectStatementForLocator.
/**
* Build the sql call from the select statement for selecting the locator
*/
private DatabaseCall buildCallFromSelectStatementForLocator(SQLSelectStatement selectStatement, WriteObjectQuery writeQuery, DatabaseCall dbCall, AbstractSession session) {
DatabaseCall call = selectStatement.buildCall(session);
// Locator LOB must not be wrapped (WLS wraps LOBs).
call.setIsNativeConnectionRequired(this.isNativeConnectionRequired);
// the LOB context must be passed into the new call object
call.setContexts(dbCall.getContexts());
// need to explicitly define one row return, otherwise, EL assumes multiple rows return and confuses the accessor
call.returnOneRow();
// the query object has to be set in order to access to the platform and login objects
call.setQuery(writeQuery);
// prepare it
call.prepare(session);
// finally do the translation
call.translate(writeQuery.getTranslationRow(), writeQuery.getModifyRow(), session);
return call;
}
use of org.eclipse.persistence.internal.databaseaccess.DatabaseCall in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method selectAllRowsFromConcreteTable.
/**
* Read all rows from the database.
* This is used only from query mechanism on a abstract-multiple table read.
*/
public Vector selectAllRowsFromConcreteTable() throws DatabaseException {
ObjectLevelReadQuery query = (ObjectLevelReadQuery) this.query;
// PERF: First check the subclass calls cache for the prepared call.
// Must clear the translation row to avoid in-lining parameters unless not a prepared query.
boolean shouldPrepare = query.shouldPrepare();
DatabaseCall call = null;
if (shouldPrepare) {
call = query.getConcreteSubclassCalls().get(query.getReferenceClass());
}
if (call == null) {
AbstractRecord translationRow = query.getTranslationRow();
if (shouldPrepare) {
query.setTranslationRow(null);
}
setSQLStatement(buildConcreteSelectStatement());
// Must also build the call.
super.prepareSelectAllRows();
if (shouldPrepare) {
if (query.hasJoining()) {
query.getConcreteSubclassJoinedMappingIndexes().put(query.getReferenceClass(), query.getJoinedAttributeManager().getJoinedMappingIndexes_());
}
query.getConcreteSubclassCalls().put(query.getReferenceClass(), (DatabaseCall) this.call);
query.setTranslationRow(translationRow);
}
} else {
setCall(call);
if (shouldPrepare && query.hasJoining()) {
query.getJoinedAttributeManager().setJoinedMappingIndexes_(query.getConcreteSubclassJoinedMappingIndexes().get(query.getReferenceClass()));
}
}
return super.selectAllRows();
}
use of org.eclipse.persistence.internal.databaseaccess.DatabaseCall in project eclipselink by eclipse-ee4j.
the class DatasourceCallQueryMechanism method selectResultSet.
/**
* Read all rows from the database, return ResultSet
* @exception DatabaseException - an error has occurred on the database
*/
public DatabaseCall selectResultSet() throws DatabaseException {
try {
// For CR 2923 must move to session we will execute call on now
// so correct DatasourcePlatform used by translate.
AbstractSession sessionToUse = this.query.getExecutionSession();
DatabaseCall clonedCall = (DatabaseCall) this.call.clone();
clonedCall.setQuery(this.query);
clonedCall.translate(this.query.getTranslationRow(), getModifyRow(), sessionToUse);
clonedCall.returnCursor();
return (DatabaseCall) sessionToUse.executeCall(clonedCall, this.query.getTranslationRow(), this.query);
} catch (java.lang.ClassCastException e) {
throw QueryException.invalidDatabaseCall(this.call);
}
}
Aggregations