Search in sources :

Example 1 with QueryOperation

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

the class BindingModelTestSuite method checkParsedSqlText.

@Test
public void checkParsedSqlText() {
    QueryOperation queryOperation = (QueryOperation) builder.getXrServiceModel().getOperation(OPERATION);
    SQLQueryHandler sqlQueryHandler = (SQLQueryHandler) queryOperation.getQueryHandler();
    String sqlString = sqlQueryHandler.getSqlString();
    assertTrue("parse SQL text does not contain GROUP BY clause", sqlString.contains(GROUP_BY_CLAUSE));
}
Also used : SQLQueryHandler(org.eclipse.persistence.internal.xr.SQLQueryHandler) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) Test(org.junit.Test)

Example 2 with QueryOperation

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

the class WSDLGenerator method createMethodDefinition.

private void createMethodDefinition(WSDLFactory factory, ExtensionRegistry registry, Definition def, Operation operation, boolean useSOAP12) throws WSDLException {
    Message requestMessage = def.createMessage();
    requestMessage.setUndefined(false);
    requestMessage.setQName(new QName(serviceNameSpace, operation.getName() + REQUEST_SUFFIX));
    Part requestPart = def.createPart();
    requestPart.setName(operation.getName() + REQUEST_SUFFIX);
    requestPart.setElementName(new QName(serviceNameSpace, operation.getName()));
    requestMessage.addPart(requestPart);
    def.addMessage(requestMessage);
    Message responseMessage = null;
    if (operation.hasResponse()) {
        responseMessage = def.createMessage();
        responseMessage.setUndefined(false);
        responseMessage.setQName(new QName(serviceNameSpace, operation.getName() + RESPONSE_SUFFIX));
        Part responsePart = def.createPart();
        responsePart.setName(operation.getName() + RESPONSE_SUFFIX);
        responsePart.setElementName(new QName(serviceNameSpace, operation.getName() + RESPONSE_SUFFIX));
        responseMessage.addPart(responsePart);
        def.addMessage(responseMessage);
    }
    PortType portType = def.getPortType(new QName(serviceNameSpace, serviceName + PORT_SUFFIX));
    javax.wsdl.Operation op = def.createOperation();
    op.setUndefined(false);
    op.setName(operation.getName());
    Input input = def.createInput();
    input.setMessage(requestMessage);
    op.setInput(input);
    if (operation.hasResponse()) {
        Output output = def.createOutput();
        output.setMessage(responseMessage);
        op.setOutput(output);
    }
    portType.addOperation(op);
    Binding binding = def.getBinding(new QName(serviceNameSpace, serviceName + BINDING_SUFFIX));
    BindingOperation bop = def.createBindingOperation();
    bop.setName(operation.getName());
    ExtensibilityElement so = null;
    if (useSOAP12) {
        so = registry.createExtension(BindingOperation.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_OPERATION));
        ((SOAP12Operation) so).setSoapActionURI(serviceNameSpace + ":" + op.getName());
    } else {
        so = registry.createExtension(BindingOperation.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_OPERATION));
        ((SOAPOperation) so).setSoapActionURI(serviceNameSpace + ":" + op.getName());
    }
    bop.addExtensibilityElement(so);
    BindingInput bi = def.createBindingInput();
    ExtensibilityElement soapInputBody = null;
    if (useSOAP12) {
        soapInputBody = registry.createExtension(BindingInput.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_BODY));
        ((SOAP12Body) soapInputBody).setUse(SOAP_USE);
    } else {
        soapInputBody = registry.createExtension(BindingInput.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_BODY));
        ((SOAPBody) soapInputBody).setUse(SOAP_USE);
    }
    bi.addExtensibilityElement(soapInputBody);
    bop.setBindingInput(bi);
    if (operation.hasResponse()) {
        BindingOutput bo = def.createBindingOutput();
        ExtensibilityElement soapOutputBody = null;
        if (useSOAP12) {
            soapOutputBody = registry.createExtension(BindingOutput.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_BODY));
            ((SOAP12Body) soapOutputBody).setUse(SOAP_USE);
        } else {
            soapOutputBody = registry.createExtension(BindingOutput.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_BODY));
            ((SOAPBody) soapOutputBody).setUse(SOAP_USE);
        }
        bo.addExtensibilityElement(soapOutputBody);
        bop.setBindingOutput(bo);
    }
    if (!(operation instanceof QueryOperation)) {
        // non-QueryOperations don't have Responses, but the fault requirements
        // mean we have to create 'dummy' WSDL outputs
        BindingOutput bo = def.createBindingOutput();
        ExtensibilityElement soapOutputBody = null;
        if (useSOAP12) {
            soapOutputBody = registry.createExtension(BindingOutput.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_BODY));
            ((SOAP12Body) soapOutputBody).setUse(SOAP_USE);
        } else {
            soapOutputBody = registry.createExtension(BindingOutput.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_BODY));
            ((SOAPBody) soapOutputBody).setUse(SOAP_USE);
        }
        bo.addExtensibilityElement(soapOutputBody);
        bop.setBindingOutput(bo);
        // add WSDL fault to binding operations
        BindingFault bindingFault = def.createBindingFault();
        String exceptionName = FAULT_SUFFIX + EXCEPTION_SUFFIX;
        bindingFault.setName(exceptionName);
        ExtensibilityElement soapFaultBody = null;
        if (useSOAP12) {
            soapFaultBody = registry.createExtension(BindingFault.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_FAULT));
            ((SOAP12Fault) soapFaultBody).setUse(SOAP_USE);
            ((SOAP12Fault) soapFaultBody).setName(exceptionName);
        } else {
            soapFaultBody = registry.createExtension(BindingFault.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_FAULT));
            ((SOAPFault) soapFaultBody).setUse(SOAP_USE);
            ((SOAPFault) soapFaultBody).setName(exceptionName);
        }
        bindingFault.addExtensibilityElement(soapFaultBody);
        bop.addBindingFault(bindingFault);
        Message emptyResponseMessage = def.getMessage(new QName(serviceNameSpace, EMPTY_RESPONSE));
        Output output = def.createOutput();
        output.setName(operation.getName() + EMPTY_RESPONSE);
        output.setMessage(emptyResponseMessage);
        op.setOutput(output);
        Message faultMessage = def.getMessage(new QName(serviceNameSpace, FAULT_SUFFIX + TYPE_SUFFIX));
        Fault fault = def.createFault();
        fault.setMessage(faultMessage);
        fault.setName(exceptionName);
        op.addFault(fault);
    }
    binding.addBindingOperation(bop);
}
Also used : SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) Binding(javax.wsdl.Binding) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) BindingOutput(javax.wsdl.BindingOutput) Message(javax.wsdl.Message) SOAP12Body(javax.wsdl.extensions.soap12.SOAP12Body) BindingFault(javax.wsdl.BindingFault) QName(javax.xml.namespace.QName) SOAP12Fault(javax.wsdl.extensions.soap12.SOAP12Fault) Fault(javax.wsdl.Fault) BindingFault(javax.wsdl.BindingFault) SOAPFault(javax.wsdl.extensions.soap.SOAPFault) SOAP12Fault(javax.wsdl.extensions.soap12.SOAP12Fault) BindingInput(javax.wsdl.BindingInput) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Input(javax.wsdl.Input) BindingInput(javax.wsdl.BindingInput) BindingOperation(javax.wsdl.BindingOperation) SOAPBody(javax.wsdl.extensions.soap.SOAPBody) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) Part(javax.wsdl.Part) BindingOutput(javax.wsdl.BindingOutput) Output(javax.wsdl.Output) SOAPFault(javax.wsdl.extensions.soap.SOAPFault) PortType(javax.wsdl.PortType) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation)

