Search in sources :

Example 11 with Procedure

use of org.apache.cayenne.map.Procedure in project cayenne by apache.

the class MySQLUnitDbAdapter method willDropTables.

@Override
public void willDropTables(Connection conn, DataMap map, Collection<String> tablesToDrop) throws Exception {
    Procedure proc = map.getProcedure("cayenne_tst_select_proc");
    if (proc != null && proc.getDataMap() == map) {
        executeDDL(conn, "mysql", "drop-select-sp.sql");
        executeDDL(conn, "mysql", "drop-update-sp.sql");
        executeDDL(conn, "mysql", "drop-update-sp2.sql");
        executeDDL(conn, "mysql", "drop-out-sp.sql");
    }
}
Also used : Procedure(org.apache.cayenne.map.Procedure)

Example 12 with Procedure

use of org.apache.cayenne.map.Procedure in project cayenne by apache.

the class SybaseUnitDbAdapter method createdTables.

@Override
public void createdTables(Connection con, DataMap map) throws Exception {
    Procedure proc = map.getProcedure("cayenne_tst_select_proc");
    if (proc != null && proc.getDataMap() == map) {
        executeDDL(con, "sybase", "create-select-sp.sql");
        executeDDL(con, "sybase", "create-update-sp.sql");
        executeDDL(con, "sybase", "create-update-sp2.sql");
        executeDDL(con, "sybase", "create-out-sp.sql");
    }
}
Also used : Procedure(org.apache.cayenne.map.Procedure)

Example 13 with Procedure

use of org.apache.cayenne.map.Procedure in project cayenne by apache.

the class ServerCaseDataDomainProvider method createAndInitDataDomain.

@Override
protected DataDomain createAndInitDataDomain() throws Exception {
    DataDomain domain = super.createAndInitDataDomain();
    DataNode node = null;
    for (DataMap dataMap : domain.getDataMaps()) {
        // add nodes and DataSources dynamically...
        DataNodeDescriptor descriptor = new DataNodeDescriptor(dataMap.getName());
        node = dataNodeFactory.createDataNode(descriptor);
        node.addDataMap(dataMap);
        // tweak procedures for testing...
        for (Procedure proc : dataMap.getProcedures()) {
            unitDbAdapter.tweakProcedure(proc);
        }
        // customizations from SimpleAccessStackAdapter that are not yet
        // ported...
        // those can be done better now
        // node
        // .getAdapter()
        // .getExtendedTypes()
        // .registerType(new StringET1ExtendedType());
        // 
        domain.addNode(node);
    }
    if (domain.getDataMaps().size() == 1) {
        domain.setDefaultNode(node);
    }
    return domain;
}
Also used : DataDomain(org.apache.cayenne.access.DataDomain) DataNode(org.apache.cayenne.access.DataNode) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Procedure(org.apache.cayenne.map.Procedure) DataMap(org.apache.cayenne.map.DataMap)

Example 14 with Procedure

use of org.apache.cayenne.map.Procedure in project cayenne by apache.

the class DataContextProcedureQueryIT method testSelect3.

@Test
public void testSelect3() 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.addParameter("aName", "An Artist");
    q.addParameter("paintingPrice", new Integer(3000));
    List<?> artists = runProcedureSelect(q);
    // check the results
    assertNotNull("Null result from StoredProcedure.", artists);
    assertEquals(1, artists.size());
    DataRow artistRow = (DataRow) artists.get(0);
    Artist a = context.objectFromDataRow(Artist.class, uppercaseConverter(artistRow));
    Painting p = a.getPaintingArray().get(0);
    // invalidate painting, it may have been updated in the proc
    context.invalidateObjects(p);
    assertEquals(2000, p.getEstimatedPrice().intValue());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Procedure(org.apache.cayenne.map.Procedure) DataRow(org.apache.cayenne.DataRow) ProcedureQuery(org.apache.cayenne.query.ProcedureQuery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 15 with Procedure

use of org.apache.cayenne.map.Procedure in project cayenne by apache.

the class ProcedureTranslator method createSqlString.

/**
 * Creates an SQL String for the stored procedure call.
 */
protected String createSqlString() {
    Procedure procedure = getProcedure();
    StringBuilder buf = new StringBuilder();
    int totalParams = callParams.size();
    // check if procedure returns values
    if (procedure.isReturningValue()) {
        totalParams--;
        buf.append("{? = call ");
    } else {
        buf.append("{call ");
    }
    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)

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