Search in sources :

Example 1 with CollectionResult

use of org.eclipse.persistence.internal.xr.CollectionResult in project eclipselink by eclipse-ee4j.

the class JDBCHelper method buildProcedureOperation.

@Override
public void buildProcedureOperation(ProcedureOperationModel procedureOperationModel) {
    String name = procedureOperationModel.getName();
    boolean isMySQL = dbwsBuilder.getDatabasePlatform().getClass().getName().contains("MySQL");
    for (ProcedureType storedProcedure : procedureOperationModel.getDbStoredProcedures()) {
        StringBuilder sb = new StringBuilder();
        if (name == null || name.length() == 0) {
            if (storedProcedure.getOverload() > 0) {
                sb.append(storedProcedure.getOverload());
                sb.append('_');
            }
            if (storedProcedure.getCatalogName() != null && storedProcedure.getCatalogName().length() > 0) {
                sb.append(storedProcedure.getCatalogName());
                sb.append('_');
            }
            if (storedProcedure.getSchema() != null && storedProcedure.getSchema().length() > 0) {
                sb.append(storedProcedure.getSchema());
                sb.append('_');
            }
            sb.append(storedProcedure.getProcedureName());
        } else {
            sb.append(name);
        }
        QueryOperation qo = new QueryOperation();
        qo.setName(sb.toString());
        QueryHandler qh;
        if (storedProcedure.isFunctionType()) {
            qh = new StoredFunctionQueryHandler();
        } else {
            qh = new StoredProcedureQueryHandler();
        }
        sb = new StringBuilder();
        if (!isMySQL) {
            if (storedProcedure.getCatalogName() != null && storedProcedure.getCatalogName().length() > 0) {
                sb.append(storedProcedure.getCatalogName());
                sb.append('.');
            }
        }
        if (storedProcedure.getSchema() != null && storedProcedure.getSchema().length() > 0) {
            sb.append(storedProcedure.getSchema());
            sb.append('.');
        }
        sb.append(storedProcedure.getProcedureName());
        ((StoredProcedureQueryHandler) qh).setName(sb.toString());
        dbwsBuilder.logMessage(FINEST, "Building QueryOperation for " + sb.toString());
        // before assigning queryHandler, check for named query in OR project
        List<DatabaseQuery> queries = dbwsBuilder.getOrProject().getQueries();
        if (queries.size() > 0) {
            for (DatabaseQuery q : queries) {
                if (q.getName().equals(qo.getName())) {
                    qh = new NamedQueryHandler();
                    ((NamedQueryHandler) qh).setName(qo.getName());
                }
            }
        }
        qo.setQueryHandler(qh);
        String returnType = procedureOperationModel.getReturnType();
        boolean isCollection = procedureOperationModel.isCollection();
        boolean isSimpleXMLFormat = procedureOperationModel.isSimpleXMLFormat();
        Result result = null;
        if (storedProcedure.isFunctionType()) {
            FunctionType storedFunction = (FunctionType) storedProcedure;
            DatabaseType rarg = storedFunction.getReturnArgument();
            if (rarg.getTypeName().contains("CURSOR")) {
                result = new CollectionResult();
                result.setType(SXF_QNAME_CURSOR);
            } else {
                result = new Result();
                int rargJdbcType = Util.getJDBCTypeFromTypeName(rarg.getTypeName());
                switch(rargJdbcType) {
                    case STRUCT:
                    case ARRAY:
                    case OTHER:
                        if (returnType != null) {
                            result.setType(buildCustomQName(returnType, dbwsBuilder));
                        } else {
                            result.setType(ANY_QNAME);
                        }
                        break;
                    default:
                        result.setType(getXMLTypeFromJDBCType(rargJdbcType));
                        break;
                }
            }
        } else {
            // if user overrides returnType, assume they're right
            if (returnType != null) {
                result = new Result();
                result.setType(buildCustomQName(returnType, dbwsBuilder));
            } else {
                if (isCollection) {
                    result = new CollectionResult();
                    if (isSimpleXMLFormat) {
                        result.setType(SXF_QNAME_CURSOR);
                    }
                } else {
                    result = new Result();
                    result.setType(SXF_QNAME);
                }
            }
        }
        if (procedureOperationModel.getBinaryAttachment()) {
            Attachment attachment = new Attachment();
            attachment.setMimeType("application/octet-stream");
            result.setAttachment(attachment);
        }
        for (ArgumentType arg : storedProcedure.getArguments()) {
            String argName = arg.getArgumentName();
            if (argName != null) {
                ProcedureArgument pa = null;
                Parameter parm = null;
                ArgumentTypeDirection direction = arg.getDirection();
                QName xmlType = null;
                switch(Util.getJDBCTypeFromTypeName(arg.getTypeName())) {
                    case STRUCT:
                    case ARRAY:
                    case OTHER:
                        String typeString = nct.generateSchemaAlias(arg.getTypeName());
                        xmlType = buildCustomQName(typeString, dbwsBuilder);
                        break;
                    default:
                        xmlType = getXMLTypeFromJDBCType(Util.getJDBCTypeFromTypeName(arg.getTypeName()));
                        break;
                }
                if (direction == IN) {
                    parm = new Parameter();
                    parm.setName(argName);
                    parm.setType(xmlType);
                    pa = new ProcedureArgument();
                    pa.setName(argName);
                    pa.setParameterName(argName);
                    if (qh instanceof StoredProcedureQueryHandler) {
                        ((StoredProcedureQueryHandler) qh).getInArguments().add(pa);
                    }
                } else {
                    // the first OUT/INOUT arg determines singleResult vs. collectionResult
                    pa = new ProcedureOutputArgument();
                    ProcedureOutputArgument pao = (ProcedureOutputArgument) pa;
                    pao.setName(argName);
                    pao.setParameterName(argName);
                    if (arg.getTypeName().contains("CURSOR") && returnType == null) {
                        // if user overrides returnType, assume they're right
                        pao.setResultType(SXF_QNAME_CURSOR);
                        if (result == null) {
                            result = new CollectionResult();
                            result.setType(SXF_QNAME_CURSOR);
                        }
                    } else {
                        // Hmm, multiple OUT's gonna be a problem - later!
                        if (returnType != null && !isSimpleXMLFormat) {
                            xmlType = qNameFromString("{" + dbwsBuilder.getTargetNamespace() + "}" + returnType, dbwsBuilder.getSchema());
                        }
                        pao.setResultType(xmlType);
                        if (result == null) {
                            if (isCollection) {
                                result = new CollectionResult();
                            } else {
                                result = new Result();
                            }
                            result.setType(xmlType);
                        }
                    }
                    if (direction == INOUT) {
                        parm = new Parameter();
                        parm.setName(argName);
                        parm.setType(xmlType);
                        result.setType(xmlType);
                        // use of INOUT precludes SimpleXMLFormat
                        isSimpleXMLFormat = false;
                        if (qh instanceof StoredProcedureQueryHandler) {
                            ((StoredProcedureQueryHandler) qh).getInOutArguments().add(pao);
                        }
                    } else {
                        if (qh instanceof StoredProcedureQueryHandler) {
                            ((StoredProcedureQueryHandler) qh).getOutArguments().add(pao);
                        }
                    }
                }
                if (parm != null) {
                    qo.getParameters().add(parm);
                }
            }
        }
        handleSimpleXMLFormat(isSimpleXMLFormat, result, procedureOperationModel);
        qo.setResult(result);
        dbwsBuilder.getXrServiceModel().getOperations().put(qo.getName(), qo);
    }
    finishProcedureOperation();
}
Also used : ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) StoredProcedureQueryHandler(org.eclipse.persistence.internal.xr.StoredProcedureQueryHandler) StoredFunctionQueryHandler(org.eclipse.persistence.internal.xr.StoredFunctionQueryHandler) QueryHandler(org.eclipse.persistence.internal.xr.QueryHandler) NamedQueryHandler(org.eclipse.persistence.internal.xr.NamedQueryHandler) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) Util.buildCustomQName(org.eclipse.persistence.tools.dbws.Util.buildCustomQName) QName(javax.xml.namespace.QName) FunctionType(org.eclipse.persistence.tools.oracleddl.metadata.FunctionType) StoredProcedureQueryHandler(org.eclipse.persistence.internal.xr.StoredProcedureQueryHandler) Attachment(org.eclipse.persistence.internal.xr.Attachment) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString) ArgumentType(org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType) ProcedureArgument(org.eclipse.persistence.internal.xr.ProcedureArgument) ProcedureOutputArgument(org.eclipse.persistence.internal.xr.ProcedureOutputArgument) CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) Result(org.eclipse.persistence.internal.xr.Result) DatabaseMetaData.procedureReturnsResult(java.sql.DatabaseMetaData.procedureReturnsResult) StoredFunctionQueryHandler(org.eclipse.persistence.internal.xr.StoredFunctionQueryHandler) CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) NamedQueryHandler(org.eclipse.persistence.internal.xr.NamedQueryHandler) Parameter(org.eclipse.persistence.internal.xr.Parameter) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) ArgumentTypeDirection(org.eclipse.persistence.tools.oracleddl.metadata.ArgumentTypeDirection)

