Search in sources :

Example 1 with ObjectArrayMapping

use of org.eclipse.persistence.mappings.structures.ObjectArrayMapping in project eclipselink by eclipse-ee4j.

the class ArrayAccessor method process.

/**
 * INTERNAL:
 * Process the ArrayMapping or ObjectArrayMapping.
 */
@Override
public void process() {
    if (isDirectEmbeddableCollection()) {
        ObjectArrayMapping mapping = new ObjectArrayMapping();
        // Add the mapping to the descriptor.
        setMapping(mapping);
        // Set the reference class name.
        mapping.setReferenceClassName(getReferenceClassName());
        // Set the attribute name.
        mapping.setAttributeName(getAttributeName());
        // Will check for PROPERTY access
        setAccessorMethods(mapping);
        mapping.setStructureName(getDatabaseType());
        // Process the @Column or column element if there is one.
        // A number of methods depend on this field so it must be
        // initialized before any further processing can take place.
        mapping.setField(new ObjectRelationalDatabaseField(getDatabaseField(getDescriptor().getPrimaryTable(), MetadataLogger.COLUMN)));
    } else {
        ArrayMapping mapping = new ArrayMapping();
        // Add the mapping to the descriptor.
        setMapping(mapping);
        // Set the attribute name.
        mapping.setAttributeName(getAttributeName());
        // Will check for PROPERTY access
        setAccessorMethods(mapping);
        mapping.setStructureName(getDatabaseType());
        // Process the @Column or column element if there is one.
        // A number of methods depend on this field so it must be
        // initialized before any further processing can take place.
        mapping.setField(new ObjectRelationalDatabaseField(getDatabaseField(getDescriptor().getPrimaryTable(), MetadataLogger.COLUMN)));
    }
}
Also used : ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) ObjectArrayMapping(org.eclipse.persistence.mappings.structures.ObjectArrayMapping) ArrayMapping(org.eclipse.persistence.mappings.structures.ArrayMapping) ObjectArrayMapping(org.eclipse.persistence.mappings.structures.ObjectArrayMapping)

Example 2 with ObjectArrayMapping

use of org.eclipse.persistence.mappings.structures.ObjectArrayMapping in project eclipselink by eclipse-ee4j.

the class OracleHelper method buildAndAddObjectArrayMapping.

/**
 * Builds an ObjectArrayMapping based on a given attribute name, field name,
 * reference class name, field type and package name, and adds the newly
 * created mapping to the given OR descriptor.
 */
protected ObjectArrayMapping buildAndAddObjectArrayMapping(ObjectRelationalDataTypeDescriptor orDesc, String attributeName, String fieldName, String referenceClassName, String structureName) {
    ObjectArrayMapping objectArrayMapping = buildObjectArrayMapping(attributeName, fieldName, referenceClassName, structureName);
    orDesc.addMapping(objectArrayMapping);
    return objectArrayMapping;
}
Also used : ObjectArrayMapping(org.eclipse.persistence.mappings.structures.ObjectArrayMapping)

Example 3 with ObjectArrayMapping

use of org.eclipse.persistence.mappings.structures.ObjectArrayMapping in project eclipselink by eclipse-ee4j.

the class PLSQLProject method buildEmployeeDescriptor.

