use of org.apache.cayenne.map.Procedure in project cayenne by apache.
the class HSQLDBProcedureTranslator method createSqlString.
/**
* Creates HSQLDB-compliant SQL to execute a stored procedure.
*/
@Override
protected String createSqlString() {
Procedure procedure = getProcedure();
StringBuilder buf = new StringBuilder();
int totalParams = callParams.size();
// check if procedure returns values
if (procedure.isReturningValue()) {
totalParams--;
// HSQL won't accept "? =". The parser only recognizes "?="
// TODO: Andrus, 12/12/2005 - this is kind of how it is in the
// CallableStatement javadocs, so we may need to make "?=" a default ... this
// requires testing on Oracle/PostgreSQL/Sybase/SQLServer.
buf.append("{?= call ");
} else {
buf.append("{call ");
}
// be enclosed in quotes. It is not clear that quotes can always be used, though
if (procedure.getFullyQualifiedName().indexOf('.') > -1) {
buf.append("\"").append(procedure.getFullyQualifiedName()).append("\"");
} else {
buf.append(procedure.getFullyQualifiedName());
}
if (totalParams > 0) {
// unroll the loop
buf.append("(?");
for (int i = 1; i < totalParams; i++) {
buf.append(", ?");
}
buf.append(")");
}
buf.append("}");
return buf.toString();
}
use of org.apache.cayenne.map.Procedure in project cayenne by apache.
the class ProcedureDisplayEventType method fireLastDisplayEvent.
@Override
public void fireLastDisplayEvent() {
DataChannelDescriptor dataChannel = (DataChannelDescriptor) controller.getProject().getRootNode();
if (!dataChannel.getName().equals(preferences.getDomain())) {
return;
}
DataMap dataMap = dataChannel.getDataMap(preferences.getDataMap());
if (dataMap == null) {
return;
}
Procedure procedure = dataMap.getProcedure(preferences.getProcedure());
if (procedure == null) {
return;
}
ProcedureDisplayEvent procedureDisplayEvent = new ProcedureDisplayEvent(this, procedure, dataMap, dataChannel);
controller.fireProcedureDisplayEvent(procedureDisplayEvent);
}
use of org.apache.cayenne.map.Procedure in project cayenne by apache.
the class DataContextProcedureQueryIT method testSelectWithRowDescriptor.
@Test
public void testSelectWithRowDescriptor() throws Exception {
if (!accessStackAdapter.supportsStoredProcedures()) {
return;
}
// create an artist with painting in the database
createArtist(1000.0);
// test ProcedureQuery with Procedure as root
Procedure proc = context.getEntityResolver().getProcedure(SELECT_STORED_PROCEDURE);
ProcedureQuery q = new ProcedureQuery(proc);
q.setFetchingDataRows(true);
q.addParameter("aName", "An Artist");
q.addParameter("paintingPrice", new Integer(3000));
// TESTING THIS ***
// A.ARTIST_ID, A.DATE_OF_BIRTH, A.ARTIST_NAME
ColumnDescriptor[] columns = new ColumnDescriptor[3];
// read ID as Long, and everything else as default types
columns[0] = new ColumnDescriptor("ARTIST_ID", Types.BIGINT);
columns[1] = new ColumnDescriptor("ARTIST_NAME", Types.CHAR);
columns[2] = new ColumnDescriptor("DATE_OF_BIRTH", Types.DATE);
q.addResultDescriptor(columns);
List<?> rows = runProcedureSelect(q);
// check the results
assertNotNull("Null result from StoredProcedure.", rows);
assertEquals(1, rows.size());
DataRow artistRow = (DataRow) rows.get(0);
assertEquals(3, artistRow.size());
artistRow = uppercaseConverter(artistRow);
Object id = artistRow.get("ARTIST_ID");
assertNotNull(id);
assertTrue("Expected Long, got: " + id.getClass().getName(), id instanceof Long);
}
use of org.apache.cayenne.map.Procedure in project cayenne by apache.
the class SybaseUnitDbAdapter method dropProcedures.
protected void dropProcedures(Connection con, DataMap map) throws Exception {
Procedure proc = map.getProcedure("cayenne_tst_select_proc");
if (proc != null && proc.getDataMap() == map) {
executeDDL(con, "sybase", "drop-select-sp.sql");
executeDDL(con, "sybase", "drop-update-sp.sql");
executeDDL(con, "sybase", "drop-update-sp2.sql");
executeDDL(con, "sybase", "drop-out-sp.sql");
}
}
use of org.apache.cayenne.map.Procedure in project cayenne by apache.
the class SchemaBuilder method initNode.
private void initNode(DataMap map) throws Exception {
DataNode node = new DataNode(map.getName());
node.setJdbcEventLogger(jdbcEventLogger);
node.setAdapter(dbAdapter);
node.setDataSource(dataSourceFactory.getSharedDataSource());
// setup test extended types
node.getAdapter().getExtendedTypes().registerType(new StringET1ExtendedType());
// tweak mapping with a delegate
for (Procedure proc : map.getProcedures()) {
unitDbAdapter.tweakProcedure(proc);
}
filterDataMap(map);
node.addDataMap(map);
node.setSchemaUpdateStrategy(new SkipSchemaUpdateStrategy());
node.setRowReaderFactory(new DefaultRowReaderFactory());
node.setBatchTranslatorFactory(new DefaultBatchTranslatorFactory());
node.setSelectTranslatorFactory(new DefaultSelectTranslatorFactory());
domain.addNode(node);
}
Aggregations