Search in sources :

Example 1 with ROWTYPEType

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

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

the class JPAMetadataGenerator method processPLSQLArgument.

/**
 * Generate a PL/SQL parameter based on the given ArgumentType. For
 * non-PL/SQL arguments the processArgument method should be used.
 */
protected PLSQLParameterMetadata processPLSQLArgument(ArgumentType arg) {
    // for %ROWTYPE, we need to create a PL/SQL record that mirrors the Table
    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);
    }
    PLSQLParameterMetadata param = new PLSQLParameterMetadata();
    // handle cursor
    if (arg.isPLSQLCursorType()) {
        param.setDirection(OUT_CURSOR_STR);
    }
    // handle stored function return type
    if (arg.getDirection() == ArgumentTypeDirection.RETURN) {
        param.setName(arg.isPLSQLCursorType() ? CURSOR_STR : RESULT_STR);
    } else {
        // direction is already set for cursor type
        if (!arg.isPLSQLCursorType()) {
            param.setDirection(arg.getDirection().name());
        }
        param.setName(arg.getArgumentName());
    }
    String dbType = arg.getTypeName();
    // handle composites
    if (arg.isComposite()) {
        DatabaseType enclosedType = arg.getEnclosedType();
        // need to prepend the package name for most PL/SQL and Cursor types
        if (enclosedType.isPLSQLType() || enclosedType.isPLSQLCursorType()) {
            dbType = getQualifiedTypeName(enclosedType);
        }
        // process the composite enclosed type
        processCompositeType(enclosedType, dbType);
    }
    param.setDatabaseType(processTypeName(dbType));
    return param;
}
Also used : 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) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) ROWTYPEType(org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType) PLSQLParameterMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLParameterMetadata) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType) Util.getAttributeTypeNameForFieldType(org.eclipse.persistence.tools.metadata.generation.Util.getAttributeTypeNameForFieldType)

Example 3 with ROWTYPEType

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

the class OracleHelper method customizeSimpleXMLTagNames.

/**
 * Customizes the simple-xml-format tags names to better represent the
 * PL/SQL record/table/column type. This is possible only with
 * strongly-typed ref cursors, since for weakly-typed ones we
 * don't know anything about the cursor's output type.
 */
protected void customizeSimpleXMLTagNames(PLSQLCursorType plsqlCursor, ProcedureOperationModel procedureOperationModel) {
    if (!plsqlCursor.isWeaklyTyped()) {
        // do not override user tag customization
        if (procedureOperationModel.getSimpleXMLFormatTag() == null) {
            procedureOperationModel.setSimpleXMLFormatTag(plsqlCursor.getCursorName());
        }
        // - TYPEType
        if (procedureOperationModel.getXmlTag() == null) {
            if (plsqlCursor.getEnclosedType().isPLSQLRecordType()) {
                PLSQLRecordType recType = (PLSQLRecordType) plsqlCursor.getEnclosedType();
                procedureOperationModel.setXmlTag(recType.getTypeName());
            } else if (plsqlCursor.getEnclosedType().isROWTYPEType()) {
                // assumes ROWTYPEType has an enclosed TableType
                ROWTYPEType rowType = (ROWTYPEType) plsqlCursor.getEnclosedType();
                TableType tableType = (TableType) rowType.getEnclosedType();
                procedureOperationModel.setXmlTag(tableType.getTableName());
            }
        }
    }
}
Also used : PLSQLRecordType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) ROWTYPEType(org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType)

Aggregations

ObjectTableType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType)3 PLSQLRecordType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType)3 ROWTYPEType (org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType)3 TableType (org.eclipse.persistence.tools.oracleddl.metadata.TableType)3 CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)2 FieldType (org.eclipse.persistence.tools.oracleddl.metadata.FieldType)2 PLSQLPackageType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType)2 ArrayList (java.util.ArrayList)1 PLSQLParameterMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLParameterMetadata)1 Util.getAttributeTypeNameForFieldType (org.eclipse.persistence.tools.metadata.generation.Util.getAttributeTypeNameForFieldType)1 ArgumentType (org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType)1 DatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType)1 ProcedureType (org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType)1 EnclosedTypeVisitor (org.eclipse.persistence.tools.oracleddl.metadata.visit.EnclosedTypeVisitor)1