Search in sources :

Example 1 with SerializedObjectConverter

use of org.eclipse.persistence.mappings.converters.SerializedObjectConverter in project eclipselink by eclipse-ee4j.

the class KryoMetadata method process.

/**
 * INTERNAL:
 * Every converter needs to be able to process themselves.
 */
@Override
public void process(DatabaseMapping mapping, MappingAccessor accessor, MetadataClass referenceClass, boolean isForMapKey) {
    SerializedObjectConverter converter = new SerializedObjectConverter(mapping, "org.eclipse.persistence.sessions.serializers.kryo.KryoSerializer");
    setConverter(mapping, converter, isForMapKey);
}
Also used : SerializedObjectConverter(org.eclipse.persistence.mappings.converters.SerializedObjectConverter)

Example 2 with SerializedObjectConverter

use of org.eclipse.persistence.mappings.converters.SerializedObjectConverter in project eclipselink by eclipse-ee4j.

the class SerializedConverterMetadata method process.

/**
 * INTERNAL:
 * Process this converter for the given mapping.
 */
@Override
public void process(DatabaseMapping mapping, MappingAccessor accessor, MetadataClass referenceClass, boolean isForMapKey) {
    SerializedObjectConverter converter = null;
    if ((m_className == null) || (m_className.length() == 0)) {
        converter = new SerializedObjectConverter(mapping);
    } else {
        converter = new SerializedObjectConverter(mapping, getClassName());
    }
    if ((m_serializerPackage != null) && (m_serializerPackage.length() > 0)) {
        converter.setSerializerPackage(m_serializerPackage);
    } else {
        // Default package to target classes package.
        converter.setSerializerPackage(referenceClass.getName().substring(0, referenceClass.getName().lastIndexOf('.')));
    }
    setConverter(mapping, converter, isForMapKey);
}
Also used : SerializedObjectConverter(org.eclipse.persistence.mappings.converters.SerializedObjectConverter)

Example 3 with SerializedObjectConverter

use of org.eclipse.persistence.mappings.converters.SerializedObjectConverter in project eclipselink by eclipse-ee4j.

the class ConverterTestSuite method testAutoApplyConverter.

/**
 * Test that an attribute picks up an auto apply converter.
 */
public void testAutoApplyConverter() {
    ServerSession session = getPersistenceUnitServerSession();
    ClassDescriptor employeeDescriptor = session.getDescriptor(Employee.class);
    DirectToFieldMapping salaryMapping = (DirectToFieldMapping) employeeDescriptor.getMappingForAttributeName("salary");
    assertNotNull("Salary mapping did not have the auto apply converter", salaryMapping.getConverter());
    DirectToFieldMapping previousSalaryMapping = (DirectToFieldMapping) employeeDescriptor.getMappingForAttributeName("previousSalary");
    assertNull("Salary mapping did not have the auto apply converter", previousSalaryMapping.getConverter());
    ClassDescriptor runnerDescriptor = session.getDescriptor(Runner.class);
    DirectToFieldMapping tagsMapping = (DirectToFieldMapping) runnerDescriptor.getMappingForAttributeName("tags");
    assertTrue("Tags mapping did not have a converter", tagsMapping.hasConverter());
    assertTrue("Serials mappings did not have a SerializedObjectConverter", tagsMapping.getConverter() instanceof ConverterClass);
    DirectToFieldMapping serialsMapping = (DirectToFieldMapping) runnerDescriptor.getMappingForAttributeName("serials");
    assertTrue("Serials mapping did not have a converter", serialsMapping.hasConverter());
    assertTrue("Serials mappings did not have a SerializedObjectConverter", serialsMapping.getConverter() instanceof SerializedObjectConverter);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) SerializedObjectConverter(org.eclipse.persistence.mappings.converters.SerializedObjectConverter) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ConverterClass(org.eclipse.persistence.mappings.converters.ConverterClass)

Example 4 with SerializedObjectConverter

use of org.eclipse.persistence.mappings.converters.SerializedObjectConverter in project eclipselink by eclipse-ee4j.

the class ConverterTestSuite method testAutoApplyConverter.

/**
 * Test that an attribute picks up an auto apply converter.
 */
