Search in sources :

Example 1 with ProcedureType

use of org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method buildTypesList.

/**
 * Uses a custom visitor to traverse each procedure/function argument and build
 * a list of required Types.  Only on instance of a given type will exist in
 * the list.
 */
public List<CompositeDatabaseType> buildTypesList(List<OperationModel> operations) {
    EnclosedTypeVisitor etVisitor = new EnclosedTypeVisitor();
    for (OperationModel opModel : operations) {
        if (opModel.isProcedureOperation()) {
            ProcedureOperationModel procedureOperation = (ProcedureOperationModel) opModel;
            if (procedureOperation.isPLSQLProcedureOperation() || procedureOperation.isAdvancedJDBCProcedureOperation()) {
                for (ProcedureType procType : procedureOperation.getDbStoredProcedures()) {
                    // build list of arguments to process (i.e. build descriptors for)
                    List<ArgumentType> args = new ArrayList<ArgumentType>();
                    // return argument
                    if (procType.isFunctionType()) {
                        // assumes that a function MUST have a return type
                        args.add(((FunctionType) procType).getReturnArgument());
                    }
                    args.addAll(procType.getArguments());
                    // now visit each argument
                    for (ArgumentType arg : args) {
                        // handle ROWTYPETypes
                        if (arg.getEnclosedType().isROWTYPEType()) {
                            ROWTYPEType rType = (ROWTYPEType) arg.getEnclosedType();
                            TableType tableType = (TableType) rType.getEnclosedType();
                            PLSQLRecordType plsqlRec = new PLSQLRecordType(rType.getTypeName());
                            plsqlRec.setParentType(new PLSQLPackageType());
                            for (FieldType col : tableType.getColumns()) {
                                FieldType ft = new FieldType(col.getFieldName());
                                ft.setEnclosedType(col.getEnclosedType());
                                plsqlRec.addField(ft);
                            }
                            arg.setEnclosedType(plsqlRec);
                        }
                        // now visit each, adding types (only one instance of each) to the list
                        if (arg.isComposite()) {
                            etVisitor.visit((CompositeDatabaseType) arg);
                        }
                    }
                }
            }
        }
    }
    // gather Complex types to hand into XMLEntityMappingsGenerator
    List<CompositeDatabaseType> types = etVisitor.getCompositeDatabaseTypes();
    for (CompositeDatabaseType type : types) {
        complextypes.add(type);
    }
    return etVisitor.getCompositeDatabaseTypes();
}
Also used : ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) PLSQLRecordType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType) PLSQLPackageType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType) ArrayList(java.util.ArrayList) ArgumentType(org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType) EnclosedTypeVisitor(org.eclipse.persistence.tools.oracleddl.metadata.visit.EnclosedTypeVisitor) ROWTYPEType(org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)

Example 2 with ProcedureType

use of org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method buildDbArtifacts.

/**
 * Gather table and procedure information based on TableOperation
 * and ProcedureOperation.  End result will be List&lt;TableType&gt;
 * and List&lt;ProcedureType&gt;.
 */
