Search in sources :

Example 16 with Procedure

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();
}
Also used : Procedure(org.apache.cayenne.map.Procedure)

Example 17 with Procedure

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);
}
Also used : ProcedureDisplayEvent(org.apache.cayenne.modeler.event.ProcedureDisplayEvent) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) Procedure(org.apache.cayenne.map.Procedure) DataMap(org.apache.cayenne.map.DataMap)

Example 18 with Procedure

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);
}
Also used : ColumnDescriptor(org.apache.cayenne.access.jdbc.ColumnDescriptor) Procedure(org.apache.cayenne.map.Procedure) DataRow(org.apache.cayenne.DataRow) ProcedureQuery(org.apache.cayenne.query.ProcedureQuery) Test(org.junit.Test)

Example 19 with Procedure

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");
    }
}
Also used : Procedure(org.apache.cayenne.map.Procedure)

Example 20 with Procedure

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);
}
Also used : DefaultRowReaderFactory(org.apache.cayenne.access.jdbc.reader.DefaultRowReaderFactory) SkipSchemaUpdateStrategy(org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy) DefaultSelectTranslatorFactory(org.apache.cayenne.access.translator.select.DefaultSelectTranslatorFactory) DataNode(org.apache.cayenne.access.DataNode) StringET1ExtendedType(org.apache.cayenne.testdo.extended_type.StringET1ExtendedType) Procedure(org.apache.cayenne.map.Procedure) DefaultBatchTranslatorFactory(org.apache.cayenne.access.translator.batch.DefaultBatchTranslatorFactory)

Aggregations

Procedure (org.apache.cayenne.map.Procedure)38 DataMap (org.apache.cayenne.map.DataMap)14 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)8 DbEntity (org.apache.cayenne.map.DbEntity)7 ProcedureParameter (org.apache.cayenne.map.ProcedureParameter)7 ProcedureEvent (org.apache.cayenne.configuration.event.ProcedureEvent)6 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)6 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)5 Embeddable (org.apache.cayenne.map.Embeddable)5 ObjEntity (org.apache.cayenne.map.ObjEntity)5 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)5 Test (org.junit.Test)4 ProjectController (org.apache.cayenne.modeler.ProjectController)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DataRow (org.apache.cayenne.DataRow)2 DataNode (org.apache.cayenne.access.DataNode)2 PatternFilter (org.apache.cayenne.dbsync.reverse.filters.PatternFilter)2 DbAttribute (org.apache.cayenne.map.DbAttribute)2 DbRelationship (org.apache.cayenne.map.DbRelationship)2 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)2