protected void buildEmployeeDescriptor() {
    ObjectRelationalDataTypeDescriptor descriptor = new ObjectRelationalDataTypeDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setTableName("PLSQL_EMP");
    descriptor.setStructureName("PLSQL_P_PLSQL_EMP_REC");
    descriptor.descriptorIsAggregate();
    descriptor.getQueryManager().addQuery("EmployeeListIn", buildEmployeeListInQuery());
    descriptor.getQueryManager().addQuery("EmployeeListOut", buildEmployeeListOutQuery());
    descriptor.getQueryManager().addQuery("EmployeeListInOut", buildEmployeeListInOutQuery());
    descriptor.getQueryManager().addQuery("EmployeeInObject", buildEmployeeInQuery());
    descriptor.getQueryManager().addQuery("EmployeeOutObject", buildEmployeeOutQuery());
    descriptor.getQueryManager().addQuery("EmployeeInOutObject", buildEmployeeInOutQuery());
    descriptor.addFieldOrdering("EMP_ID");
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("id");
    idMapping.setFieldName("EMP_ID");
    descriptor.addMapping(idMapping);
    descriptor.addFieldOrdering("NAME");
    DirectToFieldMapping nameMapping = new DirectToFieldMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setFieldName("NAME");
    descriptor.addMapping(nameMapping);
    descriptor.addFieldOrdering("ACTIVE");
    DirectToFieldMapping activeMapping = new DirectToFieldMapping();
    activeMapping.setAttributeName("active");
    activeMapping.setFieldName("ACTIVE");
    descriptor.addMapping(activeMapping);
    descriptor.addFieldOrdering("ADDRESS");
    StructureMapping addressMapping = new StructureMapping();
    addressMapping.setAttributeName("address");
    addressMapping.setFieldName("ADDRESS");
    addressMapping.setReferenceClass(Address.class);
    descriptor.addMapping(addressMapping);
    descriptor.addFieldOrdering("PHONES");
    ObjectArrayMapping phonesMapping = new ObjectArrayMapping();
    phonesMapping.setStructureName("PLSQL_P_PLSQL_PHONE_LIST");
    phonesMapping.setAttributeName("phones");
    phonesMapping.setFieldName("PHONES");
    phonesMapping.setReferenceClass(Phone.class);
    descriptor.addMapping(phonesMapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ObjectArrayMapping(org.eclipse.persistence.mappings.structures.ObjectArrayMapping) StructureMapping(org.eclipse.persistence.mappings.structures.StructureMapping) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)

Example 4 with ObjectArrayMapping

use of org.eclipse.persistence.mappings.structures.ObjectArrayMapping in project eclipselink by eclipse-ee4j.

the class VeearrayTestSuite method setUp.

@BeforeClass
public static void setUp() {
    final String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
    if ("true".equalsIgnoreCase(ddlCreateProp)) {
        ddlCreate = true;
    }
    final String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
    if ("true".equalsIgnoreCase(ddlDropProp)) {
        ddlDrop = true;
    }
    final String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
    if ("true".equalsIgnoreCase(ddlDebugProp)) {
        ddlDebug = true;
    }
    String username = System.getProperty(DATABASE_USERNAME_KEY);
    if (username == null) {
        fail("error retrieving database username");
    }
    String password = System.getProperty(DATABASE_PASSWORD_KEY);
    if (password == null) {
        fail("error retrieving database password");
    }
    String url = System.getProperty(DATABASE_URL_KEY);
    if (url == null) {
        fail("error retrieving database url");
    }
    String driver = System.getProperty(DATABASE_DRIVER_KEY);
    if (driver == null) {
        fail("error retrieving database driver");
    }
    Project orProject = new Project();
    orProject.setName("or-veearray");
    DatabaseLogin login = new DatabaseLogin();
    login.setUserName(username);
    login.setPassword(password);
    login.setConnectionString(url);
    login.setDriverClassName(driver);
    login.setDatasourcePlatform(new Oracle10Platform());
    login.bindAllParameters();
    orProject.setDatasourceLogin(login);
    ObjectRelationalDataTypeDescriptor phoneORDescriptor = new ObjectRelationalDataTypeDescriptor();
    phoneORDescriptor.setAlias("phone");
    phoneORDescriptor.useSoftCacheWeakIdentityMap();
    phoneORDescriptor.setJavaClass(Phone.class);
    phoneORDescriptor.descriptorIsAggregate();
    phoneORDescriptor.setStructureName("XR_VEE_ARRAY_PHONE");
    phoneORDescriptor.addFieldOrdering("AREACODE");
    phoneORDescriptor.addFieldOrdering("PHONENUMBER");
    phoneORDescriptor.addFieldOrdering("PHONETYPE");
    phoneORDescriptor.addDirectMapping("areaCode", "AREACODE");
    phoneORDescriptor.addDirectMapping("phonenumber", "PHONENUMBER");
    phoneORDescriptor.addDirectMapping("type", "PHONETYPE");
    orProject.addDescriptor(phoneORDescriptor);
    ObjectRelationalDataTypeDescriptor employeeORDescriptor = new ObjectRelationalDataTypeDescriptor();
    employeeORDescriptor.useSoftCacheWeakIdentityMap();
    employeeORDescriptor.getQueryManager().checkCacheForDoesExist();
    employeeORDescriptor.setAlias("employee");
    employeeORDescriptor.setJavaClass(Employee.class);
    employeeORDescriptor.addTableName("XR_VEE_ARRAY_EMP");
    employeeORDescriptor.addPrimaryKeyFieldName("XR_VEE_ARRAY_EMP.EMPNO");
    orProject.addDescriptor(employeeORDescriptor);
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("id");
    idMapping.setFieldName("XR_VEE_ARRAY_EMP.EMPNO");
    employeeORDescriptor.addMapping(idMapping);
    DirectToFieldMapping firstNameMapping = new DirectToFieldMapping();
    firstNameMapping.setAttributeName("firstName");
    firstNameMapping.setFieldName("XR_VEE_ARRAY_EMP.FNAME");
    employeeORDescriptor.addMapping(firstNameMapping);
    DirectToFieldMapping lastNameMapping = new DirectToFieldMapping();
    lastNameMapping.setAttributeName("lastName");
    lastNameMapping.setFieldName("XR_VEE_ARRAY_EMP.LNAME");
    employeeORDescriptor.addMapping(lastNameMapping);
    ObjectArrayMapping phonesMapping = new ObjectArrayMapping();
    phonesMapping.setAttributeName("phones");
    phonesMapping.setStructureName("XR_VEE_ARRAY_PHONES");
    phonesMapping.setReferenceClass(Phone.class);
    phonesMapping.setFieldName("PHONES");
    employeeORDescriptor.addMapping(phonesMapping);
    ReadAllQuery raq = new ReadAllQuery(Employee.class);
    raq.setName("getVeeArrayEmployees");
    raq.refreshIdentityMapResult();
    StoredProcedureCall spCall = new StoredProcedureCall();
    spCall.setProcedureName("GET_VEE_ARRAY_EMPS");
    spCall.useNamedCursorOutputAsResultSet("X");
    raq.setCall(spCall);
    employeeORDescriptor.getQueryManager().addQuery("getVeeArrayEmployees", raq);
    ReadObjectQuery roq = new ReadObjectQuery(Employee.class);
    roq.setName("getVeeArrayEmployee");
    roq.refreshIdentityMapResult();
    roq.addArgument("X");
    spCall = new StoredProcedureCall();
    spCall.setProcedureName("GET_VEE_ARRAY_EMP");
    spCall.addNamedArgument("X", "X", Types.INTEGER);
    spCall.useNamedCursorOutputAsResultSet("Y");
    roq.setCall(spCall);
    employeeORDescriptor.getQueryManager().addQuery("getVeeArrayEmployee", roq);
    ObjectRelationalDatabaseField ordf = new ObjectRelationalDatabaseField("");
    ordf.setSqlType(Types.STRUCT);
    ordf.setSqlTypeName("XR_VEE_ARRAY_PHONE");
    ordf.setType(Phone.class);
    DataModifyQuery dataModifyQuery = new DataModifyQuery();
    dataModifyQuery.setName("updateVeeArrayPhones");
    dataModifyQuery.addArgument("X");
    dataModifyQuery.addArgument("Y");
    spCall = new StoredProcedureCall();
    spCall.setProcedureName("UPDATE_VEE_ARRAY_PHS");
    spCall.addNamedArgument("X", "X", Types.INTEGER);
    spCall.addNamedArgument("Y", "Y", Types.ARRAY, "XR_VEE_ARRAY_PHONES", ordf);
    dataModifyQuery.setCall(spCall);
    employeeORDescriptor.getQueryManager().addQuery("updateVeeArrayPhones", dataModifyQuery);
    NamespaceResolver ns = new NamespaceResolver();
    ns.setDefaultNamespaceURI("urn:veearray");
    Project oxProject = new Project();
    oxProject.setName("ox-veearray");
    XMLLogin xmlLogin = new XMLLogin();
    xmlLogin.getProperties().remove("user");
    xmlLogin.getProperties().remove("password");
    oxProject.setLogin(xmlLogin);
    XMLDescriptor employeeOXDescriptor = new XMLDescriptor();
    employeeOXDescriptor.setAlias("employee");
    employeeOXDescriptor.setJavaClass(Employee.class);
    employeeOXDescriptor.setDefaultRootElement("employee");
    employeeOXDescriptor.setNamespaceResolver(ns);
    XMLSchemaURLReference schemaReference = new XMLSchemaURLReference();
    schemaReference.setSchemaContext("/employeeType");
    schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
    employeeOXDescriptor.setSchemaReference(schemaReference);
    XMLDirectMapping xmlIdMapping = new XMLDirectMapping();
    xmlIdMapping.setAttributeName("id");
    XMLField idField = new XMLField();
    idField.setName("@id/text()");
    idField.setSchemaType(INT_QNAME);
    xmlIdMapping.setField(idField);
    employeeOXDescriptor.addMapping(xmlIdMapping);
    XMLDirectMapping xmlFirstNameMapping = new XMLDirectMapping();
    xmlFirstNameMapping.setAttributeName("firstName");
    XMLField firstNameField = new XMLField();
    firstNameField.setName("first-name/text()");
    firstNameField.setSchemaType(STRING_QNAME);
    xmlFirstNameMapping.setField(firstNameField);
    employeeOXDescriptor.addMapping(xmlFirstNameMapping);
    XMLDirectMapping xmlLastNameMapping = new XMLDirectMapping();
    xmlLastNameMapping.setAttributeName("lastName");
    XMLField lastNameField = new XMLField();
    lastNameField.setName("last-name/text()");
    lastNameField.setSchemaType(STRING_QNAME);
    xmlLastNameMapping.setField(lastNameField);
    employeeOXDescriptor.addMapping(xmlLastNameMapping);
    XMLCompositeCollectionMapping xmlPhonesMapping = new XMLCompositeCollectionMapping();
    xmlPhonesMapping.setAttributeName("phones");
    xmlPhonesMapping.setReferenceClass(Phone.class);
    xmlPhonesMapping.setXPath("phones/phone");
    employeeOXDescriptor.addMapping(xmlPhonesMapping);
    oxProject.addDescriptor(employeeOXDescriptor);
    XMLDescriptor phoneOXDescriptor = new XMLDescriptor();
    phoneOXDescriptor.setAlias("phone");
    phoneOXDescriptor.setJavaClass(Phone.class);
    phoneOXDescriptor.setDefaultRootElement("phone");
    phoneOXDescriptor.setNamespaceResolver(ns);
    schemaReference = new XMLSchemaURLReference();
    schemaReference.setSchemaContext("/phoneType");
    schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
    phoneOXDescriptor.setSchemaReference(schemaReference);
    XMLDirectMapping areaCodeMapping = new XMLDirectMapping();
    areaCodeMapping.setAttributeName("areaCode");
    XMLField areaCodeField = new XMLField();
    areaCodeField.setName("area-code/text()");
    areaCodeField.setSchemaType(STRING_QNAME);
    areaCodeMapping.setField(areaCodeField);
    phoneOXDescriptor.addMapping(areaCodeMapping);
    XMLDirectMapping phonenumberMapping = new XMLDirectMapping();
    phonenumberMapping.setAttributeName("phonenumber");
    XMLField phonenumberField = new XMLField();
    phonenumberField.setName("phonenumber/text()");
    phonenumberField.setSchemaType(STRING_QNAME);
    phonenumberMapping.setField(phonenumberField);
    phoneOXDescriptor.addMapping(phonenumberMapping);
    XMLDirectMapping typeMapping = new XMLDirectMapping();
    typeMapping.setAttributeName("type");
    XMLField typeField = new XMLField();
    typeField.setName("type/text()");
    typeField.setSchemaType(STRING_QNAME);
    typeMapping.setField(typeField);
    phoneOXDescriptor.addMapping(typeMapping);
    oxProject.addDescriptor(phoneOXDescriptor);
    XRServiceFactory factory = new XRServiceFactory() {

        Project orProject;

        Project oxProject;

        XRServiceFactory setProject(Project orProject, Project oxProject) {
            this.orProject = orProject;
            this.oxProject = oxProject;
            parentClassLoader = ClassLoader.getSystemClassLoader();
            xrSchemaStream = new ByteArrayInputStream(VEEARRAY_SCHEMA.getBytes());
            return this;
        }

        @Override
        public void buildSessions() {
            DatabaseSession ds = orProject.createDatabaseSession();
            ds.dontLogMessages();
            xrService.setORSession(ds);
            xrService.setXMLContext(new XMLContext(oxProject));
            xrService.setOXSession(xrService.getXMLContext().getSession(0));
        }
    }.setProject(orProject, oxProject);
    XMLContext context = new XMLContext(new DBWSModelProject());
    XMLUnmarshaller unmarshaller = context.createUnmarshaller();
    DBWSModel model = (DBWSModel) unmarshaller.unmarshal(new StringReader(VEEARRAY_XRMODEL));
    xrService = factory.buildService(model);
    if (ddlCreate) {
        try {
            AllTests.runDdl(CREATE_DDL, ddlDebug);
        } catch (Exception e) {
        // e.printStackTrace();
        }
    }
}
Also used : Oracle10Platform(org.eclipse.persistence.platform.database.oracle.Oracle10Platform) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) StringReader(java.io.StringReader) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor) DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery) DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) XMLField(org.eclipse.persistence.oxm.XMLField) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) DBWSModel(org.eclipse.persistence.dbws.DBWSModel) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) StoredProcedureCall(org.eclipse.persistence.queries.StoredProcedureCall) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLSchemaURLReference(org.eclipse.persistence.oxm.schema.XMLSchemaURLReference) SQLException(java.sql.SQLException) Project(org.eclipse.persistence.sessions.Project) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) XRServiceFactory(org.eclipse.persistence.internal.xr.XRServiceFactory) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ByteArrayInputStream(java.io.ByteArrayInputStream) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) ObjectArrayMapping(org.eclipse.persistence.mappings.structures.ObjectArrayMapping) BeforeClass(org.junit.BeforeClass)

