Search in sources :

Example 1 with TableType

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

the class BaseDBWSBuilderHelper method buildOROXProjects.

/**
 * Builds OR/OX projects, descriptors {@literal &} mappings, based on a given list
 * of types, as well as table(s) and secondary SQL.
 */
public void buildOROXProjects(NamingConventionTransformer nct, List<CompositeDatabaseType> types) {
    // save for later
    this.nct = nct;
    String projectName = dbwsBuilder.getProjectName();
    Project orProject = new Project();
    orProject.setName(projectName + UNDERSCORE + DBWS_OR_LABEL);
    Project oxProject = null;
    if (dbTables.isEmpty() && !dbwsBuilder.hasBuildSqlOperations()) {
        dbwsBuilder.logMessage(FINEST, "No tables specified");
        oxProject = new SimpleXMLFormatProject();
    } else {
        oxProject = new Project();
    }
    oxProject.setName(projectName + UNDERSCORE + DBWS_OX_LABEL);
    for (TableType dbTable : dbTables) {
        String tableName = dbTable.getTableName();
        RelationalDescriptor desc = buildORDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.requireCRUDOperations, nct);
        orProject.addDescriptor(desc);
        XMLDescriptor xdesc = buildOXDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.getTargetNamespace(), nct);
        oxProject.addDescriptor(xdesc);
        for (FieldType dbColumn : dbTable.getColumns()) {
            String columnName = dbColumn.getFieldName();
            ElementStyle style = nct.styleForElement(columnName);
            if (style == NONE) {
                continue;
            }
            dbwsBuilder.logMessage(FINE, "Building mappings for " + tableName + DOT + columnName);
            DirectToFieldMapping orFieldMapping = buildORFieldMappingFromColumn(dbColumn, desc, dbwsBuilder.getDatabasePlatform(), nct);
            desc.addMapping(orFieldMapping);
            XMLDirectMapping oxFieldMapping = buildOXFieldMappingFromColumn(dbColumn, dbwsBuilder.getDatabasePlatform(), nct);
            if (oxFieldMapping instanceof XMLBinaryDataMapping) {
                xdesc.getNamespaceResolver().put(XML_MIME_PREFIX, XML_MIME_URL);
            }
            xdesc.addMapping(oxFieldMapping);
            // check for switch from Byte[] to byte[]
            if (oxFieldMapping.getAttributeClassificationName() == APBYTE.getName()) {
                orFieldMapping.setAttributeClassificationName(APBYTE.getName());
            }
        }
        setUpFindQueries(nct, tableName, desc);
    }
    finishUpProjects(orProject, oxProject, types);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ElementStyle(org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType)

Example 2 with TableType

use of org.eclipse.persistence.tools.oracleddl.metadata.TableType 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 3 with TableType

use of org.eclipse.persistence.tools.oracleddl.metadata.TableType 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 4 with TableType

use of org.eclipse.persistence.tools.oracleddl.metadata.TableType 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)

Example 5 with TableType

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

the class JPAMetadataGenerator method generateXmlEntityMappings.

/**
 * Generate an XMLEntityMappings instance based on a given list of meta-model database types.
 *
 * @param databaseTypes the list of meta-model database types to be used to generate an XMLEntityMappings
 * @see org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType
 */
public XMLEntityMappings generateXmlEntityMappings(List<CompositeDatabaseType> databaseTypes) {
    List<ProcedureType> procedures = new ArrayList<ProcedureType>();
    List<TableType> tables = new ArrayList<TableType>();
    // populate lists of TableTypes and ProcedureTypes
    for (CompositeDatabaseType dbType : databaseTypes) {
        if (dbType.isTableType()) {
            tables.add((TableType) dbType);
        } else if (dbType.isProcedureType()) {
            procedures.add((ProcedureType) dbType);
        }
    }
    // handle stored procedure overloading
    handleOverloading(procedures);
    // process TableTypes
    for (TableType table : tables) {
        EntityAccessor entity = processTableType(table);
        xmlEntityMappings.getEntities().add(entity);
    }
    // process ProcedureTypes
    for (ProcedureType procedure : procedures) {
        // PL/SQL stored procedures and functions will have a PLSQLPackageType as its parent
        PLSQLPackageType pkgType = procedure.getParentType();
        if (pkgType != null) {
            // handle PL/SQL
            if (procedure.isFunctionType()) {
                xmlEntityMappings.getNamedPLSQLStoredFunctionQueries().add(processPLSQLFunctionType((FunctionType) procedure, pkgType));
            } else {
                xmlEntityMappings.getNamedPLSQLStoredProcedureQueries().add(processPLSQLProcedureType(procedure, pkgType));
            }
        } else {
            // handle top-level (non-PL/SQL) functions and procedures
            if (procedure.isFunctionType()) {
                xmlEntityMappings.getNamedStoredFunctionQueries().add(processFunctionType((FunctionType) procedure));
            } else {
                xmlEntityMappings.getNamedStoredProcedureQueries().add(processProcedureType(procedure));
            }
        }
    }
    return xmlEntityMappings;
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor) ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) PLSQLPackageType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType) FunctionType(org.eclipse.persistence.tools.oracleddl.metadata.FunctionType) ArrayList(java.util.ArrayList) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)

Aggregations

TableType (org.eclipse.persistence.tools.oracleddl.metadata.TableType)9 ObjectTableType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType)6 ArrayList (java.util.ArrayList)5 PLSQLPackageType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType)4 ProcedureType (org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType)4 CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)3 FieldType (org.eclipse.persistence.tools.oracleddl.metadata.FieldType)3 PLSQLRecordType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType)3 ROWTYPEType (org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType)3 Util.qNameFromString (org.eclipse.persistence.tools.dbws.Util.qNameFromString)2 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 DBWSModelProject (org.eclipse.persistence.dbws.DBWSModelProject)1 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)1 EntityAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor)1 PLSQLParameterMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLParameterMetadata)1 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)1 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)1 SimpleXMLFormatProject (org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject)1