|
| 1 | +/* |
| 2 | + * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License v. 2.0 which is available at |
| 6 | + * http://www.eclipse.org/legal/epl-2.0, |
| 7 | + * or the Eclipse Distribution License v. 1.0 which is available at |
| 8 | + * http://www.eclipse.org/org/documents/edl-v10.php. |
| 9 | + * |
| 10 | + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause |
| 11 | + */ |
| 12 | +package org.eclipse.persistence.testing.models.aggregate; |
| 13 | + |
| 14 | +import org.eclipse.persistence.descriptors.ChangedFieldsLockingPolicy; |
| 15 | +import org.eclipse.persistence.descriptors.ClassDescriptor; |
| 16 | +import org.eclipse.persistence.descriptors.RelationalDescriptor; |
| 17 | +import org.eclipse.persistence.mappings.AggregateObjectMapping; |
| 18 | +import org.eclipse.persistence.mappings.DirectToFieldMapping; |
| 19 | + |
| 20 | +public class SimpleAggregateProject extends org.eclipse.persistence.sessions.Project { |
| 21 | + |
| 22 | + public SimpleAggregateProject() { |
| 23 | + applyPROJECT(); |
| 24 | + applyLOGIN(); |
| 25 | + |
| 26 | + addDescriptor(buildSimpleAggregateClassDescriptor()); |
| 27 | + addDescriptor(buildSimpleEntityDescriptor()); |
| 28 | + } |
| 29 | + |
| 30 | + protected void applyLOGIN() { |
| 31 | + } |
| 32 | + |
| 33 | + protected void applyPROJECT() { |
| 34 | + setName("SimpleAggregateSystem"); |
| 35 | + } |
| 36 | + |
| 37 | + public ClassDescriptor buildSimpleAggregateClassDescriptor() { |
| 38 | + RelationalDescriptor descriptor = new RelationalDescriptor(); |
| 39 | + descriptor.descriptorIsAggregate(); |
| 40 | + descriptor.setJavaClass(SimpleAggregate.class); |
| 41 | + |
| 42 | + // ClassDescriptor Properties. |
| 43 | + descriptor.setAlias("SimpleAggregate"); |
| 44 | + |
| 45 | + |
| 46 | + // Query Manager. |
| 47 | + |
| 48 | + |
| 49 | + // Event Manager. |
| 50 | + |
| 51 | + // Mappings. |
| 52 | + DirectToFieldMapping contentMapping = new DirectToFieldMapping(); |
| 53 | + contentMapping.setAttributeName("content"); |
| 54 | + contentMapping.setFieldName("content->DIRECT"); |
| 55 | + descriptor.addMapping(contentMapping); |
| 56 | + |
| 57 | + return descriptor; |
| 58 | + } |
| 59 | + |
| 60 | + protected ClassDescriptor buildSimpleEntityDescriptor() { |
| 61 | + RelationalDescriptor descriptor = new RelationalDescriptor(); |
| 62 | + //descriptor.setCacheable(false); |
| 63 | + |
| 64 | + // SECTION: DESCRIPTOR |
| 65 | + descriptor.setJavaClass(SimpleEntity.class); |
| 66 | + descriptor.addTableName("SIMPLEENTITY"); |
| 67 | + descriptor.addPrimaryKeyFieldName("SIMPLEENTITY.ID"); |
| 68 | + |
| 69 | + ChangedFieldsLockingPolicy lockingPolicy = new ChangedFieldsLockingPolicy(); |
| 70 | + descriptor.setOptimisticLockingPolicy(lockingPolicy); |
| 71 | + |
| 72 | + // SECTION: DIRECTTOFIELDMAPPING |
| 73 | + DirectToFieldMapping directtofieldmapping = new DirectToFieldMapping(); |
| 74 | + directtofieldmapping.setAttributeName("id"); |
| 75 | + directtofieldmapping.setIsReadOnly(false); |
| 76 | + directtofieldmapping.setFieldName("SIMPLEENTITY.ID"); |
| 77 | + descriptor.addMapping(directtofieldmapping); |
| 78 | + |
| 79 | + DirectToFieldMapping fieldmapping = new DirectToFieldMapping(); |
| 80 | + fieldmapping.setAttributeName("field"); |
| 81 | + fieldmapping.setIsReadOnly(false); |
| 82 | + fieldmapping.setFieldName("SIMPLEENTITY.FIELD"); |
| 83 | + descriptor.addMapping(fieldmapping); |
| 84 | + |
| 85 | + AggregateObjectMapping aggregateObjectMapping = new AggregateObjectMapping(); |
| 86 | + aggregateObjectMapping.setAttributeName("simpleAggregate"); |
| 87 | + aggregateObjectMapping.setReferenceClass(SimpleAggregate.class); |
| 88 | + aggregateObjectMapping.setIsNullAllowed(true); |
| 89 | + aggregateObjectMapping.addFieldNameTranslation("SIMPLEENTITY.CONTENT", "content->DIRECT"); |
| 90 | + descriptor.addMapping(aggregateObjectMapping); |
| 91 | + |
| 92 | + return descriptor; |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments