Search in sources :

Example 1 with TransformerBasedFieldTransformation

use of org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation in project eclipselink by eclipse-ee4j.

the class TableTypeTestSuite method setUp.

@BeforeClass
public static void setUp() throws WSDLException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    if (conn == null) {
        try {
            conn = buildConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
    if ("true".equalsIgnoreCase(ddlCreateProp)) {
        ddlCreate = true;
    }
    String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
    if ("true".equalsIgnoreCase(ddlDropProp)) {
        ddlDrop = true;
    }
    String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
    if ("true".equalsIgnoreCase(ddlDebugProp)) {
        ddlDebug = true;
    }
    if (ddlCreate) {
        runDdl(conn, CREATE_TABLETYPE_TABLE, ddlDebug);
        runDdl(conn, CREATE_TABLETYPE2_TABLE, ddlDebug);
        try {
            Statement stmt = conn.createStatement();
            for (int i = 0; i < POPULATE_TABLETYPE_TABLE.length; i++) {
                stmt.addBatch(POPULATE_TABLETYPE_TABLE[i]);
            }
            stmt.executeBatch();
            stmt = conn.createStatement();
            for (int i = 0; i < POPULATE_TABLETYPE2_TABLE.length; i++) {
                stmt.addBatch(POPULATE_TABLETYPE2_TABLE[i]);
            }
            stmt.executeBatch();
        } catch (SQLException e) {
        // e.printStackTrace();
        }
    }
    DBWS_BUILDER_XML_USERNAME = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<dbws-builder xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + "<properties>" + "<property name=\"projectName\">tabletype</property>" + "<property name=\"logLevel\">off</property>" + "<property name=\"username\">";
    DBWS_BUILDER_XML_PASSWORD = "</property><property name=\"password\">";
    DBWS_BUILDER_XML_URL = "</property><property name=\"url\">";
    DBWS_BUILDER_XML_DRIVER = "</property><property name=\"driver\">";
    DBWS_BUILDER_XML_PLATFORM = "</property><property name=\"platformClassname\">";
    DBWS_BUILDER_XML_MAIN = "</property>" + "</properties>" + "<table " + "schemaPattern=\"%\" " + "tableNamePattern=\"TABLETYPE\" " + "/>" + "<table " + "schemaPattern=\"%\" " + "tableNamePattern=\"TABLETYPE2\" " + "/>" + "</dbws-builder>";
    builder = new DBWSBuilder();
    OracleHelper builderHelper = new OracleHelper(builder);
    builder.setBuilderHelper(builderHelper);
    Field workbenchProj_field = BaseDBWSBuilderHelper.class.getDeclaredField("workbenchXMLProject");
    workbenchProj_field.setAccessible(true);
    ObjectPersistenceWorkbenchXMLProject workbenchXMLProject = (ObjectPersistenceWorkbenchXMLProject) workbenchProj_field.get(builderHelper);
    XMLTransformationMapping versionMapping = (XMLTransformationMapping) workbenchXMLProject.getDescriptor(Project.class).getMappings().get(0);
    TransformerBasedFieldTransformation versionTransformer = (TransformerBasedFieldTransformation) versionMapping.getFieldTransformations().get(0);
    Field transformerField = TransformerBasedFieldTransformation.class.getDeclaredField("transformer");
    transformerField.setAccessible(true);
    ConstantTransformer constantTransformer = (ConstantTransformer) transformerField.get(versionTransformer);
    constantTransformer.setValue("Eclipse Persistence Services - " + releaseVersion);
    DBWSTestSuite.setUp(".");
}
Also used : TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) SQLException(java.sql.SQLException) Statement(java.sql.Statement) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) OracleHelper(org.eclipse.persistence.tools.dbws.oracle.OracleHelper) ConstantTransformer(org.eclipse.persistence.mappings.transformers.ConstantTransformer) SQLException(java.sql.SQLException) WSDLException(javax.wsdl.WSDLException) DBWSBuilder(org.eclipse.persistence.tools.dbws.DBWSBuilder) Field(java.lang.reflect.Field) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) Project(org.eclipse.persistence.sessions.Project) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) BeforeClass(org.junit.BeforeClass)

Example 2 with TransformerBasedFieldTransformation

use of org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation in project eclipselink by eclipse-ee4j.