public void testAutoApplyConverter() {
    ServerSession session = getPersistenceUnitServerSession();
    ClassDescriptor employeeDescriptor = session.getDescriptor(Employee.class);
    DirectToFieldMapping salaryMapping = (DirectToFieldMapping) employeeDescriptor.getMappingForAttributeName("salary");
    assertNotNull("Salary mapping did not have the auto apply converter", salaryMapping.getConverter());
    DirectToFieldMapping previousSalaryMapping = (DirectToFieldMapping) employeeDescriptor.getMappingForAttributeName("previousSalary");
    assertNull("Salary mapping did not have the auto apply converter", previousSalaryMapping.getConverter());
    ClassDescriptor runnerDescriptor = session.getDescriptor(Runner.class);
    DirectToFieldMapping tagsMapping = (DirectToFieldMapping) runnerDescriptor.getMappingForAttributeName("tags");
    assertTrue("Tags mapping did not have a converter", tagsMapping.hasConverter());
    assertTrue("Serials mappings did not have a SerializedObjectConverter", tagsMapping.getConverter() instanceof ConverterClass);
    DirectToFieldMapping serialsMapping = (DirectToFieldMapping) runnerDescriptor.getMappingForAttributeName("serials");
    assertTrue("Serials mapping did not have a converter", serialsMapping.hasConverter());
    assertTrue("Serials mappings did not have a SerializedObjectConverter", serialsMapping.getConverter() instanceof SerializedObjectConverter);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) SerializedObjectConverter(org.eclipse.persistence.mappings.converters.SerializedObjectConverter) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ConverterClass(org.eclipse.persistence.mappings.converters.ConverterClass)

Example 5 with SerializedObjectConverter

use of org.eclipse.persistence.mappings.converters.SerializedObjectConverter in project eclipselink by eclipse-ee4j.

the class MappingProject method buildEmployeeDescriptor.