public void buildDbArtifacts() {
    List<TableOperationModel> tableOperations = new ArrayList<TableOperationModel>();
    List<ProcedureOperationModel> procedureOperations = new ArrayList<ProcedureOperationModel>();
    // its possible a builder might have pre-built tables
    if (dbTables.size() == 0) {
        // do Table operations first
        for (OperationModel operation : dbwsBuilder.operations) {
            if (operation.isTableOperation()) {
                TableOperationModel tom = (TableOperationModel) operation;
                tableOperations.add(tom);
                if (tom.additionalOperations != null && tom.additionalOperations.size() > 0) {
                    for (OperationModel nestedOperation : tom.additionalOperations) {
                        if (nestedOperation.isProcedureOperation()) {
                            procedureOperations.add((ProcedureOperationModel) nestedOperation);
                        }
                    }
                }
            }
        }
        if (tableOperations.size() > 0) {
            List<String> catalogPatterns = new ArrayList<String>();
            List<String> schemaPatterns = new ArrayList<String>();
            List<String> tableNamePatterns = new ArrayList<String>();
            for (TableOperationModel tableOperation : tableOperations) {
                catalogPatterns.add(tableOperation.getCatalogPattern());
                schemaPatterns.add(tableOperation.getSchemaPattern());
                tableNamePatterns.add(tableOperation.getTablePattern());
            }
            List<TableType> tables = loadTables(catalogPatterns, schemaPatterns, tableNamePatterns);
            // if we didn't find any tables log a WARNING
            if (tables == null || tables.isEmpty()) {
                logNotFoundWarnings(NO_TABLE_MSG, schemaPatterns, catalogPatterns, tableNamePatterns);
            } else {
                // now assign tables to operations
                for (TableType tableType : tables) {
                    for (TableOperationModel tableOperation : tableOperations) {
                        // figure out catalog(optional)/schema/tableName matching
                        boolean tableNameMatch = sqlMatch(tableOperation.getTablePattern(), tableType.getTableName());
                        boolean schemaNameMatch = sqlMatch(tableOperation.getSchemaPattern(), tableType.getSchema());
                        if (tableNameMatch && schemaNameMatch) {
                            String originalCatalogPattern = tableOperation.getCatalogPattern();
                            if (tableType.isDbTableType() && originalCatalogPattern != null) {
                                boolean catalogNameMatch = sqlMatch(originalCatalogPattern, ((DbTable) tableType).getCatalog());
                                if (catalogNameMatch) {
                                    tableOperation.getDbTables().add(tableType);
                                }
                            } else {
                                tableOperation.getDbTables().add(tableType);
                            }
                        }
                    }
                }
                dbTables.addAll(tables);
            }
        }
    }
    // it's possible a builder might have pre-built procedures
    if (dbStoredProcedures.size() == 0) {
        for (OperationModel operation : dbwsBuilder.operations) {
            if (operation.isProcedureOperation()) {
                procedureOperations.add((ProcedureOperationModel) operation);
            }
        }
        if (procedureOperations.size() > 0) {
            List<String> catalogPatterns = new ArrayList<String>();
            List<String> schemaPatterns = new ArrayList<String>();
            List<String> procedureNamePatterns = new ArrayList<String>();
            for (ProcedureOperationModel procedureOperation : procedureOperations) {
                catalogPatterns.add(procedureOperation.getCatalogPattern());
                schemaPatterns.add(procedureOperation.getSchemaPattern());
                procedureNamePatterns.add(procedureOperation.getProcedurePattern());
            }
            List<ProcedureType> procedures = loadProcedures(catalogPatterns, schemaPatterns, procedureNamePatterns);
            // if we didn't find any procs/funcs log a WARNING
            if (procedures == null || procedures.isEmpty()) {
                logNotFoundWarnings(NO_PROC_MSG, schemaPatterns, catalogPatterns, procedureNamePatterns);
            } else {
                // now assign procedures to operations
                for (ProcedureType procedureType : procedures) {
                    for (ProcedureOperationModel procedureOperation : procedureOperations) {
                        boolean procedureNameMatch = sqlMatch(procedureOperation.getProcedurePattern(), procedureType.getProcedureName());
                        boolean schemaNameMatch = true;
                        boolean catalogNameMatch = true;
                        if (procedureNameMatch) {
                            String originalSchemaPattern = procedureOperation.getSchemaPattern();
                            if (originalSchemaPattern != null) {
                                schemaNameMatch = sqlMatch(originalSchemaPattern, procedureType.getSchema());
                            }
                            String originalCatalogPattern = procedureOperation.getCatalogPattern();
                            if (originalCatalogPattern != null) {
                                catalogNameMatch = sqlMatch(originalCatalogPattern, procedureType.getCatalogName());
                            }
                        }
                        if (procedureNameMatch && schemaNameMatch && catalogNameMatch) {
                            procedureOperation.getDbStoredProcedures().add(procedureType);
                        }
                    }
                }
                dbStoredProcedures.addAll(procedures);
            }
        }
    }
}
Also used : ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) ArrayList(java.util.ArrayList)

Example 3 with ProcedureType

use of org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method finishUpProjects.

/**
 * Complete project configuration.  Build descriptors for secondary SQL
 * and complex arguments. Set the projects on the DBWSBuilder instance.
 */