the class PLSQLcollectionTestSuite method toProjectXML.

@Test
public void toProjectXML() throws IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException {
    ObjectPersistenceWorkbenchXMLProject runtimeProject = new ObjectPersistenceWorkbenchXMLProject();
    XMLTransformationMapping versionMapping = (XMLTransformationMapping) runtimeProject.getDescriptor(Project.class).getMappings().get(0);
    TransformerBasedFieldTransformation versionTransformer = (TransformerBasedFieldTransformation) versionMapping.getFieldTransformations().get(0);
    Field transformerField = TransformerBasedFieldTransformation.class.getDeclaredField("transformer");
    transformerField.setAccessible(true);
    ConstantTransformer constantTransformer = (ConstantTransformer) transformerField.get(versionTransformer);
    constantTransformer.setValue(CONSTANT_PROJECT_BUILD_VERSION);
    XMLContext context = new XMLContext(runtimeProject);
    XMLMarshaller marshaller = context.createMarshaller();
    Document testDoc = marshaller.objectToXML(project);
    Document controlDoc = xmlParser.parse(new StringReader(TEST_PROJECT_CONTROL_DOC));
    assertTrue("control document not same as instance document", comparer.isNodeEqual(controlDoc, testDoc));
}
Also used : ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) Project(org.eclipse.persistence.sessions.Project) Field(java.lang.reflect.Field) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) StringReader(java.io.StringReader) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) Document(org.w3c.dom.Document) ConstantTransformer(org.eclipse.persistence.mappings.transformers.ConstantTransformer) Test(org.junit.Test)

Example 3 with TransformerBasedFieldTransformation

use of org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation in project eclipselink by eclipse-ee4j.

the class OracleObjecttypeTestSuite method setUp.