protected void buildEmployeeDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(Employee.class);
    Vector vector = new Vector();
    vector.addElement("MAP_EMP");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("MAP_EMP.FNAME");
    descriptor.addPrimaryKeyFieldName("MAP_EMP.LNAME");
    descriptor.addPrimaryKeyFieldName("MAP_EMP.SEX");
    // SECTION: COPY POLICY
    descriptor.createCopyPolicy("constructor");
    descriptor.useSoftIdentityMap();
    // SECTION: INSTANTIATION POLICY
    descriptor.createInstantiationPolicy("constructor");
    // SECTION: DIRECTCOLLECTIONMAPPING
    DirectCollectionMapping directcollectionmapping = new DirectCollectionMapping();
    directcollectionmapping.setAttributeName("policies");
    directcollectionmapping.setIsReadOnly(false);
    directcollectionmapping.setUsesIndirection(true);
    directcollectionmapping.setIsPrivateOwned(false);
    directcollectionmapping.setDirectFieldName("MAP_POL.POLICY");
    directcollectionmapping.setReferenceTableName("MAP_POL");
    directcollectionmapping.addReferenceKeyFieldName("MAP_POL.LNAME", "MAP_EMP.LNAME");
    directcollectionmapping.addReferenceKeyFieldName("MAP_POL.FNAME", "MAP_EMP.FNAME");
    descriptor.addMapping(directcollectionmapping);
    // SECTION: DIRECTTOFIELDMAPPING
    DirectToFieldMapping directtofieldmapping = new DirectToFieldMapping();
    directtofieldmapping.setAttributeName("firstName");
    directtofieldmapping.setIsReadOnly(false);
    directtofieldmapping.setFieldName("MAP_EMP.FNAME");
    descriptor.addMapping(directtofieldmapping);
    // SECTION: DIRECTTOFIELDMAPPING
    DirectToFieldMapping directtofieldmapping1 = new DirectToFieldMapping();
    directtofieldmapping1.setAttributeName("lastName");
    directtofieldmapping1.setIsReadOnly(false);
    directtofieldmapping1.setFieldName("MAP_EMP.LNAME");
    descriptor.addMapping(directtofieldmapping1);
    // SECTION: ONETOONEMAPPING
    OneToOneMapping onetoonemapping1 = new OneToOneMapping();
    onetoonemapping1.setAttributeName("cubicle");
    onetoonemapping1.setIsReadOnly(false);
    onetoonemapping1.setUsesIndirection(false);
    onetoonemapping1.setReferenceClass(Cubicle.class);
    onetoonemapping1.setIsPrivateOwned(true);
    onetoonemapping1.addForeignKeyFieldName("MAP_EMP.C_ID", "MAP_CUB.C_ID");
    descriptor.addMapping(onetoonemapping1);
    // SECTION: MANYTOMANYMAPPING
    ManyToManyMapping manytomanymapping = new ManyToManyMapping();
    manytomanymapping.setAttributeName("phoneNumbers");
    manytomanymapping.setIsReadOnly(false);
    manytomanymapping.setUsesIndirection(true);
    manytomanymapping.setReferenceClass(Phone.class);
    manytomanymapping.setIsPrivateOwned(true);
    manytomanymapping.setRelationTableName("MAP_EMPH");
    manytomanymapping.addSourceRelationKeyFieldName("MAP_EMPH.LNAME", "MAP_EMP.LNAME");
    manytomanymapping.addSourceRelationKeyFieldName("MAP_EMPH.FNAME", "MAP_EMP.FNAME");
    manytomanymapping.addTargetRelationKeyFieldName("MAP_EMPH.P_ID", "MAP_PHO.P_ID");
    descriptor.addMapping(manytomanymapping);
    // SECTION: MANYTOMANYMAPPING
    ManyToManyMapping manytomanymapping1 = new ManyToManyMapping();
    manytomanymapping1.setAttributeName("shipments");
    manytomanymapping1.setIsReadOnly(false);
    manytomanymapping1.setUsesIndirection(false);
    manytomanymapping1.setReferenceClass(Shipment.class);
    manytomanymapping1.setIsPrivateOwned(false);
    manytomanymapping1.setRelationTableName("MAP_EMSP");
    manytomanymapping1.addSourceRelationKeyFieldName("MAP_EMSP.EMP_LNAME", "MAP_EMP.LNAME");
    manytomanymapping1.addSourceRelationKeyFieldName("MAP_EMSP.EMP_FNAME", "MAP_EMP.FNAME");
    manytomanymapping1.addTargetRelationKeyFieldName("MAP_EMSP.SP_TSMIL", "MAP_SHIP.SP_TSMIL");
    manytomanymapping1.addTargetRelationKeyFieldName("MAP_EMSP.SP_TS", "MAP_SHIP.SP_TS");
    descriptor.addMapping(manytomanymapping1);
    // SECTION: OBJECTTYPEMAPPING
    DirectToFieldMapping objecttypemapping = new DirectToFieldMapping();
    ObjectTypeConverter objecttypeconverter = new ObjectTypeConverter();
    objecttypemapping.setAttributeName("sex");
    objecttypemapping.setIsReadOnly(false);
    objecttypemapping.setFieldName("MAP_EMP.SEX");
    objecttypeconverter.setDefaultAttributeValue("female");
    objecttypeconverter.addConversionValue("F", "female");
    objecttypeconverter.addConversionValue("M", "male");
    objecttypemapping.setConverter(objecttypeconverter);
    descriptor.addMapping(objecttypemapping);
    // SECTION: ONETOMANYMAPPING
    OneToManyMapping onetomanymapping = new OneToManyMapping();
    onetomanymapping.setAttributeName("managedEmployees");
    onetomanymapping.setIsReadOnly(false);
    onetomanymapping.setUsesIndirection(false);
    onetomanymapping.setGetMethodName("getManagedEmployeesForTOPLink");
    onetomanymapping.setSetMethodName("setManagedEmployeesFromTOPLink");
    onetomanymapping.setReferenceClass(Employee.class);
    onetomanymapping.setIsPrivateOwned(false);
    onetomanymapping.addTargetForeignKeyFieldName("MAP_EMP.M_LNAME", "MAP_EMP.LNAME");
    onetomanymapping.addTargetForeignKeyFieldName("MAP_EMP.M_FNAME", "MAP_EMP.FNAME");
    descriptor.addMapping(onetomanymapping);
    // SECTION: ONETOONEMAPPING
    OneToOneMapping onetoonemapping = new OneToOneMapping();
    onetoonemapping.setAttributeName("computer");
    onetoonemapping.setIsReadOnly(false);
    onetoonemapping.setUsesIndirection(false);
    onetoonemapping.setGetMethodName("getComputer");
    onetoonemapping.setSetMethodName("setComputer");
    onetoonemapping.setReferenceClass(Hardware.class);
    onetoonemapping.setIsPrivateOwned(true);
    onetoonemapping.addTargetForeignKeyFieldName("MAP_HRW.EMP_FNAME", "MAP_EMP.FNAME");
    onetoonemapping.addTargetForeignKeyFieldName("MAP_HRW.EMP_LNAME", "MAP_EMP.LNAME");
    descriptor.addMapping(onetoonemapping);
    // SECTION: ONETOONEMAPPING
    OneToOneMapping onetoonemapping2 = new OneToOneMapping();
    onetoonemapping2.setAttributeName("manager");
    onetoonemapping2.setIsReadOnly(false);
    onetoonemapping2.setUsesIndirection(false);
    onetoonemapping2.setGetMethodName("getManager");
    onetoonemapping2.setSetMethodName("setManager");
    onetoonemapping2.setReferenceClass(Employee.class);
    onetoonemapping2.setIsPrivateOwned(false);
    onetoonemapping2.addForeignKeyFieldName("MAP_EMP.M_FNAME", "MAP_EMP.FNAME");
    onetoonemapping2.addForeignKeyFieldName("MAP_EMP.M_LNAME", "MAP_EMP.LNAME");
    descriptor.addMapping(onetoonemapping2);
    // SECTION: SERIALIZEDMAPPING
    DirectToFieldMapping serializedmapping = new DirectToFieldMapping();
    SerializedObjectConverter serializedconverter = new SerializedObjectConverter();
    serializedmapping.setAttributeName("jobDescription");
    serializedmapping.setIsReadOnly(false);
    serializedmapping.setGetMethodName("getJobDescription");
    serializedmapping.setSetMethodName("setJobDescription");
    serializedmapping.setFieldName("MAP_EMP.JDESC");
    serializedmapping.setConverter(serializedconverter);
    descriptor.addMapping(serializedmapping);
    // SECTION: TRANSFORMATIONMAPPING
    TransformationMapping transformationmapping = new TransformationMapping();
    transformationmapping.setAttributeName("dateAndTimeOfBirth");
    transformationmapping.setIsReadOnly(false);
    transformationmapping.setUsesIndirection(false);
    transformationmapping.setAttributeTransformation("setDateAndTime");
    transformationmapping.addFieldTransformation("MAP_EMP.BDAY", "getDate");
    transformationmapping.addFieldTransformation("MAP_EMP.BTIME", "getTime");
    descriptor.addMapping(transformationmapping);
    // SECTION: TRANSFORMATIONMAPPING
    TransformationMapping transformationmapping1 = new TransformationMapping();
    transformationmapping1.setAttributeName("designation");
    transformationmapping1.setIsReadOnly(false);
    transformationmapping1.setUsesIndirection(true);
    transformationmapping1.setGetMethodName("getDesignation");
    transformationmapping1.setSetMethodName("setDesignation");
    transformationmapping1.setAttributeTransformation("getRankFromRow");
    transformationmapping1.addFieldTransformation("MAP_EMP.ERANK", "getRankFromObject");
    descriptor.addMapping(transformationmapping1);
    // SECTION: TYPECONVERSIONMAPPING
    DirectToFieldMapping typeconversionmapping = new DirectToFieldMapping();
    TypeConversionConverter typeconversionconverter = new TypeConversionConverter();
    typeconversionmapping.setAttributeName("joiningDate");
    typeconversionmapping.setIsReadOnly(false);
    typeconversionmapping.setFieldName("MAP_EMP.JDAY");
    typeconversionconverter.setObjectClass(java.util.Date.class);
    typeconversionconverter.setDataClass(java.sql.Date.class);
    typeconversionmapping.setConverter(typeconversionconverter);
    descriptor.addMapping(typeconversionmapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter) SerializedObjectConverter(org.eclipse.persistence.mappings.converters.SerializedObjectConverter) TransformationMapping(org.eclipse.persistence.mappings.TransformationMapping) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) DirectCollectionMapping(org.eclipse.persistence.mappings.DirectCollectionMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter) Vector(java.util.Vector) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Aggregations

SerializedObjectConverter (org.eclipse.persistence.mappings.converters.SerializedObjectConverter)7 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)4 TypeConversionConverter (org.eclipse.persistence.mappings.converters.TypeConversionConverter)3 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)2 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)2 ConverterClass (org.eclipse.persistence.mappings.converters.ConverterClass)2 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)2 Vector (java.util.Vector)1 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)1 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)1 RelationTableMechanism (org.eclipse.persistence.mappings.RelationTableMechanism)1 TransformationMapping (org.eclipse.persistence.mappings.TransformationMapping)1 Converter (org.eclipse.persistence.mappings.converters.Converter)1 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)1