Package org.apache.cayenne.map

Examples of org.apache.cayenne.map.Procedure


        // If name hasn't changed, just return
        if (Util.nullSafeEquals(oldName, newName)) {
            return;
        }

        Procedure procedure = parameter.getProcedure();
        procedure.removeCallParameter(parameter.getName());
        parameter.setName(newName);
        procedure.addCallParameter(parameter);
    }
View Full Code Here


                String catalog = rs.getString("PROCEDURE_CAT");
                String schema = rs.getString("PROCEDURE_SCHEM");

                short type = rs.getShort("PROCEDURE_TYPE");

                Procedure procedure = new Procedure(name);
                procedure.setCatalog(catalog);
                procedure.setSchema(schema);

                switch (type) {
                case DatabaseMetaData.procedureNoResult:
                case DatabaseMetaData.procedureResultUnknown:
                    procedure.setReturningValue(false);
                    break;
                case DatabaseMetaData.procedureReturnsResult:
                    procedure.setReturningValue(true);
                    break;
                }

                if (procedures == null) {
                    procedures = new HashMap<String, Procedure>();
                }

                procedures.put(procedure.getFullyQualifiedName(), procedure);
            }
        } finally {
            rs.close();
        }

        // if nothing found, return
        if (procedures == null) {
            return;
        }

        // get columns
        ResultSet columnsRS = getMetaData().getProcedureColumns(null,
                schemaPattern, namePattern, null);
        try {
            while (columnsRS.next()) {

                String schema = columnsRS.getString("PROCEDURE_SCHEM");
                String name = columnsRS.getString("PROCEDURE_NAME");

                // TODO: this will be moved to Delegate...
                if (EXCLUDED_PROCEDURES.contains(name)) {
                    continue;
                }

                String columnName = columnsRS.getString("COLUMN_NAME");
                short type = columnsRS.getShort("COLUMN_TYPE");

                String key = (schema != null) ? schema + '.' + name : name;

                // skip ResultSet columns, as they are not described in Cayenne
                // procedures
                // yet...
                if (type == DatabaseMetaData.procedureColumnResult) {
                    logger.debug("skipping ResultSet column: " + key + "."
                            + columnName);
                }

                Procedure procedure = procedures.get(key);

                if (procedure == null) {
                    logger.info("invalid procedure column, no procedure found: "
                            + key + "." + columnName);
                    continue;
                }

                ProcedureParameter column = new ProcedureParameter(columnName);

                if (columnName == null) {
                    if (type == DatabaseMetaData.procedureColumnReturn) {
                        logger.debug("null column name, assuming result column: "
                                + key);
                        column.setName("_return_value");
                    } else {
                        logger.info("invalid null column name, skipping column : "
                                + key);
                        continue;
                    }
                }

                int columnType = columnsRS.getInt("DATA_TYPE");
                int columnSize = columnsRS.getInt("LENGTH");

                // ignore precision of non-decimal columns
                int decimalDigits = -1;
                if (TypesMapping.isDecimal(columnType)) {
                    decimalDigits = columnsRS.getShort("SCALE");
                    if (columnsRS.wasNull()) {
                        decimalDigits = -1;
                    }
                }

                switch (type) {
                case DatabaseMetaData.procedureColumnIn:
                    column.setDirection(ProcedureParameter.IN_PARAMETER);
                    break;
                case DatabaseMetaData.procedureColumnInOut:
                    column.setDirection(ProcedureParameter.IN_OUT_PARAMETER);
                    break;
                case DatabaseMetaData.procedureColumnOut:
                    column.setDirection(ProcedureParameter.OUT_PARAMETER);
                    break;
                case DatabaseMetaData.procedureColumnReturn:
                    procedure.setReturningValue(true);
                    break;
                }

                column.setMaxLength(columnSize);
                column.setPrecision(decimalDigits);
                column.setProcedure(procedure);
                column.setType(columnType);
                procedure.addCallParameter(column);
            }
        } finally {
            columnsRS.close();
        }
View Full Code Here

    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");
        }
View Full Code Here

        return true;
    }

    @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");
        }
View Full Code Here

        dropProcedures(con, map);
    }

    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");
        }
View Full Code Here

        // 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);
View Full Code Here

        // 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));
View Full Code Here

        if (node == null) {
            return;
        }

        Procedure procedure = e.getProcedure();
        DefaultMutableTreeNode currentNode = new DefaultMutableTreeNode(procedure, false);
        positionNode(node, currentNode, Comparators.getDataMapChildrenComparator());
        showNode(currentNode);
    }
View Full Code Here

            createProcedureParameter();
        }
    }

    public void createProcedureParameter() {
        Procedure procedure = getProjectController().getCurrentProcedure();

        ProcedureParameter parameter =
            (ProcedureParameter) NamedObjectFactory.createObject(
                ProcedureParameter.class,
                procedure);
               
        procedure.addCallParameter(parameter);

        ProjectController mediator = getProjectController();
        mediator.fireProcedureParameterEvent(
            new ProcedureParameterEvent(this, parameter, MapEvent.ADD));
View Full Code Here

    private void initController() {
        returnsValue.addItemListener(new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                Procedure procedure = eventController.getCurrentProcedure();
                if (procedure != null && !ignoreChange) {
                    procedure.setReturningValue(returnsValue.isSelected());
                    eventController.fireProcedureEvent(new ProcedureEvent(
                            ProcedureTab.this,
                            procedure));
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.map.Procedure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.