|
| 1 | +package org.eclipse.persistence.testing.models.aggregate; |
| 2 | + |
| 3 | +import org.eclipse.persistence.descriptors.ChangedFieldsLockingPolicy; |
| 4 | +import org.eclipse.persistence.descriptors.ClassDescriptor; |
| 5 | +import org.eclipse.persistence.descriptors.RelationalDescriptor; |
| 6 | +import org.eclipse.persistence.mappings.AggregateObjectMapping; |
| 7 | +import org.eclipse.persistence.mappings.DirectToFieldMapping; |
| 8 | + |
| 9 | +public class SimpleAggregateProject extends org.eclipse.persistence.sessions.Project { |
| 10 | + |
| 11 | + public SimpleAggregateProject() { |
| 12 | + applyPROJECT(); |
| 13 | + applyLOGIN(); |
| 14 | + |
| 15 | + addDescriptor(buildSimpleAggregateClassDescriptor()); |
| 16 | + addDescriptor(buildSimpleEntityDescriptor()); |
| 17 | + } |
| 18 | + |
| 19 | + protected void applyLOGIN() { |
| 20 | + } |
| 21 | + |
| 22 | + protected void applyPROJECT() { |
| 23 | + setName("SimpleAggregateSystem"); |
| 24 | + } |
| 25 | + |
| 26 | + public ClassDescriptor buildSimpleAggregateClassDescriptor() { |
| 27 | + RelationalDescriptor descriptor = new RelationalDescriptor(); |
| 28 | + descriptor.descriptorIsAggregate(); |
| 29 | + descriptor.setJavaClass(SimpleAggregate.class); |
| 30 | + |
| 31 | + // ClassDescriptor Properties. |
| 32 | + descriptor.setAlias("SimpleAggregate"); |
| 33 | + |
| 34 | + |
| 35 | + // Query Manager. |
| 36 | + |
| 37 | + |
| 38 | + // Event Manager. |
| 39 | + |
| 40 | + // Mappings. |
| 41 | + DirectToFieldMapping contentMapping = new DirectToFieldMapping(); |
| 42 | + contentMapping.setAttributeName("content"); |
| 43 | + contentMapping.setFieldName("content->DIRECT"); |
| 44 | + descriptor.addMapping(contentMapping); |
| 45 | + |
| 46 | + return descriptor; |
| 47 | + } |
| 48 | + |
| 49 | + protected ClassDescriptor buildSimpleEntityDescriptor() { |
| 50 | + RelationalDescriptor descriptor = new RelationalDescriptor(); |
| 51 | + //descriptor.setCacheable(false); |
| 52 | + |
| 53 | + // SECTION: DESCRIPTOR |
| 54 | + descriptor.setJavaClass(SimpleEntity.class); |
| 55 | + descriptor.addTableName("SIMPLEENTITY"); |
| 56 | + descriptor.addPrimaryKeyFieldName("SIMPLEENTITY.ID"); |
| 57 | + |
| 58 | + ChangedFieldsLockingPolicy lockingPolicy = new ChangedFieldsLockingPolicy(); |
| 59 | + descriptor.setOptimisticLockingPolicy(lockingPolicy); |
| 60 | + |
| 61 | + // SECTION: DIRECTTOFIELDMAPPING |
| 62 | + DirectToFieldMapping directtofieldmapping = new DirectToFieldMapping(); |
| 63 | + directtofieldmapping.setAttributeName("id"); |
| 64 | + directtofieldmapping.setIsReadOnly(false); |
| 65 | + directtofieldmapping.setFieldName("SIMPLEENTITY.ID"); |
| 66 | + descriptor.addMapping(directtofieldmapping); |
| 67 | + |
| 68 | + DirectToFieldMapping fieldmapping = new DirectToFieldMapping(); |
| 69 | + fieldmapping.setAttributeName("field"); |
| 70 | + fieldmapping.setIsReadOnly(false); |
| 71 | + fieldmapping.setFieldName("SIMPLEENTITY.FIELD"); |
| 72 | + descriptor.addMapping(fieldmapping); |
| 73 | + |
| 74 | + AggregateObjectMapping aggregateObjectMapping = new AggregateObjectMapping(); |
| 75 | + aggregateObjectMapping.setAttributeName("simpleAggregate"); |
| 76 | + aggregateObjectMapping.setReferenceClass(SimpleAggregate.class); |
| 77 | + aggregateObjectMapping.setIsNullAllowed(true); |
| 78 | + aggregateObjectMapping.addFieldNameTranslation("SIMPLEENTITY.CONTENT", "content->DIRECT"); |
| 79 | + descriptor.addMapping(aggregateObjectMapping); |
| 80 | + |
| 81 | + return descriptor; |
| 82 | + } |
| 83 | + |
| 84 | +} |
0 commit comments