@BeforeClass
public static void setUp() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    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;
    }
    final String username = System.getProperty(DATABASE_USERNAME_KEY);
    if (username == null) {
        fail("error retrieving database username");
    }
    final String password = System.getProperty(DATABASE_PASSWORD_KEY);
    if (password == null) {
        fail("error retrieving database password");
    }
    final String url = System.getProperty(DATABASE_URL_KEY);
    if (url == null) {
        fail("error retrieving database url");
    }
    final String driver = System.getProperty(DATABASE_DRIVER_KEY);
    if (driver == null) {
        fail("error retrieving database driver");
    }
    Project orProject = new Project();
    orProject.setName("or-oracleobjecttype");
    ObjectRelationalDataTypeDescriptor addressORDescriptor = new ObjectRelationalDataTypeDescriptor();
    addressORDescriptor.setAlias("address");
    addressORDescriptor.useSoftCacheWeakIdentityMap();
    addressORDescriptor.setJavaClass(Address.class);
    addressORDescriptor.descriptorIsAggregate();
    addressORDescriptor.setStructureName("XR_ADDRESS_TYPE");
    addressORDescriptor.addFieldOrdering("STREET");
    addressORDescriptor.addFieldOrdering("CITY");
    addressORDescriptor.addFieldOrdering("PROV");
    addressORDescriptor.addDirectMapping("street", "STREET");
    addressORDescriptor.addDirectMapping("city", "CITY");
    addressORDescriptor.addDirectMapping("province", "PROV");
    orProject.addDescriptor(addressORDescriptor);
    ObjectRelationalDataTypeDescriptor employeeORDescriptor = new ObjectRelationalDataTypeDescriptor();
    employeeORDescriptor.useSoftCacheWeakIdentityMap();
    employeeORDescriptor.getQueryManager().checkCacheForDoesExist();
    employeeORDescriptor.setAlias("employee");
    employeeORDescriptor.setJavaClass(EmployeeWithAddress.class);
    employeeORDescriptor.addTableName("XR_EMP_ADDR");
    employeeORDescriptor.addPrimaryKeyFieldName("XR_EMP_ADDR.EMPNO");
    orProject.addDescriptor(employeeORDescriptor);
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("id");
    idMapping.setFieldName("XR_EMP_ADDR.EMPNO");
    employeeORDescriptor.addMapping(idMapping);
    DirectToFieldMapping firstNameMapping = new DirectToFieldMapping();
    firstNameMapping.setAttributeName("firstName");
    firstNameMapping.setFieldName("XR_EMP_ADDR.FNAME");
    employeeORDescriptor.addMapping(firstNameMapping);
    DirectToFieldMapping lastNameMapping = new DirectToFieldMapping();
    lastNameMapping.setAttributeName("lastName");
    lastNameMapping.setFieldName("XR_EMP_ADDR.LNAME");
    employeeORDescriptor.addMapping(lastNameMapping);
    StructureMapping addressMapping = new StructureMapping();
    addressMapping.setAttributeName("address");
    addressMapping.setReferenceClass(Address.class);
    addressMapping.setFieldName("ADDRESS");
    employeeORDescriptor.addMapping(addressMapping);
    ReadAllQuery readQuery = new ReadAllQuery(EmployeeWithAddress.class);
    readQuery.setName("getEmployeesByProv");
    readQuery.addArgument("X");
    StoredProcedureCall spCall = new StoredProcedureCall();
    spCall.setProcedureName("GET_EMPLOYEES_BY_PROV");
    spCall.addNamedArgument("X", "X", Types.STRUCT, "XR_ADDRESS_TYPE");
    spCall.useNamedCursorOutputAsResultSet("Y");
    readQuery.setCall(spCall);
    employeeORDescriptor.getQueryManager().addQuery("getEmployeesByProv", readQuery);
    ObjectPersistenceWorkbenchXMLProject runtimeProject = new ObjectPersistenceWorkbenchXMLProject();
    XMLTransformationMapping versionMapping = (XMLTransformationMapping) runtimeProject.getDescriptor(Project.class).getMappings().firstElement();
    TransformerBasedFieldTransformation versionTransformer = (TransformerBasedFieldTransformation) versionMapping.getFieldTransformations().get(0);
    Field transformerField = TransformerBasedFieldTransformation.class.getDeclaredField("transformer");
    transformerField.setAccessible(true);
    ConstantTransformer constantTransformer = (ConstantTransformer) transformerField.get(versionTransformer);
    constantTransformer.setValue(CONSTANT_PROJECT_BUILD_VERSION);
    XMLContext context = new XMLContext(runtimeProject);
    XMLMarshaller marshaller = context.createMarshaller();
    Document orProjectDoc = xmlPlatform.createDocument();
    marshaller.marshal(orProject, orProjectDoc);
    Document orProjectXMLDoc = xmlParser.parse(new StringReader(OBJECTTYPE_OR_PROJECT));
    assertTrue("OracleObjecttype java-built OR project not same as XML-built OR project.  Expected:\n" + documentToString(orProjectXMLDoc) + "\nActual:\n" + documentToString(orProjectDoc), comparer.isNodeEqual(orProjectXMLDoc, orProjectDoc));
    NamespaceResolver ns = new NamespaceResolver();
    ns.setDefaultNamespaceURI("urn:oracleobjecttype");
    Project oxProject = new Project();
    oxProject.setName("ox-oracleobjecttype");
    XMLLogin xmlLogin = new XMLLogin();
    xmlLogin.setPlatform(new DOMPlatform());
    xmlLogin.getProperties().remove("user");
    xmlLogin.getProperties().remove("password");
    oxProject.setLogin(xmlLogin);
    XMLDescriptor addressOXDescriptor = new XMLDescriptor();
    addressOXDescriptor.setAlias("address");
    addressOXDescriptor.setJavaClass(Address.class);
    addressOXDescriptor.setDefaultRootElement("address");
    addressOXDescriptor.setNamespaceResolver(ns);
    XMLSchemaURLReference schemaReference = new XMLSchemaURLReference();
    schemaReference.setSchemaContext("/addressType");
    schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
    addressOXDescriptor.setSchemaReference(schemaReference);
    XMLDirectMapping streetMapping = new XMLDirectMapping();
    streetMapping.setAttributeName("street");
    XMLField streetField = new XMLField();
    streetField.setName("street/text()");
    streetField.setSchemaType(STRING_QNAME);
    streetMapping.setField(streetField);
    addressOXDescriptor.addMapping(streetMapping);
    XMLDirectMapping cityMapping = new XMLDirectMapping();
    cityMapping.setAttributeName("city");
    XMLField cityField = new XMLField();
    cityField.setName("city/text()");
    cityField.setSchemaType(STRING_QNAME);
    cityMapping.setField(cityField);
    addressOXDescriptor.addMapping(cityMapping);
    XMLDirectMapping provinceMapping = new XMLDirectMapping();
    provinceMapping.setAttributeName("province");
    XMLField provinceField = new XMLField();
    provinceField.setName("province/text()");
    provinceField.setSchemaType(STRING_QNAME);
    provinceMapping.setField(provinceField);
    addressOXDescriptor.addMapping(provinceMapping);
    oxProject.addDescriptor(addressOXDescriptor);
    XMLDescriptor employeeOXDescriptor = new XMLDescriptor();
    employeeOXDescriptor.setAlias("employee");
    employeeOXDescriptor.setJavaClass(EmployeeWithAddress.class);
    employeeOXDescriptor.setDefaultRootElement("employee");
    employeeOXDescriptor.setNamespaceResolver(ns);
    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);
    XMLCompositeObjectMapping xmlAddressMapping = new XMLCompositeObjectMapping();
    xmlAddressMapping.setAttributeName("address");
    xmlAddressMapping.setReferenceClass(Address.class);
    xmlAddressMapping.setXPath("address");
    employeeOXDescriptor.addMapping(xmlAddressMapping);
    oxProject.addDescriptor(employeeOXDescriptor);
    Document oxProjectDoc = xmlPlatform.createDocument();
    marshaller.marshal(oxProject, oxProjectDoc);
    Document oxProjectXMLDoc = xmlParser.parse(new StringReader(OBJECTTYPE_OX_PROJECT));
    assertTrue("OracleObjecttype java-built OX project not same as XML-built OX project.  Expected:\n" + documentToString(oxProjectXMLDoc) + "\nActual:\n" + documentToString(oxProjectDoc), comparer.isNodeEqual(oxProjectXMLDoc, oxProjectDoc));
    XRServiceFactory factory = new XRServiceFactory() {

        XRServiceFactory init() {
            parentClassLoader = ClassLoader.getSystemClassLoader();
            xrSchemaStream = new ByteArrayInputStream(OBJECTTYPE_SCHEMA.getBytes());
            return this;
        }

        @Override
        public void buildSessions() {
            Project orProject = XMLProjectReader.read(new StringReader(OBJECTTYPE_OR_PROJECT), parentClassLoader);
            DatabaseLogin login = new DatabaseLogin();
            login.setUserName(username);
            login.setPassword(password);
            login.setConnectionString(url);
            login.setDriverClassName(driver);
            login.setDatasourcePlatform(new Oracle11Platform());
            login.bindAllParameters();
            orProject.setDatasourceLogin(login);
            DatabaseSession ds = orProject.createDatabaseSession();
            ds.dontLogMessages();
            xrService.setORSession(ds);
            Project oxProject = XMLProjectReader.read(new StringReader(OBJECTTYPE_OX_PROJECT), parentClassLoader);
            xrService.setXMLContext(new XMLContext(oxProject));
            xrService.setOXSession(xrService.getXMLContext().getSession(0));
        }
    }.init();
    context = new XMLContext(new DBWSModelProject());
    XMLUnmarshaller unmarshaller = context.createUnmarshaller();
    DBWSModel model = (DBWSModel) unmarshaller.unmarshal(new StringReader(OBJECTTYPE_XRMODEL));
    xrService = factory.buildService(model);
    if (ddlCreate) {
        try {
            AllTests.runDdl(CREATE_DDL, ddlDebug);
        } catch (Exception e) {
        // e.printStackTrace();
        }
    }
}
Also used : TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) Oracle11Platform(org.eclipse.persistence.platform.database.oracle.Oracle11Platform) Document(org.w3c.dom.Document) StructureMapping(org.eclipse.persistence.mappings.structures.StructureMapping) Field(java.lang.reflect.Field) XMLField(org.eclipse.persistence.oxm.XMLField) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) StringReader(java.io.StringReader) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor) DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) XMLField(org.eclipse.persistence.oxm.XMLField) DOMPlatform(org.eclipse.persistence.oxm.platform.DOMPlatform) DBWSModel(org.eclipse.persistence.dbws.DBWSModel) StoredProcedureCall(org.eclipse.persistence.queries.StoredProcedureCall) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLSchemaURLReference(org.eclipse.persistence.oxm.schema.XMLSchemaURLReference) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) ConstantTransformer(org.eclipse.persistence.mappings.transformers.ConstantTransformer) SQLException(java.sql.SQLException) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) 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) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) BeforeClass(org.junit.BeforeClass)