Example 5 with ObjectArrayMapping

use of org.eclipse.persistence.mappings.structures.ObjectArrayMapping in project eclipselink by eclipse-ee4j.

the class OracleHelper method buildObjectArrayMapping.

/**
 * Builds an ObjectArrayMapping based on a given attribute name, field name,
 * reference class name and structureName.
 */
protected ObjectArrayMapping buildObjectArrayMapping(String attributeName, String fieldName, String referenceClassName, String structureName) {
    ObjectArrayMapping objectArrayMapping = new ObjectArrayMapping();
    objectArrayMapping.setAttributeName(attributeName);
    objectArrayMapping.setFieldName(fieldName);
    objectArrayMapping.setStructureName(structureName);
    objectArrayMapping.useCollectionClass(ArrayList.class);
    objectArrayMapping.setReferenceClassName(referenceClassName);
    // we have a map of created descriptors, keyed on javaClassName, which - along with a
    // list of referenceClassNames (set upon reference mapping creation) will allow us
    // to set aggregate descriptors as required.
    referencedORDescriptors.add(referenceClassName);
    return objectArrayMapping;
}
Also used : ObjectArrayMapping(org.eclipse.persistence.mappings.structures.ObjectArrayMapping)

Aggregations

ObjectArrayMapping (org.eclipse.persistence.mappings.structures.ObjectArrayMapping)6 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)2 ObjectRelationalDataTypeDescriptor (org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)2 ObjectRelationalDatabaseField (org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringReader (java.io.StringReader)1 SQLException (java.sql.SQLException)1 DBWSModel (org.eclipse.persistence.dbws.DBWSModel)1 DBWSModelProject (org.eclipse.persistence.dbws.DBWSModelProject)1 XRServiceFactory (org.eclipse.persistence.internal.xr.XRServiceFactory)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 ArrayMapping (org.eclipse.persistence.mappings.structures.ArrayMapping)1 StructureMapping (org.eclipse.persistence.mappings.structures.StructureMapping)1 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)1 XMLContext (org.eclipse.persistence.oxm.XMLContext)1 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)1 XMLField (org.eclipse.persistence.oxm.XMLField)1 XMLLogin (org.eclipse.persistence.oxm.XMLLogin)1 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)1 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)1