Example 2 with CollectionResult

use of org.eclipse.persistence.internal.xr.CollectionResult in project eclipselink by eclipse-ee4j.

the class DBWSModelProject method buildResultDescriptor.

// result
// 
// type|attachment
protected XMLDescriptor buildResultDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Result.class);
    descriptor.setDefaultRootElement("result");
    XMLTransformationMapping type = new XMLTransformationMapping();
    type.setAttributeName("type");
    QNameTransformer qNameTransformer = new QNameTransformer("type/text()");
    type.addFieldTransformer("type/text()", qNameTransformer);
    type.setAttributeTransformer(qNameTransformer);
    descriptor.addMapping(type);
    XMLCompositeObjectMapping attachment = new XMLCompositeObjectMapping();
    attachment.setAttributeName("attachment");
    attachment.setXPath("attachment");
    attachment.setReferenceClass(Attachment.class);
    descriptor.addMapping(attachment);
    XMLCompositeObjectMapping sxf = new XMLCompositeObjectMapping();
    sxf.setAttributeName("simpleXMLFormat");
    sxf.setXPath("simple-xml-format");
    sxf.setReferenceClass(SimpleXMLFormat.class);
    descriptor.addMapping(sxf);
    XMLDirectMapping isCollection = new XMLDirectMapping();
    isCollection.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public String getAttributeName() {
            return "isCollection";
        }

        @Override
        public Object getAttributeValueFromObject(Object object) throws DescriptorException {
            if (object instanceof CollectionResult) {
                return Boolean.TRUE;
            }
            return null;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) throws DescriptorException {
        }
    });
    isCollection.setXPath("@isCollection");
    descriptor.addMapping(isCollection);
    XMLField isColl = new XMLField("@isCollection");
    isColl.setSchemaType(BOOLEAN_QNAME);
    descriptor.getInheritancePolicy().setClassIndicatorField(isColl);
    descriptor.getInheritancePolicy().setClassExtractor(new ClassExtractor() {

        @Override
        @SuppressWarnings({ "unchecked" })
        public <T> Class<T> extractClassFromRow(DataRecord dataRecord, Session session) {
            Class<?> clz = Result.class;
            UnmarshalRecord uRecord = (UnmarshalRecord) dataRecord;
            Attributes attrs = uRecord.getAttributes();
            if (attrs != null) {
                for (int i = 0, l = attrs.getLength(); i < l; i++) {
                    String attributeName = attrs.getQName(i);
                    if (attributeName.equals("isCollection")) {
                        String value = attrs.getValue(i);
                        if (value.equalsIgnoreCase("true")) {
                            clz = CollectionResult.class;
                            break;
                        }
                    }
                }
            }
            return (Class<T>) clz;
        }
    });
    XMLDirectMapping jdbcTypeMapping = new XMLDirectMapping();
    jdbcTypeMapping.setAttributeName("jdbcType");
    jdbcTypeMapping.setXPath("@jdbcType");
    descriptor.addMapping(jdbcTypeMapping);
    return descriptor;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) Attributes(org.xml.sax.Attributes) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) ClassExtractor(org.eclipse.persistence.descriptors.ClassExtractor) CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) UnmarshalRecord(org.eclipse.persistence.oxm.record.UnmarshalRecord) QNameTransformer(org.eclipse.persistence.internal.xr.QNameTransformer) DataRecord(org.eclipse.persistence.sessions.DataRecord) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) Session(org.eclipse.persistence.sessions.Session)