Example 3 with QueryOperation

use of org.eclipse.persistence.internal.xr.QueryOperation 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 4 with QueryOperation

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

the class SOAPResponseWriter method initialize.

@SuppressWarnings("unchecked")
public void initialize() {
    SOAPResponseClassLoader loader = new SOAPResponseClassLoader(Thread.currentThread().getContextClassLoader());
    NamespaceResolver nr = new NamespaceResolver();
    nr.put(SERVICE_NAMESPACE_PREFIX, dbwsAdapter.getExtendedSchema().getTargetNamespace());
    for (Operation op : dbwsAdapter.getOperationsList()) {
        String className = op.getName() + "_Response";
        Class<?> opClass = loader.buildClass(className);
        XMLDescriptor descriptor = new XMLDescriptor();
        descriptor.setDefaultRootElement(SERVICE_NAMESPACE_PREFIX + ":" + op.getName() + "Response");
        descriptor.setNamespaceResolver(nr);
        descriptor.setJavaClass(opClass);
        if (op instanceof QueryOperation) {
            QueryOperation queryOperation = (QueryOperation) op;
            if (queryOperation.isSimpleXMLFormat()) {
                XMLAnyObjectMapping mapping = new XMLAnyObjectMapping();
                mapping.setUseXMLRoot(true);
                mapping.setAttributeName("result");
                mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                descriptor.addMapping(mapping);
                mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
            } else if (queryOperation.isAttachment()) {
                Attachment attachment = queryOperation.getResult().getAttachment();
                XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
                mapping.setAttributeName("result");
                mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                mapping.setSwaRef(true);
                mapping.setShouldInlineBinaryData(false);
                mapping.setMimeType(attachment.getMimeType());
                descriptor.addMapping(mapping);
            } else {
                QName type = queryOperation.getResult().getType();
                String localElement = type.getLocalPart();
                // look for top-level complex types
                Set<Map.Entry<String, ComplexType>> entrySet = dbwsAdapter.getSchema().getTopLevelComplexTypes().entrySet();
                for (Map.Entry<String, ComplexType> me : entrySet) {
                    if (me.getValue().getName().equals(type.getLocalPart())) {
                        localElement = me.getKey();
                        break;
                    }
                }
                XMLDescriptor typeDescriptor = dbwsAdapter.getDescriptorsByQName().get(type);
                if (typeDescriptor != null) {
                    if (queryOperation.isCollection()) {
                        XMLCompositeCollectionMapping mapping = new XMLCompositeCollectionMapping();
                        mapping.setAttributeName("result");
                        mapping.setReferenceClass(typeDescriptor.getJavaClass());
                        mapping.useCollectionClass(ArrayList.class);
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/" + localElement);
                        descriptor.getNamespaceResolver().setDefaultNamespaceURI(typeDescriptor.getNamespaceResolver().getDefaultNamespaceURI());
                        descriptor.addMapping(mapping);
                        mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
                    } else {
                        XMLCompositeObjectMapping mapping = new XMLCompositeObjectMapping();
                        mapping.setAttributeName("result");
                        mapping.setReferenceClass(typeDescriptor.getJavaClass());
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/" + localElement);
                        descriptor.getNamespaceResolver().setDefaultNamespaceURI(typeDescriptor.getNamespaceResolver().getDefaultNamespaceURI());
                        descriptor.addMapping(mapping);
                        mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
                    }
                } else {
                    if (type.equals(new QName(W3C_XML_SCHEMA_NS_URI, "any"))) {
                        XMLAnyObjectMapping mapping = new XMLAnyObjectMapping();
                        mapping.setAttributeName("result");
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                        descriptor.addMapping(mapping);
                    } else if (type.equals(new QName(W3C_XML_SCHEMA_NS_URI, BASE_64_BINARY))) {
                        XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
                        mapping.setAttributeName("result");
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                        mapping.setShouldInlineBinaryData(true);
                        ((XMLField) mapping.getField()).setSchemaType(type);
                        descriptor.addMapping(mapping);
                    } else {
                        XMLDirectMapping mapping = new XMLDirectMapping();
                        mapping.setAttributeName("result");
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/text()");
                        descriptor.addMapping(mapping);
                    }
                }
            }
        }
        dbwsAdapter.getOXSession().getProject().addDescriptor(descriptor);
        ((DatabaseSessionImpl) dbwsAdapter.getOXSession()).initializeDescriptorIfSessionAlive(descriptor);
        dbwsAdapter.getXMLContext().storeXMLDescriptorByQName(descriptor);
        resultDescriptors.put(op.getName(), descriptor);
    }
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) Set(java.util.Set) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Attachment(org.eclipse.persistence.internal.xr.Attachment) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) Operation(org.eclipse.persistence.internal.xr.Operation) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) HashMap(java.util.HashMap) Map(java.util.Map) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 5 with QueryOperation

use of org.eclipse.persistence.internal.xr.QueryOperation 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)

Aggregations

QueryOperation (org.eclipse.persistence.internal.xr.QueryOperation)9 QName (javax.xml.namespace.QName)7 Parameter (org.eclipse.persistence.internal.xr.Parameter)5 Attachment (org.eclipse.persistence.internal.xr.Attachment)4 CollectionResult (org.eclipse.persistence.internal.xr.CollectionResult)4 Result (org.eclipse.persistence.internal.xr.Result)4 BindingOperation (javax.wsdl.BindingOperation)3 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)3 SOAPOperation (javax.wsdl.extensions.soap.SOAPOperation)3 SOAP12Operation (javax.wsdl.extensions.soap12.SOAP12Operation)3 NamedQueryHandler (org.eclipse.persistence.internal.xr.NamedQueryHandler)3 Operation (org.eclipse.persistence.internal.xr.Operation)3 Binding (javax.wsdl.Binding)2 Message (javax.wsdl.Message)2 Part (javax.wsdl.Part)2 PortType (javax.wsdl.PortType)2 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)2 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)2 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)2 ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)2