protected void finishUpProjects(Project orProject, Project oxProject, List<CompositeDatabaseType> typeList) {
    // handle build SQL
    for (OperationModel opModel : dbwsBuilder.operations) {
        if (opModel.hasBuildSql()) {
            addToOROXProjectsForBuildSql((ModelWithBuildSql) opModel, orProject, oxProject, nct);
        }
    }
    // create OR/OX projects, descriptors/mappings for the types
    addToOROXProjectsForComplexTypes(typeList, orProject, oxProject);
    // build queries for procedures with complex arguments
    for (OperationModel opModel : dbwsBuilder.operations) {
        if (opModel.isProcedureOperation()) {
            ProcedureOperationModel procedureOperation = (ProcedureOperationModel) opModel;
            for (ProcedureType procType : procedureOperation.getDbStoredProcedures()) {
                buildQueryForProcedureType(procType, orProject, oxProject, procedureOperation, hasPLSQLArgs(getArgumentListForProcedureType(procType)));
            }
        }
    }
    // set aggregate OR descriptors where appropriate
    for (String refClassName : referencedORDescriptors) {
        ClassDescriptor cdesc = createdORDescriptors.get(refClassName);
        // should not be null, but check to avoid an exception
        if (cdesc != null) {
            cdesc.descriptorIsAggregate();
        }
    }
    DatabaseLogin databaseLogin = new DatabaseLogin();
    databaseLogin.removeProperty(USER_STR);
    databaseLogin.removeProperty(PASSWORD_STR);
    databaseLogin.setDriverClassName(null);
    databaseLogin.setConnectionString(null);
    orProject.setLogin(databaseLogin);
    XMLLogin xmlLogin = new XMLLogin();
    xmlLogin.setDatasourcePlatform(new DOMPlatform());
    xmlLogin.getProperties().remove(USER_STR);
    xmlLogin.getProperties().remove(PASSWORD_STR);
    oxProject.setLogin(xmlLogin);
    dbwsBuilder.setOrProject(orProject);
    dbwsBuilder.setOxProject(oxProject);
}
Also used : ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) DOMPlatform(org.eclipse.persistence.oxm.platform.DOMPlatform) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLLogin(org.eclipse.persistence.oxm.XMLLogin)

Example 4 with ProcedureType

use of org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType in project eclipselink by eclipse-ee4j.

the class ProcedureOverloadTestSuite method setUp.

@SuppressWarnings({ "rawtypes", "unchecked" })
@BeforeClass
public static void setUp() throws ClassNotFoundException, SQLException {
    AllTests.setUp();
    String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
    if ("true".equalsIgnoreCase(ddlCreateProp)) {
        ddlCreate = true;
    }
    String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
    if ("true".equalsIgnoreCase(ddlDropProp)) {
        ddlDrop = true;
    }
    String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
    if ("true".equalsIgnoreCase(ddlDebugProp)) {
        ddlDebug = true;
    }
    if (ddlCreate) {
        runDdl(conn, CREATE_PACKAGEX_PACKAGE, ddlDebug);
    }
    String schema = System.getProperty(DATABASE_USERNAME_KEY, DEFAULT_DATABASE_USERNAME);
    List<String> procedurePatterns = new ArrayList<String>();
    procedurePatterns.add("P1");
    procedurePatterns.add("P1_1");
    procedurePatterns.add("P1_2");
    procedurePatterns.add("F1");
    procedurePatterns.add("F1_1");
    // use DatabaseTypeBuilder to generate a list of PackageTypes
    dbTypeBuilder = new DatabaseTypeBuilder();
    dbProcedures = new ArrayList();
    try {
        // process the package
        List<PLSQLPackageType> packages = dbTypeBuilder.buildPackages(conn, schema, "PACKAGEX");
        for (PLSQLPackageType pkgType : packages) {
            // now get the desired procedures/functions from the processed package
            for (ProcedureType procType : pkgType.getProcedures()) {
                if (procedurePatterns.contains(procType.getProcedureName())) {
                    dbProcedures.add(procType);
                }
            }
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
}
Also used : ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) DatabaseTypeBuilder(org.eclipse.persistence.tools.oracleddl.util.DatabaseTypeBuilder) PLSQLPackageType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType) ArrayList(java.util.ArrayList) AllTests.documentToString(org.eclipse.persistence.tools.metadata.generation.test.AllTests.documentToString) ParseException(org.eclipse.persistence.tools.oracleddl.parser.ParseException) BeforeClass(org.junit.BeforeClass)

Example 5 with ProcedureType

use of org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType in project eclipselink by eclipse-ee4j.

the class TypeRowTypeTestSuite method setUp.