Example 3 with CollectionResult

use of org.eclipse.persistence.internal.xr.CollectionResult in project eclipselink by eclipse-ee4j.

the class OracleHelper method buildProcedureOperation.

/**
 * Builds query operations for a given ProcedureOperationModel.
 */
@Override
public void buildProcedureOperation(ProcedureOperationModel procedureOperationModel) {
    for (ProcedureType storedProcedure : procedureOperationModel.getDbStoredProcedures()) {
        boolean hasComplexArgs = hasComplexArgs(storedProcedure);
        QueryOperation qo = new QueryOperation();
        qo.setName(getNameForQueryOperation(procedureOperationModel, storedProcedure));
        String qualifiedProcName = getQualifiedProcedureName(procedureOperationModel, storedProcedure);
        dbwsBuilder.logMessage(FINEST, BUILDING_QUERYOP_FOR + qualifiedProcName);
        QueryHandler qh = null;
        // before assigning queryHandler, check for named query in OR project
        List<DatabaseQuery> queries = dbwsBuilder.getOrProject().getQueries();
        if (queries.size() > 0) {
            for (DatabaseQuery q : queries) {
                if (q.getName().equals(qo.getName())) {
                    qh = new NamedQueryHandler();
                    ((NamedQueryHandler) qh).setName(qo.getName());
                }
            }
        }
        if (qh == null) {
            if (storedProcedure.isFunctionType()) {
                qh = new StoredFunctionQueryHandler();
            } else {
                qh = new StoredProcedureQueryHandler();
            }
            ((StoredProcedureQueryHandler) qh).setName(qualifiedProcName);
        }
        qo.setQueryHandler(qh);
        String returnType = procedureOperationModel.getReturnType();
        boolean isCollection = procedureOperationModel.isCollection();
        boolean isSimpleXMLFormat = procedureOperationModel.isSimpleXMLFormat();
        Result result = null;
        /**
         * For multiple OUT args as well as a stored function with OUT args, we want
         * the result to be a collection and the type to be "xsd:any".  We will
         * force SimpleXMLFormat for now as well.
         */
        int outArgCount = 0;
        for (ArgumentType argument : storedProcedure.getArguments()) {
            ArgumentTypeDirection argDirection = argument.getDirection();
            if (argDirection == OUT) {
                outArgCount++;
            }
        }
        if (outArgCount > 1 || (outArgCount > 0 && storedProcedure.isFunctionType())) {
            isCollection = true;
            isSimpleXMLFormat = true;
            result = new CollectionResult();
            result.setType(ANY_QNAME);
        } else {
            if (storedProcedure.isFunctionType()) {
                ArgumentType returnArg = ((FunctionType) storedProcedure).getReturnArgument();
                result = buildResultForStoredFunction(returnArg, returnType);
                // tags to better represent the PL/SQL record/table/column type
                if (returnArg.getEnclosedType().isPLSQLCursorType()) {
                    customizeSimpleXMLTagNames((PLSQLCursorType) returnArg.getEnclosedType(), procedureOperationModel);
                }
            } else if (hasComplexArgs) {
                if (Util.noOutArguments(storedProcedure)) {
                    result = new Result();
                    // rowcount
                    result.setType(new QName(SCHEMA_URL, INT, SCHEMA_PREFIX));
                }
            } else {
                // if user overrides returnType, assume they're right
                if (returnType != null) {
                    result = new Result();
                    result.setType(buildCustomQName(returnType, dbwsBuilder));
                } else {
                    if (isCollection) {
                        result = new CollectionResult();
                        if (isSimpleXMLFormat) {
                            result.setType(SXF_QNAME_CURSOR);
                        }
                    } else {
                        result = new Result();
                        result.setType(SXF_QNAME);
                    }
                }
            }
        }
        for (ArgumentType arg : storedProcedure.getArguments()) {
            String argName = arg.getArgumentName();
            if (argName != null) {
                QName xmlType = null;
                ProcedureArgument pa = null;
                // for INOUT's
                ProcedureArgument paShadow = null;
                Parameter parm = null;
                ArgumentTypeDirection direction = arg.getDirection();
                if (!hasComplexArgs) {
                    if (arg.getEnclosedType().isPLSQLCursorType()) {
                        PLSQLCursorType cursorType = (PLSQLCursorType) arg.getEnclosedType();
                        if (cursorType.isWeaklyTyped()) {
                            xmlType = buildCustomQName("SYS_REFCURSOR", dbwsBuilder);
                        }
                    } else {
                        xmlType = getXMLTypeFromJDBCType(Util.getJDBCTypeFromTypeName(arg.getTypeName()));
                    }
                } else {
                    // handle PL/SQL records and collections
                    if (arg.getEnclosedType().isPLSQLType()) {
                        String packageName = ((PLSQLType) arg.getEnclosedType()).getParentType().getPackageName();
                        // may need to prepend package name
                        String typeString = (packageName != null && packageName.length() > 0) ? packageName + UNDERSCORE + arg.getTypeName() : arg.getTypeName();
                        // may need to strip off %
                        typeString = typeString.contains(PERCENT) ? typeString.replace(PERCENT, UNDERSCORE) : typeString;
                        xmlType = buildCustomQName(nct.generateSchemaAlias(typeString), dbwsBuilder);
                    } else if (arg.getEnclosedType().isVArrayType() || arg.getEnclosedType().isObjectType() || arg.getEnclosedType().isObjectTableType()) {
                        // handle advanced JDBC types
                        xmlType = buildCustomQName(nct.generateSchemaAlias(arg.getTypeName()), dbwsBuilder);
                    } else {
                        switch(Util.getJDBCTypeFromTypeName(arg.getTypeName())) {
                            case STRUCT:
                            case ARRAY:
                                String typeString = nct.generateSchemaAlias(arg.getTypeName());
                                xmlType = buildCustomQName(typeString, dbwsBuilder);
                                break;
                            default:
                                xmlType = getXMLTypeFromJDBCType(Util.getJDBCTypeFromTypeName(arg.getTypeName()));
                                break;
                        }
                    }
                }
                if (direction == null || direction == IN) {
                    parm = new Parameter();
                    parm.setName(argName);
                    parm.setType(xmlType);
                    // handle optional arg
                    parm.setOptional(arg.optional());
                    pa = new ProcedureArgument();
                    pa.setName(argName);
                    pa.setParameterName(argName);
                    if (qh instanceof StoredProcedureQueryHandler) {
                        ((StoredProcedureQueryHandler) qh).getInArguments().add(pa);
                    }
                } else {
                    // the first OUT/INOUT arg determines singleResult vs. collectionResult
                    pa = new ProcedureOutputArgument();
                    ProcedureOutputArgument pao = (ProcedureOutputArgument) pa;
                    pao.setName(argName);
                    pao.setParameterName(argName);
                    boolean isCursor = arg.isPLSQLCursorType() || arg.getTypeName().contains(CURSOR_STR);
                    // tags to better represent the PL/SQL record/table/column type
                    if (arg.isPLSQLCursorType()) {
                        customizeSimpleXMLTagNames((PLSQLCursorType) arg.getEnclosedType(), procedureOperationModel);
                    }
                    if (isCursor && returnType == null) {
                        // if user overrides returnType, assume they're right
                        pao.setResultType(SXF_QNAME_CURSOR);
                        if (result == null) {
                            result = new CollectionResult();
                            result.setType(SXF_QNAME_CURSOR);
                        }
                    } else {
                        // Hmm, multiple OUT's gonna be a problem - later!
                        if (returnType != null && !isSimpleXMLFormat) {
                            xmlType = qNameFromString(OPEN_PAREN + dbwsBuilder.getTargetNamespace() + CLOSE_PAREN + returnType, dbwsBuilder.getSchema());
                        }
                        if (isCursor) {
                            pao.setResultType(new QName(EMPTY_STRING, CURSOR_OF_STR + returnType));
                            Result newResult = new CollectionResult();
                            newResult.setType(result.getType());
                            result = newResult;
                        } else {
                            pao.setResultType(xmlType);
                        }
                        if (result == null) {
                            if (isCollection) {
                                result = new CollectionResult();
                            } else {
                                result = new Result();
                            }
                            result.setType(xmlType);
                        }
                    }
                    if (direction == INOUT) {
                        parm = new Parameter();
                        parm.setName(argName);
                        parm.setType(xmlType);
                        result.setType(xmlType);
                        if (qh instanceof StoredProcedureQueryHandler) {
                            ((StoredProcedureQueryHandler) qh).getInOutArguments().add(pao);
                        }
                        paShadow = new ProcedureArgument();
                        paShadow.setName(argName);
                        paShadow.setParameterName(argName);
                    } else {
                        // OUT arg
                        if (qh instanceof StoredProcedureQueryHandler) {
                            ((StoredProcedureQueryHandler) qh).getOutArguments().add(pao);
                        }
                    }
                }
                // for XMLType, we want the type code to be 'OPAQUE' (2007)
                if (arg.getEnclosedType() == ScalarDatabaseTypeEnum.XMLTYPE_TYPE) {
                    pa.setJdbcType(getJDBCTypeForTypeName(XMLTYPE_STR));
                }
                if (hasComplexArgs && arg.getEnclosedType().isPLSQLType()) {
                    pa.setComplexTypeName(storedProcedure.getCatalogName() + UNDERSCORE + arg.getTypeName());
                    if (paShadow != null) {
                        paShadow.setComplexTypeName(pa.getComplexTypeName());
                    }
                }
                if (parm != null) {
                    qo.getParameters().add(parm);
                }
            }
        }
        if (procedureOperationModel.getBinaryAttachment()) {
            Attachment attachment = new Attachment();
            attachment.setMimeType(APP_OCTET_STREAM);
            result.setAttachment(attachment);
        }
        // the user may want simpleXMLFormat
        handleSimpleXMLFormat(isSimpleXMLFormat, result, procedureOperationModel);
        qo.setResult(result);
        dbwsBuilder.getXrServiceModel().getOperations().put(qo.getName(), qo);
    }
    finishProcedureOperation();
}
Also used : ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) StoredProcedureQueryHandler(org.eclipse.persistence.internal.xr.StoredProcedureQueryHandler) StoredFunctionQueryHandler(org.eclipse.persistence.internal.xr.StoredFunctionQueryHandler) QueryHandler(org.eclipse.persistence.internal.xr.QueryHandler) NamedQueryHandler(org.eclipse.persistence.internal.xr.NamedQueryHandler) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) Util.buildCustomQName(org.eclipse.persistence.tools.dbws.Util.buildCustomQName) QName(javax.xml.namespace.QName) FunctionType(org.eclipse.persistence.tools.oracleddl.metadata.FunctionType) StoredProcedureQueryHandler(org.eclipse.persistence.internal.xr.StoredProcedureQueryHandler) PLSQLCursorType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCursorType) Attachment(org.eclipse.persistence.internal.xr.Attachment) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString) ArgumentType(org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType) ProcedureArgument(org.eclipse.persistence.internal.xr.ProcedureArgument) ProcedureOutputArgument(org.eclipse.persistence.internal.xr.ProcedureOutputArgument) CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) Result(org.eclipse.persistence.internal.xr.Result) StoredFunctionQueryHandler(org.eclipse.persistence.internal.xr.StoredFunctionQueryHandler) CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) NamedQueryHandler(org.eclipse.persistence.internal.xr.NamedQueryHandler) Parameter(org.eclipse.persistence.internal.xr.Parameter) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) ArgumentTypeDirection(org.eclipse.persistence.tools.oracleddl.metadata.ArgumentTypeDirection)