Example 4 with TransformerBasedFieldTransformation

use of org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation in project eclipselink by eclipse-ee4j.

the class AbstractTransformationMapping method addFieldTransformerClassName.

/**
 * INTERNAL:
 * Add the name of a field and the name of a class which implements
 * the FieldTransformer interface. When the object is written, the transform
 * method will be called on the FieldTransformer to acquire the value to put
 * in the field.
 */
public void addFieldTransformerClassName(DatabaseField field, String className) {
    TransformerBasedFieldTransformation transformation = new TransformerBasedFieldTransformation();
    transformation.setField(field);
    transformation.setTransformerClassName(className);
    getFieldTransformations().add(transformation);
}
Also used : TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation)

Example 5 with TransformerBasedFieldTransformation

use of org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation in project eclipselink by eclipse-ee4j.

the class ProjectClassGenerator method addTransformationMappingLines.

protected void addTransformationMappingLines(NonreflectiveMethodDefinition method, String mappingName, TransformationMapping mapping) {
    if (!mapping.isWriteOnly()) {
        if (mapping.getAttributeMethodName() != null) {
            method.addLine(mappingName + ".setAttributeTransformation(\"" + mapping.getAttributeMethodName() + "\");");
        } else {
            method.addLine(mappingName + ".setAttributeTransformer(new " + mapping.getAttributeTransformerClassName() + "());");
        }
    }
    Iterator<FieldTransformation> fieldTransformations = mapping.getFieldTransformations().iterator();
    while (fieldTransformations.hasNext()) {
        FieldTransformation trans = fieldTransformations.next();
        String fieldName = trans.getFieldName();
        if (trans instanceof MethodBasedFieldTransformation) {
            String methodName = ((MethodBasedFieldTransformation) trans).getMethodName();
            method.addLine(mappingName + ".addFieldTransformation(\"" + fieldName + "\", \"" + methodName + "\");");
        } else {
            String transformerClass = ((TransformerBasedFieldTransformation) trans).getTransformerClassName();
            method.addLine(mappingName + ".addFieldTransformer(\"" + fieldName + "\", new " + transformerClass + "());");
        }
    }
    IndirectionPolicy policy = mapping.getIndirectionPolicy();
    if (policy instanceof ContainerIndirectionPolicy) {
        String containerClassName = ((ContainerIndirectionPolicy) policy).getContainerClassName();
        method.addLine(mappingName + ".useContainerIndirection(" + containerClassName + ".class);");
    } else if (policy instanceof BasicIndirectionPolicy) {
        method.addLine(mappingName + ".useBasicIndirection();");
    }
    method.addLine(mappingName + ".setIsMutable(" + mapping.isMutable() + ");");
}
Also used : TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation) ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) ProxyIndirectionPolicy(org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy) ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) InMemoryQueryIndirectionPolicy(org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy) IndirectionPolicy(org.eclipse.persistence.internal.indirection.IndirectionPolicy) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) FieldTransformation(org.eclipse.persistence.internal.descriptors.FieldTransformation) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation)

Aggregations

TransformerBasedFieldTransformation (org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation)11 Field (java.lang.reflect.Field)5 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)5 ConstantTransformer (org.eclipse.persistence.mappings.transformers.ConstantTransformer)5 XMLTransformationMapping (org.eclipse.persistence.oxm.mappings.XMLTransformationMapping)5 Project (org.eclipse.persistence.sessions.Project)5 FieldTransformation (org.eclipse.persistence.internal.descriptors.FieldTransformation)4 MethodBasedFieldTransformation (org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation)4 StringReader (java.io.StringReader)2 PrivilegedActionException (java.security.PrivilegedActionException)2 SQLException (java.sql.SQLException)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 XMLContext (org.eclipse.persistence.oxm.XMLContext)2 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)2 BeforeClass (org.junit.BeforeClass)2 Document (org.w3c.dom.Document)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Statement (java.sql.Statement)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1