@SuppressWarnings({ "unchecked", "rawtypes" })
@BeforeClass
public static void setUp() throws ClassNotFoundException, SQLException {
    AllTests.setUp();
    String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
    if ("true".equalsIgnoreCase(ddlCreateProp)) {
        ddlCreate = true;
    }
    String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
    if ("true".equalsIgnoreCase(ddlDropProp)) {
        ddlDrop = true;
    }
    String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
    if ("true".equalsIgnoreCase(ddlDebugProp)) {
        ddlDebug = true;
    }
    if (ddlCreate) {
        runDdl(conn, CREATE_EMPTYPE_TABLE, ddlDebug);
        runDdl(conn, CREATE_EMPREC_TYPE, ddlDebug);
        runDdl(conn, CREATE_EMP_RECORD_PACKAGE, ddlDebug);
        runDdl(conn, CREATE_ROWTYPE_TEST_PACKAGE, ddlDebug);
    }
    String schema = System.getProperty(DATABASE_USERNAME_KEY, DEFAULT_DATABASE_USERNAME);
    List<String> procedurePatterns = new ArrayList<String>();
    procedurePatterns.add("get_emp_record");
    procedurePatterns.add("testProc");
    procedurePatterns.add("testFunc");
    // use DatabaseTypeBuilder to generate a lists of TableTypes and PackageTypes
    dbTypeBuilder = new DatabaseTypeBuilder();
    try {
        // process the table
        List<TableType> dbTables = dbTypeBuilder.buildTables(conn, schema, "EMPTYPEX");
        // process the "EMP_RECORD_PACKAGE" package
        List<ProcedureType> empRecPkgProcedures = new ArrayList<ProcedureType>();
        List<PLSQLPackageType> packages = dbTypeBuilder.buildPackages(conn, schema, "EMP_RECORD_PACKAGE");
        for (PLSQLPackageType pkgType : packages) {
            // now get the desired procedures/functions from the processed package
            for (ProcedureType procType : pkgType.getProcedures()) {
                if (procedurePatterns.contains(procType.getProcedureName())) {
                    empRecPkgProcedures.add(procType);
                }
            }
        }
        // process the "RTYPE_PKG" package
        List<ProcedureType> rtypePkgProcedures = new ArrayList<ProcedureType>();
        packages = dbTypeBuilder.buildPackages(conn, schema, "RTYPE_PKG");
        for (PLSQLPackageType pkgType : packages) {
            // now get the desired procedures/functions from the processed package
            for (ProcedureType procType : pkgType.getProcedures()) {
                if (procedurePatterns.contains(procType.getProcedureName())) {
                    rtypePkgProcedures.add(procType);
                }
            }
        }
        // combine tables and procedures to pass to the metadata generator
        dbTypes = new ArrayList();
        dbTypes.addAll(dbTables);
        dbTypes.addAll(empRecPkgProcedures);
        dbTypes.addAll(rtypePkgProcedures);
    } catch (ParseException e) {
        e.printStackTrace();
        fail("An unexpected exception occurred: " + e.getMessage());
    }
}
Also used : ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) DatabaseTypeBuilder(org.eclipse.persistence.tools.oracleddl.util.DatabaseTypeBuilder) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) PLSQLPackageType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType) ArrayList(java.util.ArrayList) AllTests.documentToString(org.eclipse.persistence.tools.metadata.generation.test.AllTests.documentToString) ParseException(org.eclipse.persistence.tools.oracleddl.parser.ParseException) BeforeClass(org.junit.BeforeClass)

Aggregations

ProcedureType (org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType)17 ArrayList (java.util.ArrayList)13 PLSQLPackageType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType)10 ParseException (org.eclipse.persistence.tools.oracleddl.parser.ParseException)7 AllTests.documentToString (org.eclipse.persistence.tools.metadata.generation.test.AllTests.documentToString)6 DatabaseTypeBuilder (org.eclipse.persistence.tools.oracleddl.util.DatabaseTypeBuilder)6 BeforeClass (org.junit.BeforeClass)6 Util.qNameFromString (org.eclipse.persistence.tools.dbws.Util.qNameFromString)5 ArgumentType (org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType)5 FunctionType (org.eclipse.persistence.tools.oracleddl.metadata.FunctionType)5 CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)4 TableType (org.eclipse.persistence.tools.oracleddl.metadata.TableType)4 ObjectTableType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 QName (javax.xml.namespace.QName)2 Attachment (org.eclipse.persistence.internal.xr.Attachment)2 CollectionResult (org.eclipse.persistence.internal.xr.CollectionResult)2 NamedQueryHandler (org.eclipse.persistence.internal.xr.NamedQueryHandler)2