Example 4 with CollectionResult

use of org.eclipse.persistence.internal.xr.CollectionResult in project eclipselink by eclipse-ee4j.

the class OracleHelper method buildResultForStoredFunction.

/**
 * Build and return a Result instance based on a given ProcedureType
 * and return type name.
 */
protected Result buildResultForStoredFunction(ArgumentType returnArgument, String returnType) {
    Result result = null;
    DatabaseType rargDataType = returnArgument.getEnclosedType();
    // handle ref cursor
    if (rargDataType.isPLSQLCursorType() || returnArgument.getTypeName().contains(CURSOR_STR)) {
        result = new CollectionResult();
        result.setType(SXF_QNAME_CURSOR);
    } else {
        result = new Result();
        int rargJdbcType = OTHER;
        if (rargDataType.isComposite()) {
            if (rargDataType.isObjectType()) {
                rargJdbcType = STRUCT;
            } else if (rargDataType.isVArrayType() || rargDataType.isObjectTableType()) {
                rargJdbcType = ARRAY;
            }
        } else {
            rargJdbcType = Util.getJDBCTypeFromTypeName(returnArgument.getTypeName());
        }
        switch(rargJdbcType) {
            case OTHER:
                String returnTypeName;
                // if user overrides returnType, assume they're right
                if (returnType != null && returnType.length() > 0) {
                    returnTypeName = returnType;
                } else {
                    returnType = rargDataType.getTypeName();
                    // packages only apply to PL/SQL types
                    String packageName = null;
                    if (rargDataType.isPLSQLType()) {
                        packageName = ((PLSQLType) rargDataType).getParentType().getPackageName();
                    }
                    // may need to prepend a package name
                    returnTypeName = (packageName != null && packageName.length() > 0) ? packageName + UNDERSCORE + returnType : returnType;
                    // may need to strip off %
                    returnTypeName = returnTypeName.contains(PERCENT) ? returnTypeName.replace(PERCENT, UNDERSCORE) : returnTypeName;
                    returnTypeName = nct.generateSchemaAlias(returnTypeName);
                }
                result.setType(buildCustomQName(returnTypeName, dbwsBuilder));
                break;
            case STRUCT:
            case ARRAY:
                // if user overrides returnType, assume they're right
                if (returnType == null || returnType.length() == 0) {
                    returnType = rargDataType.getTypeName().toLowerCase().concat(TYPE_STR);
                }
                result.setType(buildCustomQName(returnType, dbwsBuilder));
                break;
            default:
                // scalar types
                result.setType(getXMLTypeFromJDBCType(rargJdbcType));
                break;
        }
    }
    // for XMLType, we want the type code to be 'OPAQUE' (2007)
    if (rargDataType == ScalarDatabaseTypeEnum.XMLTYPE_TYPE) {
        result.setJdbcType(getJDBCTypeForTypeName(XMLTYPE_STR));
    }
    return result;
}
Also used : CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) Util.getAttributeClassForDatabaseType(org.eclipse.persistence.tools.dbws.Util.getAttributeClassForDatabaseType) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString) PLSQLType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType) CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) Result(org.eclipse.persistence.internal.xr.Result)

Example 5 with CollectionResult

use of org.eclipse.persistence.internal.xr.CollectionResult in project eclipselink by eclipse-ee4j.

the class SQLOperationModel method buildOperation.

@Override
public void buildOperation(DBWSBuilder builder) {
    super.buildOperation(builder);
    QueryOperation qo = new QueryOperation();
    qo.setName(name);
    SQLQueryHandler sqlqh = new SQLQueryHandler();
    Result result;
    if (isCollection) {
        result = new CollectionResult();
    } else {
        result = new Result();
    }
    SimpleXMLFormat sxf = null;
    if (isSimpleXMLFormat() || getReturnType() == null) {
        sxf = new SimpleXMLFormat();
        if (simpleXMLFormatTag != null && simpleXMLFormatTag.length() > 0) {
            sxf.setSimpleXMLFormatTag(simpleXMLFormatTag);
        }
        result.setType(SXF_QNAME);
    }
    if (xmlTag != null && xmlTag.length() > 0) {
        if (sxf == null) {
            sxf = new SimpleXMLFormat();
            result.setType(SXF_QNAME);
        }
        sxf.setXMLTag(xmlTag);
    }
    if (sxf != null) {
        result.setSimpleXMLFormat(sxf);
        // check to see if the O-X project needs descriptor for SimpleXMLFormat
        if (builder.oxProject.getDescriptorForAlias(DEFAULT_SIMPLE_XML_FORMAT_TAG) == null) {
            SimpleXMLFormatProject sxfProject = new SimpleXMLFormatProject();
            builder.oxProject.addDescriptor(sxfProject.buildXRRowSetModelDescriptor());
        }
    }
    if (binaryAttachment) {
        Attachment attachment = new Attachment();
        attachment.setMimeType(DEFAULT_ATTACHMENT_MIMETYPE);
        result.setAttachment(attachment);
    }
    if (returnType != null && returnType.length() > 0) {
        result.setType(qNameFromString("{" + builder.getTargetNamespace() + "}" + returnType, builder.schema));
    } else {
        result.setType(SXF_QNAME);
        result.setSimpleXMLFormat(sxf == null ? new SimpleXMLFormat() : sxf);
    }
    qo.setResult(result);
    sqlqh.setSqlString(convertJDBCParameterBindingMarkers(sql, bindings));
    if (!bindings.isEmpty()) {
        for (BindingModel param : bindings) {
            Parameter p = new Parameter();
            p.setName(param.name);
            p.setType(qNameFromString(param.type, builder.schema));
            qo.getParameters().add(p);
        }
    }
    qo.setQueryHandler(sqlqh);
    builder.xrServiceModel.getOperations().put(qo.getName(), qo);
    // check to see if the schema requires sxfType to be added
    if (requiresSimpleXMLFormat(builder.xrServiceModel) && builder.schema.getTopLevelElements().get("simple-xml-format") == null) {
        addSimpleXMLFormat(builder.schema);
    }
}
Also used : CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) SQLQueryHandler(org.eclipse.persistence.internal.xr.SQLQueryHandler) Parameter(org.eclipse.persistence.internal.xr.Parameter) Attachment(org.eclipse.persistence.internal.xr.Attachment) Util.addSimpleXMLFormat(org.eclipse.persistence.tools.dbws.Util.addSimpleXMLFormat) SimpleXMLFormat(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormat) Util.requiresSimpleXMLFormat(org.eclipse.persistence.tools.dbws.Util.requiresSimpleXMLFormat) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) Result(org.eclipse.persistence.internal.xr.Result) CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult)

Aggregations

CollectionResult (org.eclipse.persistence.internal.xr.CollectionResult)6 Result (org.eclipse.persistence.internal.xr.Result)5 Parameter (org.eclipse.persistence.internal.xr.Parameter)4 QueryOperation (org.eclipse.persistence.internal.xr.QueryOperation)4 QName (javax.xml.namespace.QName)3 Attachment (org.eclipse.persistence.internal.xr.Attachment)3 NamedQueryHandler (org.eclipse.persistence.internal.xr.NamedQueryHandler)3 Util.qNameFromString (org.eclipse.persistence.tools.dbws.Util.qNameFromString)3 ProcedureArgument (org.eclipse.persistence.internal.xr.ProcedureArgument)2 ProcedureOutputArgument (org.eclipse.persistence.internal.xr.ProcedureOutputArgument)2 QueryHandler (org.eclipse.persistence.internal.xr.QueryHandler)2 StoredFunctionQueryHandler (org.eclipse.persistence.internal.xr.StoredFunctionQueryHandler)2 StoredProcedureQueryHandler (org.eclipse.persistence.internal.xr.StoredProcedureQueryHandler)2 SimpleXMLFormatProject (org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject)2 DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)2 Util.buildCustomQName (org.eclipse.persistence.tools.dbws.Util.buildCustomQName)2 ArgumentType (org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType)2 ArgumentTypeDirection (org.eclipse.persistence.tools.oracleddl.metadata.ArgumentTypeDirection)2 CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)2 DatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType)2