Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2011-02-06 02:33:04 +0000
committerkmoore2011-02-06 02:33:04 +0000
commitda90c110eaa10e7f631b6baac3055ccb4d2df73b (patch)
tree81a624622d1a781eb08c8b7c0b69461fb6fa8679 /jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt
parent364d3d58c1576b4718e65b969d1422b6ff1fb4aa (diff)
downloadwebtools.dali-da90c110eaa10e7f631b6baac3055ccb4d2df73b.tar.gz
webtools.dali-da90c110eaa10e7f631b6baac3055ccb4d2df73b.tar.xz
webtools.dali-da90c110eaa10e7f631b6baac3055ccb4d2df73b.zip
renamed org.eclipse.jpt.core.tests to org.eclipse.jpt.jpa.core.tests
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt')
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java61
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/MiscTests.java65
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/JptJpaCoreTests.java74
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/ContextModelTestCase.java221
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaFileTests.java411
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaProjectTests.java172
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JptJpaCoreContextModelTests.java52
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java236
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java759
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaAssociationOverrideTests.java446
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaAttributeOverrideTests.java260
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaBasicMappingTests.java995
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaCascadeTests.java321
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaColumnTests.java843
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java458
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddableTests.java171
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java659
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddedMappingTests.java863
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEntityTests.java3417
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaGeneratedValueTests.java150
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaIdMappingTests.java715
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaJoinColumnTests.java549
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaJoinTableTests.java1177
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaManyToManyMappingTests.java1180
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaManyToOneMappingTests.java960
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaMappedSuperclassTests.java288
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaNamedNativeQueryTests.java432
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaNamedQueryTests.java333
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaOneToManyMappingTests.java1160
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaOneToOneMappingTests.java1511
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java303
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaQueryHintTests.java145
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaSecondaryTableTests.java730
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaSequenceGeneratorTests.java235
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaTableGeneratorTests.java671
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaTableTests.java610
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaTransientMappingTests.java249
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaVersionMappingTests.java400
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JptCoreContextJavaModelTests.java59
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/EntityMappingsTests.java1066
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/GenericOrmPersistentAttributeTests.java314
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/GenericOrmPersistentTypeTests.java574
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/JptCoreOrmContextModelTests.java62
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmAssociationOverrideTests.java267
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmAttributeOverrideTests.java99
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmBasicMappingTests.java711
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmCascadeTests.java280
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmColumnTests.java835
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmDiscriminatorColumnTests.java456
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmEmbeddableTests.java295
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmEmbeddedIdMappingTests.java923
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmEmbeddedMappingTests.java943
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmEntityTests.java2790
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmGeneratedValueTests.java136
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmIdMappingTests.java746
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmJoinColumnTests.java506
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmJoinTableTests.java1365
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmManyToManyMappingTests.java1065
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmManyToOneMappingTests.java618
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmMappedSuperclassTests.java386
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmNamedNativeQueryTests.java358
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmNamedQueryTests.java273
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmOneToManyMappingTests.java1058
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmOneToOneMappingTests.java1196
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmPrimaryKeyJoinColumnTests.java253
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmQueryHintTests.java122
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmSecondaryTableTests.java767
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmSequenceGeneratorTests.java172
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmTableGeneratorTests.java604
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmTableTests.java827
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmTransientMappingTests.java305
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmVersionMappingTests.java489
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmXmlTests.java69
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/PersistenceUnitDefaultsTests.java369
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/PersistenceUnitMetadataTests.java104
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/ClassRefTests.java113
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/JptCorePersistenceContextModelTests.java33
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/MappingFileRefTests.java98
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/PersistenceTests.java134
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/PersistenceUnitTestCase.java361
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/PersistenceUnitTests.java1247
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/PersistenceXmlTests.java56
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/RootContextNodeTests.java53
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/Generic2_0ContextModelTestCase.java35
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/Generic2_0JavaContextModelTests.java41
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaAssociationOverride2_0Tests.java580
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaCascade2_0Tests.java106
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaCollectionTable2_0Tests.java722
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java2077
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaEmbeddedMapping2_0Tests.java1550
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaEntity2_0Tests.java2069
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java1218
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaManyToOneMapping2_0Tests.java419
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java1526
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaOneToOneMapping2_0Tests.java884
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0Tests.java162
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaPersistentType2_0Tests.java853
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/java/GenericJavaSequenceGenerator2_0Tests.java200
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/Generic2_0OrmContextModelTests.java41
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmAssociationOverride2_0Tests.java534
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmCascade2_0Tests.java89
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmCollectionTable2_0Tests.java753
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java1459
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmEmbeddedMapping2_0Tests.java1734
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmEntity2_0Tests.java1972
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java939
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java674
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java1230
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java991
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0Tests.java550
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmPersistentType2_0Tests.java283
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/orm/GenericOrmSequenceGenerator2_0Tests.java91
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0ConnectionTests.java186
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java520
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceContextModelTests.java30
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceUnitTests.java58
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/Access2_0AnnotationTests.java175
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/AssociationOverride2_0Tests.java885
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/AssociationOverrides2_0Tests.java988
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/Cacheable2_0AnnotationTests.java106
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/CollectionTable2_0AnnotationTests.java498
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java169
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/JavaResource2_0Tests.java48
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/JavaResourceModel2_0TestCase.java29
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ManyToMany2_0AnnotationTests.java409
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ManyToOne2_0AnnotationTests.java402
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java108
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyColumn2_0AnnotationTests.java404
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyEnumerated2_0AnnotationTests.java90
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyJoinColumn2_0AnnotationTests.java352
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyJoinColumns2_0AnnotationTests.java420
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyTemporal2_0AnnotationTests.java89
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapsId2_0AnnotationTests.java86
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/OneToMany2_0AnnotationTests.java412
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/OneToOne2_0AnnotationTests.java462
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/OrderColumn2_0AnnotationTests.java252
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/SequenceGenerator2_0AnnotationTests.java123
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/model/JpaProjectManagerTests.java262
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/model/JptJpaCoreModelTests.java28
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/platform/BaseJpaPlatformTests.java77
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/platform/JpaPlatformExtensionTests.java96
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/platform/JpaPlatformTests.java129
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/projects/TestJpaProject.java128
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/JptJpaCoreResourceModelTests.java42
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/AssociationOverrideTests.java253
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/AssociationOverridesTests.java320
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/AttributeOverrideTests.java157
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/AttributeOverridesTests.java274
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/BasicTests.java151
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/ColumnTests.java404
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/DiscriminatorColumnTests.java212
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/DiscriminatorValueTests.java83
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/EmbeddableTests.java74
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/EmbeddedIdTests.java50
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/EmbeddedTests.java50
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/EntityTests.java125
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/EnumeratedTests.java89
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/GeneratedValueTests.java133
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/IdClassTests.java103
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/IdTests.java50
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/InheritanceTests.java83
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JPTToolsTests.java479
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourceModelTestCase.java164
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java870
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java937
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JoinColumnTests.java352
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JoinColumnsTests.java420
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JoinTableTests.java656
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JpaJavaResourceModelTestCase.java48
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JptJavaResourceTests.java75
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/LobTests.java49
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/ManyToManyTests.java394
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/ManyToOneTests.java387
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/MapKeyTests.java88
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/MappedSuperclassTests.java74
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/NamedNativeQueriesTests.java421
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/NamedNativeQueryTests.java341
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/NamedQueriesTests.java331
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/NamedQueryTests.java259
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/OneToManyTests.java397
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/OneToOneTests.java447
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/OrderByTests.java87
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/PrimaryKeyJoinColumnTests.java187
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/PrimaryKeyJoinColumnsTests.java252
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/QueryHintTests.java65
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/SecondaryTableTests.java436
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/SecondaryTablesTests.java503
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/SequenceGeneratorTests.java234
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/TableGeneratorTests.java501
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/TableTests.java346
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/TemporalTests.java88
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/TransientTests.java50
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/VersionTests.java49
193 files changed, 90282 insertions, 0 deletions
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java
new file mode 100644
index 0000000000..f9168afacd
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.jpt.common.utility.internal.ReflectionTools;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Configure the core for testing:<ul>
+ * <li>handle events synchronously
+ * <li>do not flush preferences
+ * </ul>
+ */
+@SuppressWarnings("nls")
+public class JptJpaCoreTestsPlugin
+ extends Plugin
+{
+
+ private static JptJpaCoreTestsPlugin INSTANCE;
+
+ public static JptJpaCoreTestsPlugin instance() {
+ return INSTANCE;
+ }
+
+
+ // ********** plug-in implementation **********
+
+ public JptJpaCoreTestsPlugin() {
+ super();
+ if (INSTANCE != null) {
+ throw new IllegalStateException();
+ }
+ // this convention is *wack*... ~bjv
+ INSTANCE = this;
+ }
+
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ JpaProjectManager jpaProjectManager = JptJpaCorePlugin.getJpaProjectManager();
+ ReflectionTools.executeMethod(jpaProjectManager, "handleEventsSynchronously");
+ ReflectionTools.executeStaticMethod(JptJpaCorePlugin.class, "doNotFlushPreferences");
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/MiscTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/MiscTests.java
new file mode 100644
index 0000000000..f0ce85043d
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/MiscTests.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.ILock;
+import org.eclipse.core.runtime.jobs.Job;
+
+@SuppressWarnings("nls")
+public class MiscTests extends TestCase {
+
+ public MiscTests(String name) {
+ super(name);
+ }
+
+ /*
+ *
+ */
+ public void testJobsAndLocks() throws Exception {
+ ILock lock = Job.getJobManager().newLock();
+ Job testJob = new TestJob(lock);
+ testJob.schedule();
+ }
+
+ class TestJob extends Job {
+ private final ILock lock;
+ TestJob(ILock lock) {
+ super("test job");
+ this.lock = lock;
+ }
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ this.run();
+ return Status.OK_STATUS;
+ }
+ private void run() {
+ try {
+ this.lock.acquire();
+ MiscTests.sleep(100);
+ } finally {
+ this.lock.release();
+ }
+ }
+ }
+
+ static void sleep(long millis) {
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/JptJpaCoreTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/JptJpaCoreTests.java
new file mode 100644
index 0000000000..c61b1046e9
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/JptJpaCoreTests.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal;
+
+import java.io.File;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.eclipse.jpt.jpa.core.tests.internal.context.JptJpaCoreContextModelTests;
+import org.eclipse.jpt.jpa.core.tests.internal.model.JptJpaCoreModelTests;
+import org.eclipse.jpt.jpa.core.tests.internal.projects.TestJpaProject;
+import org.eclipse.jpt.jpa.core.tests.internal.resource.JptJpaCoreResourceModelTests;
+
+/**
+ * decentralize test creation code
+ *
+ * Required Java system property:
+ * -Dorg.eclipse.jpt.jpa.jar=<jpa.jar path>
+ */
+@SuppressWarnings("nls")
+public class JptJpaCoreTests {
+ private static final String JPA_JAR_PROPERTY = TestJpaProject.JPA_JAR_NAME_SYSTEM_PROPERTY;
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JptJpaCoreTests.class.getPackage().getName());
+ suite.addTest(JptJpaCoreModelTests.suite());
+ suite.addTest(JptJpaCoreResourceModelTests.suite());
+ suite.addTest(JptJpaCoreContextModelTests.suite());
+ return suite;
+ }
+
+ public static boolean requiredJarsExists() {
+ return jpaJarPropertyExists() && jpaJarFileExists();
+ }
+
+ public static boolean jpaJarPropertyExists() {
+ return getSystemProperty(JPA_JAR_PROPERTY) != null;
+ }
+
+ public static boolean jpaJarFileExists() {
+ return (new File(getSystemProperty(JPA_JAR_PROPERTY))).exists();
+ }
+
+ public static String buildMissingJarErrorMessage() {
+ if( ! jpaJarPropertyExists()) {
+ return errorMissingProperty(JPA_JAR_PROPERTY);
+ }
+ return errorJarFileDoesNotExist(getSystemProperty(JPA_JAR_PROPERTY));
+ }
+
+ /*********** private **********/
+ private static String errorMissingProperty(String propertyName) {
+ return "missing Java system property: \"" + propertyName + "\"";
+ }
+
+ private static String errorJarFileDoesNotExist(String propertyValue) {
+ return "JAR file doesn't exist: \"" + propertyValue + "\"";
+ }
+
+ private static String getSystemProperty(String propertyName) {
+ return System.getProperty(propertyName);
+ }
+
+ private JptJpaCoreTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/ContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/ContextModelTestCase.java
new file mode 100644
index 0000000000..1d312fb923
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/ContextModelTestCase.java
@@ -0,0 +1,221 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject;
+import org.eclipse.jpt.common.core.tests.internal.utility.jdt.AnnotationTestCase;
+import org.eclipse.jpt.jpa.core.JpaFacet;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
+import org.eclipse.jpt.jpa.core.context.MappingFile;
+import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetDataModelProperties;
+import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProperties;
+import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProvider;
+import org.eclipse.jpt.jpa.core.platform.GenericPlatform;
+import org.eclipse.jpt.jpa.core.resource.orm.XmlEntityMappings;
+import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory;
+import org.eclipse.jpt.jpa.core.resource.persistence.XmlJavaClassRef;
+import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef;
+import org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistence;
+import org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistenceUnit;
+import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
+import org.eclipse.jpt.jpa.core.tests.internal.projects.TestJpaProject;
+import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper;
+
+@SuppressWarnings("nls")
+public abstract class ContextModelTestCase extends AnnotationTestCase
+{
+ protected static final String BASE_PROJECT_NAME = "ContextModelTestProject";
+
+ protected JpaXmlResource persistenceXmlResource;
+
+ protected JpaXmlResource ormXmlResource;
+
+
+ protected ContextModelTestCase(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.persistenceXmlResource = getJpaProject().getPersistenceXmlResource();
+ this.ormXmlResource = getJpaProject().getDefaultOrmXmlResource();
+ this.waitForWorkspaceJobsToFinish();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ this.persistenceXmlResource = null;
+ this.ormXmlResource = null;
+ JptJpaCorePlugin.getWorkspacePreferences().clear();
+ this.waitForWorkspaceJobsToFinish();
+ super.tearDown();
+ }
+
+ @Override
+ protected TestJavaProject buildJavaProject(boolean autoBuild) throws Exception {
+ return buildJpaProject(BASE_PROJECT_NAME, autoBuild, buildJpaConfigDataModel());
+ }
+
+ protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild, IDataModel jpaConfig)
+ throws Exception {
+ return TestJpaProject.buildJpaProject(projectName, autoBuild, jpaConfig);
+ }
+
+ protected IDataModel buildJpaConfigDataModel() {
+ IDataModel dataModel = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider());
+ // default facet version is 2.0 - most tests use 1.0
+ dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_1_0.getVersionString());
+ // most tests use the basic generic platform
+ dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, GenericPlatform.VERSION_1_0);
+ // most tests do use an orm.xml
+ dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE);
+ return dataModel;
+ }
+
+ protected JpaProject getJpaProject() {
+ return getJavaProject().getJpaProject();
+ }
+
+ protected void waitForWorkspaceJobsToFinish() throws InterruptedException {
+ // This job will not start running until all the other workspace jobs are done
+ Job waitJob = new Job("Wait job") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ return Status.OK_STATUS;
+ }
+ };
+ waitJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
+ waitJob.schedule();
+ waitJob.join();
+ }
+
+ protected JpaXmlResource getPersistenceXmlResource() {
+ return this.persistenceXmlResource;
+ }
+
+ protected JpaXmlResource getOrmXmlResource() {
+ return this.ormXmlResource;
+ }
+
+ /**
+ * It's nice to be able to call this method from the debugger,
+ * to force the XML files to be written out so you can see their current state.
+ */
+ protected void saveXmlFiles() {
+ try {
+ this.saveXmlFiles_();
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ protected void saveXmlFiles_() throws Exception {
+ this.persistenceXmlResource.saveIfNecessary();
+ this.ormXmlResource.saveIfNecessary();
+ }
+
+ protected XmlEntityMappings getXmlEntityMappings() {
+ return (XmlEntityMappings) getOrmXmlResource().getRootObject();
+ }
+
+ protected XmlPersistence getXmlPersistence() {
+ return (XmlPersistence) getPersistenceXmlResource().getRootObject();
+ }
+
+ protected MappingFile getMappingFile() {
+ return this.getPersistenceUnit().mappingFileRefs().next().getMappingFile();
+ }
+
+ protected EntityMappings getEntityMappings() {
+ MappingFile mappingFile = this.getMappingFile();
+ return (mappingFile == null) ? null : (EntityMappings) mappingFile.getRoot();
+ }
+
+ protected XmlPersistenceUnit getXmlPersistenceUnit() {
+ return getXmlPersistence().getPersistenceUnits().get(0);
+ }
+
+ protected PersistenceUnit getPersistenceUnit() {
+ return getRootContextNode().getPersistenceXml().getPersistence().persistenceUnits().next();
+ }
+
+ protected ClassRef getSpecifiedClassRef() {
+ return getPersistenceUnit().specifiedClassRefs().next();
+ }
+
+ protected JavaPersistentType getJavaPersistentType() {
+ return getSpecifiedClassRef().getJavaPersistentType();
+ }
+
+ protected JavaEntity getJavaEntity() {
+ return (JavaEntity) getJavaPersistentType().getMapping();
+ }
+
+ protected void addXmlClassRef(String className) {
+ XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit();
+
+ XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef();
+ xmlClassRef.setJavaClass(className);
+ xmlPersistenceUnit.getClasses().add(xmlClassRef);
+ }
+
+ protected void removeXmlClassRef(String className) {
+ XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit();
+ XmlJavaClassRef xmlJavaClassRefToRemove = null;
+ for (XmlJavaClassRef xmlJavaClassRef : xmlPersistenceUnit.getClasses()) {
+ if (xmlJavaClassRef.getJavaClass().equals(className)) {
+ xmlJavaClassRefToRemove = xmlJavaClassRef;
+ }
+ }
+ if (xmlJavaClassRefToRemove == null) {
+ throw new IllegalArgumentException();
+ }
+ xmlPersistenceUnit.getClasses().remove(xmlJavaClassRefToRemove);
+ }
+
+ protected void addXmlMappingFileRef(String fileName) {
+ XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit();
+
+ XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef();
+ xmlMappingFileRef.setFileName(fileName);
+ xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef);
+ }
+
+ protected JpaRootContextNode getRootContextNode() {
+ return getJavaProject().getJpaProject().getRootContextNode();
+ }
+
+ @Override
+ protected TestJpaProject getJavaProject() {
+ return (TestJpaProject) super.getJavaProject();
+ }
+
+ protected void deleteResource(Resource resource) throws CoreException {
+ WorkbenchResourceHelper.deleteResource(resource);
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaFileTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaFileTests.java
new file mode 100644
index 0000000000..b23d196eda
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaFileTests.java
@@ -0,0 +1,411 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context;
+
+import java.util.Iterator;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory;
+import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef;
+import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
+
+@SuppressWarnings("nls")
+public class JpaFileTests extends ContextModelTestCase
+{
+ public JpaFileTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef();
+ mappingFileRef.setFileName(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString());
+ getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef);
+ getPersistenceXmlResource().save(null);
+ }
+
+ private ICompilationUnit createTestEntity() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+ });
+ }
+
+ public void testGetRootStructureNode() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ IFile file = getOrmXmlResource().getFile();
+ JpaFile ormXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+
+ assertEquals(getEntityMappings(), ormXmlJpaFile.rootStructureNodes().next());
+
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next());
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ //verify the mapping file reference "wins" as the root structure node when both
+ //persistence.xml <class> tag and mapping file <entity> tag exist for a particulary java class
+ assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next());
+
+ getEntityMappings().removePersistentType(ormPersistentType);
+
+ assertEquals(getJavaEntity().getPersistentType(), javaJpaFile.rootStructureNodes().next());
+
+ ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next());
+ }
+
+ public void testEntityMappingsRootStructureNodeRemoved() throws Exception {
+ IFile file = getOrmXmlResource().getFile();
+ JpaFile ormXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ assertEquals(getEntityMappings(), ormXmlJpaFile.rootStructureNodes().next());
+
+ JpaXmlResource resource = (JpaXmlResource) ormXmlJpaFile.getResourceModel();
+ resource.getContents().remove(resource.getRootObject());
+
+ assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext());
+ }
+
+ public void testImpliedEntityMappingsRootStructureNodeRemoved() throws Exception {
+ IFile file = getOrmXmlResource().getFile();
+ JpaFile ormXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+
+ assertNull(getPersistenceUnit().getImpliedMappingFileRef());
+
+ getXmlPersistenceUnit().getMappingFiles().remove(0);
+ assertNotNull(getPersistenceUnit().getImpliedMappingFileRef());
+ assertEquals(getPersistenceUnit().getImpliedMappingFileRef().getMappingFile().getRoot(), ormXmlJpaFile.rootStructureNodes().next());
+
+ JpaXmlResource resource = (JpaXmlResource) ormXmlJpaFile.getResourceModel();
+ resource.getContents().remove(resource.getRootObject());
+
+ assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext());
+ }
+
+ public void testEntityMappingsRootStructureNodeRemovedFromResourceModel() throws Exception {
+ IFile file = getOrmXmlResource().getFile();
+ JpaFile ormXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ assertEquals(getEntityMappings(), ormXmlJpaFile.rootStructureNodes().next());
+
+ getOrmXmlResource().getContents().remove(getOrmXmlResource().getRootObject());
+
+ assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext());
+ }
+
+ public void testUpdatePersistenceRootStructureNodePersistenceRemoved() throws Exception {
+ IFile file = getPersistenceXmlResource().getFile();
+ JpaFile persistenceXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ assertEquals(getRootContextNode().getPersistenceXml().getPersistence(), persistenceXmlJpaFile.rootStructureNodes().next());
+
+ JpaXmlResource resource = (JpaXmlResource) persistenceXmlJpaFile.getResourceModel();
+ resource.getContents().remove(resource.getRootObject());
+
+ assertFalse(persistenceXmlJpaFile.rootStructureNodes().hasNext());
+ }
+
+ public void testUpdateOrmJavaRootStructureNodePersistenceRemoved() throws Exception {
+ IFile file = getPersistenceXmlResource().getFile();
+ JpaFile persistenceXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next());
+
+ JpaXmlResource resource = (JpaXmlResource) persistenceXmlJpaFile.getResourceModel();
+ resource.getContents().remove(resource.getRootObject());
+
+ assertFalse(javaJpaFile.rootStructureNodes().hasNext());
+ }
+
+ public void testUpdateJavaRootStructureNodePersistenceRemoved() throws Exception {
+ IFile file = getPersistenceXmlResource().getFile();
+ JpaFile persistenceXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ ICompilationUnit cu = createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next());
+
+ JpaXmlResource resource = (JpaXmlResource) persistenceXmlJpaFile.getResourceModel();
+ resource.getContents().remove(resource.getRootObject());
+
+ assertFalse(javaJpaFile.rootStructureNodes().hasNext());
+ }
+
+ public void testPersistenceRootStructureNodeRemovedFromResourceModel() throws Exception {
+ IFile file = getPersistenceXmlResource().getFile();
+ JpaFile persistenceXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ getRootContextNode().getPersistenceXml().getPersistence();
+ assertEquals(getRootContextNode().getPersistenceXml().getPersistence(), persistenceXmlJpaFile.rootStructureNodes().next());
+
+ getPersistenceXmlResource().getContents().remove(getXmlPersistence());
+
+ assertFalse(persistenceXmlJpaFile.rootStructureNodes().hasNext());
+ }
+
+ public void testUpdateOrmJavaRootStructureNodePersistenceXmlRemoved() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next());
+
+ getPersistenceXmlResource().getContents().remove(getXmlPersistence());
+ assertFalse(javaJpaFile.rootStructureNodes().hasNext());
+ }
+
+ public void testUpdateJavaRootStructureNodePersistenceXmlRemoved() throws Exception {
+ ICompilationUnit cu = createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next());
+
+ getPersistenceXmlResource().getContents().remove(getXmlPersistence());
+ assertFalse(javaJpaFile.rootStructureNodes().hasNext());
+ }
+
+ public void testOrmJavaPersistentTypeRootStructureNodeRemoved() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
+ assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+ assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof OrmPersistentType);
+
+
+ getEntityMappings().removePersistentType(0);
+
+ assertEquals(1, javaJpaFile.rootStructureNodesSize());
+ assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof ClassRef);
+ assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+ }
+
+ public void testOrmJavaPersistentTypeRootStructureNodeRemovedFromResourceModel() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
+ assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+ assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof OrmPersistentType);
+
+ getXmlEntityMappings().getEntities().remove(0);
+
+ assertEquals(1, javaJpaFile.rootStructureNodesSize());
+ assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof ClassRef);
+ assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+ }
+
+ public void testJavaPersistentTypeRootStructureNodeRemoved() throws Exception {
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentType javaPersistentType = getJavaPersistentType();
+ assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+ assertEquals(getEntityMappings().getPersistenceUnit().specifiedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent());
+
+ getEntityMappings().getPersistenceUnit().removeSpecifiedClassRef(0);
+ assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+ assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent());
+ }
+
+ public void testJavaPersistentTypeRootStructureNodeRemovedFromResourceModel() throws Exception {
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentType javaPersistentType = getJavaPersistentType();
+ Iterator<JpaStructureNode> rootStructureNodes = javaJpaFile.rootStructureNodes();
+ JpaStructureNode rootStructureNode = rootStructureNodes.next();
+ assertEquals(javaPersistentType, rootStructureNode);
+ assertEquals(getEntityMappings().getPersistenceUnit().specifiedClassRefs().next(), rootStructureNode.getParent());
+ assertFalse(rootStructureNodes.hasNext());
+
+ removeXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+ assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent());
+ }
+
+ public void testImpliedJavaPersistentTypeRootStructureNodeRemoved() throws Exception {
+ getJpaProject().setDiscoversAnnotatedClasses(true);
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ JavaPersistentType javaPersistentType = getPersistenceUnit().impliedClassRefs().next().getJavaPersistentType();
+ assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+
+ javaPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY);
+
+ assertFalse(javaJpaFile.rootStructureNodes().hasNext());
+ }
+
+ public void testJavaRootStructureNodesEntityMappingsRemoved() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
+ assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+
+ getOrmXmlResource().getContents().remove(getXmlEntityMappings());
+ assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+ assertEquals(1, javaJpaFile.rootStructureNodesSize());
+ assertEquals(getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent());
+ }
+
+ public void testJavaRootStructureNodesPersistenceUnitRemovedFromResourceModel() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
+ assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+
+ getXmlPersistence().getPersistenceUnits().remove(0);
+
+ assertFalse(javaJpaFile.rootStructureNodes().hasNext());
+ assertEquals(0, javaJpaFile.rootStructureNodesSize());
+ }
+
+ public void testJavaRootStructureNodesPersistenceUnitRemoved() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
+ assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+
+ getJpaProject().getRootContextNode().getPersistenceXml().getPersistence().removePersistenceUnit(0);
+
+ assertFalse(javaJpaFile.rootStructureNodes().hasNext());
+ assertEquals(0, javaJpaFile.rootStructureNodesSize());
+ }
+
+ public void testJavaRootStructureNodesOrmPersistentTypeRemoved() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
+ assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+
+ getEntityMappings().removePersistentType(0);
+ assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+ assertEquals(1, javaJpaFile.rootStructureNodesSize());
+ assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent());
+ }
+
+ public void testJavaRootStructureNodesOrmTypeMappingMorphed() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
+ assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+
+ ormPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY);
+ assertEquals(1, javaJpaFile.rootStructureNodesSize());
+ javaPersistentType = getEntityMappings().getPersistentTypes().iterator().next().getJavaPersistentType();
+ assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+
+ getEntityMappings().removePersistentType(0);
+ assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+ assertEquals(1, javaJpaFile.rootStructureNodesSize());
+ assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent());
+ }
+
+ public void testUpdateOrmJavaRootStructureNodeMappingFileRefChanged() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next());
+
+ MappingFileRef mappingFileRef = getPersistenceUnit().mappingFileRefs().next();
+ mappingFileRef.setFileName("foo");
+
+ ormPersistentType = ((EntityMappings) getPersistenceUnit().getImpliedMappingFileRef().getMappingFile().getRoot()).getPersistentTypes().iterator().next();
+ assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next());
+
+ IFile file = getPersistenceXmlResource().getFile();
+ JpaFile ormXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+
+ assertEquals(1, ormXmlJpaFile.rootStructureNodesSize());
+ }
+
+ public void testUpdateJavaRootStructureNodeMappingFileRefChanged() throws Exception {
+ ICompilationUnit cu = createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next());
+
+ MappingFileRef mappingFileRef = getPersistenceUnit().mappingFileRefs().next();
+ mappingFileRef.setFileName("foo");
+ assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next());
+ }
+
+
+ public void testUpdateJavaRootStrucutreNodeDeleteOrmResource() throws Exception {
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ ICompilationUnit cu = createTestEntity();
+ JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+
+ JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
+ assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+
+
+ deleteResource(getOrmXmlResource());
+
+ assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next());
+ assertEquals(1, javaJpaFile.rootStructureNodesSize());
+ assertEquals(getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent());
+ }
+ //TODO test rootStructureNodes with a static inner class
+} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaProjectTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaProjectTests.java
new file mode 100644
index 0000000000..9d161a60e5
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaProjectTests.java
@@ -0,0 +1,172 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context;
+
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties;
+import org.eclipse.jpt.jpa.core.JpaFacet;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetDataModelProperties;
+import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProperties;
+import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProvider;
+import org.eclipse.jpt.jpa.core.internal.operations.OrmFileCreationDataModelProvider;
+import org.eclipse.jpt.jpa.core.internal.operations.PersistenceFileCreationDataModelProvider;
+import org.eclipse.jpt.jpa.core.platform.GenericPlatform;
+import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
+import org.eclipse.jpt.jpa.core.tests.internal.projects.TestJpaProject;
+import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+
+@SuppressWarnings("nls")
+public class JpaProjectTests extends TestCase
+{
+ static final String BASE_PROJECT_NAME = JpaProjectTests.class.getSimpleName();
+
+ TestJpaProject jpaProject;
+
+
+ public JpaProjectTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.jpaProject = TestJpaProject.buildJpaProject(BASE_PROJECT_NAME, false, buildJpaConfigDataModel()); // false = no auto-build
+ }
+
+ protected IDataModel buildJpaConfigDataModel() {
+ IDataModel dataModel = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider());
+ dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_1_0.getVersionString());
+ dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, GenericPlatform.VERSION_1_0);
+ dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE);
+ return dataModel;
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ this.jpaProject.getProject().delete(true, true, null);
+ this.jpaProject = null;
+ super.tearDown();
+ }
+
+ protected JpaProject getJpaProject() {
+ return this.jpaProject.getJpaProject();
+ }
+
+ public void testGetPersistenceXmlResource() throws Exception {
+ JpaXmlResource resource = this.getJpaProject().getPersistenceXmlResource();
+ assertNotNull(resource);
+ assertEquals(JptJpaCorePlugin.PERSISTENCE_XML_CONTENT_TYPE, resource.getContentType());
+ assertEquals("src/META-INF/persistence.xml", resource.getFile().getProjectRelativePath().toString());
+
+ //delete the persistence.xml file and verify it is not returned from getPersistenceXmlResource()
+ resource.delete(null);
+ resource = this.getJpaProject().getPersistenceXmlResource();
+ assertNull(resource);
+
+ //add the persistence.xml file back
+ createPersistenceXmlFile();
+ resource = this.getJpaProject().getPersistenceXmlResource();
+ assertNotNull(resource);
+ assertEquals(JptJpaCorePlugin.PERSISTENCE_XML_CONTENT_TYPE, resource.getContentType());
+ assertEquals("src/META-INF/persistence.xml", resource.getFile().getProjectRelativePath().toString());
+ }
+
+ private void createPersistenceXmlFile() throws Exception {
+ IDataModel config =
+ DataModelFactory.createDataModel(new PersistenceFileCreationDataModelProvider());
+ config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH,
+ getJpaProject().getProject().getFolder("src/META-INF").getFullPath());
+ config.getDefaultOperation().execute(null, null);
+ }
+
+ public void testGetDefaultOrmXmlResource() throws Exception {
+ JpaXmlResource resource = this.getJpaProject().getDefaultOrmXmlResource();
+ assertNotNull(resource);
+ assertEquals(JptJpaCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType());
+ assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString());
+
+ //delete the orm.xml file and verify it is not returned from getDefaultOrmXmlResource()
+ resource.delete(null);
+ resource = this.getJpaProject().getDefaultOrmXmlResource();
+ assertNull(resource);
+
+ //add the default orm.xml file back
+ createDefaultOrmXmlFile();
+ resource = this.getJpaProject().getDefaultOrmXmlResource();
+ assertNotNull(resource);
+ assertEquals(JptJpaCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType());
+ assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString());
+ }
+
+ private void createDefaultOrmXmlFile() throws Exception {
+ IDataModel config =
+ DataModelFactory.createDataModel(new OrmFileCreationDataModelProvider());
+ config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH,
+ getJpaProject().getProject().getFolder("src/META-INF").getFullPath());
+ config.getDefaultOperation().execute(null, null);
+ }
+
+ private void createOrmXmlFile(String fileName) throws Exception {
+ IDataModel config =
+ DataModelFactory.createDataModel(new OrmFileCreationDataModelProvider());
+ config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH,
+ getJpaProject().getProject().getFolder("src/META-INF").getFullPath());
+ config.setProperty(JptFileCreationDataModelProperties.FILE_NAME, fileName);
+ config.getDefaultOperation().execute(null, null);
+ }
+
+ public void testGetMappingFileResource() throws Exception {
+ JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH);
+ assertNotNull(resource);
+ assertEquals(JptJpaCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType());
+ assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString());
+
+ //delete the orm.xml file and verify it is not returned from getMappingFileResource()
+ resource.delete(null);
+ resource = this.getJpaProject().getMappingFileXmlResource(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH);
+ assertNull(resource);
+
+ //add the orm.xml file back
+ createDefaultOrmXmlFile();
+ resource = this.getJpaProject().getMappingFileXmlResource(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH);
+ assertNotNull(resource);
+ assertEquals(JptJpaCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType());
+ assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString());
+ }
+
+ public void testGetMappingFileResourceDifferentlyName() throws Exception {
+ JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml"));
+ assertNull(resource);
+
+ //create the orm2.xml file
+ createOrmXmlFile("orm2.xml");
+ resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml"));
+ assertNotNull(resource);
+ assertEquals(JptJpaCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType());
+ assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString());
+
+ //delete the orm2.xml file and verify it is not returned from getMappingFileResource()
+ resource.delete(null);
+ resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml"));
+ assertNull(resource);
+
+ //add the orm2.xml file back
+ createOrmXmlFile("orm2.xml");
+ resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml"));
+ assertNotNull(resource);
+ assertEquals(JptJpaCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType());
+ assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString());
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JptJpaCoreContextModelTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JptJpaCoreContextModelTests.java
new file mode 100644
index 0000000000..52c3042f96
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JptJpaCoreContextModelTests.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.jpt.jpa.core.tests.internal.JptJpaCoreTests;
+import org.eclipse.jpt.jpa.core.tests.internal.context.java.JptCoreContextJavaModelTests;
+import org.eclipse.jpt.jpa.core.tests.internal.context.orm.JptCoreOrmContextModelTests;
+import org.eclipse.jpt.jpa.core.tests.internal.context.persistence.JptCorePersistenceContextModelTests;
+import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.java.Generic2_0JavaContextModelTests;
+import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.orm.Generic2_0OrmContextModelTests;
+import org.eclipse.jpt.jpa.core.tests.internal.jpa2.context.persistence.Generic2_0PersistenceContextModelTests;
+
+/**
+ * Required Java system property:
+ * -Dorg.eclipse.jpt.jpa.jar=<jpa.jar path>
+ */
+public class JptJpaCoreContextModelTests
+ extends TestCase
+{
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JptJpaCoreContextModelTests.class.getPackage().getName());
+
+ if (JptJpaCoreTests.requiredJarsExists()) {
+ suite.addTestSuite(JpaProjectTests.class);
+ suite.addTestSuite(JpaFileTests.class);
+ suite.addTest(JptCorePersistenceContextModelTests.suite());
+ suite.addTest(JptCoreOrmContextModelTests.suite());
+ suite.addTest(JptCoreContextJavaModelTests.suite());
+ suite.addTest(Generic2_0JavaContextModelTests.suite());
+ suite.addTest(Generic2_0OrmContextModelTests.suite());
+ suite.addTest(Generic2_0PersistenceContextModelTests.suite());
+ } else {
+ suite.addTest(TestSuite.warning(JptJpaCoreTests.buildMissingJarErrorMessage()));
+ }
+ return suite;
+ }
+
+ private JptJpaCoreContextModelTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java
new file mode 100644
index 0000000000..1a2395aba8
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java
@@ -0,0 +1,236 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.AccessType;
+import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaBasicMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaEmbeddedMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaIdMapping;
+import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class GenericJavaPersistentAttributeTests extends ContextModelTestCase
+{
+
+ private ICompilationUnit createTestEntityAnnotatedField() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Id");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityAnnotatedMethod() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendGetIdMethodAnnotationTo(StringBuilder sb) {
+ sb.append("@Id");
+ }
+ });
+ }
+
+
+ public GenericJavaPersistentAttributeTests(String name) {
+ super(name);
+ }
+
+ public void testGetName() throws Exception {
+ createTestType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+
+ assertEquals("id", persistentAttribute.getName());
+ }
+
+ public void testGetMapping() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ assertTrue(persistentAttribute.getMapping() instanceof JavaIdMapping);
+
+ persistentAttribute.setMappingKey(null);
+ assertTrue(persistentAttribute.getMapping() instanceof JavaBasicMapping);
+ }
+
+ public void testGetSpecifiedMapping() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ assertTrue(persistentAttribute.getMapping() instanceof JavaIdMapping);
+
+ persistentAttribute.setMappingKey(null);
+ assertTrue(persistentAttribute.getMapping().isDefault());
+ }
+
+ public void testGetSpecifiedMappingNull() throws Exception {
+ createTestType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+
+ assertTrue(persistentAttribute.getMapping().isDefault());
+ assertNotNull(persistentAttribute.getMapping());
+ }
+
+ public void testMappingKey() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+
+ assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey());
+
+ persistentAttribute.setMappingKey(null);
+ assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey());
+ }
+
+ public void testDefaultMappingKey() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+
+ assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey());
+ assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey());
+ }
+
+ public void testSetSpecifiedMappingKey() throws Exception {
+ createTestType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ assertTrue(persistentAttribute.getMapping().isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+
+ assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey());
+ assertTrue(persistentAttribute.getMapping() instanceof JavaEmbeddedMapping);
+ }
+
+ public void testSetSpecifiedMappingKey2() throws Exception {
+ createTestEntityAnnotatedField();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey());
+
+ persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+
+ assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey());
+ assertTrue(persistentAttribute.getMapping() instanceof JavaEmbeddedMapping);
+ }
+
+ public void testSetSpecifiedMappingKeyNull() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey());
+
+ persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+
+ assertTrue(persistentAttribute.getMapping().isDefault());
+ }
+
+ public void testGetMappingKeyMappingChangeInResourceModel() throws Exception {
+ createTestEntityAnnotatedField();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.setPrimaryAnnotation(EmbeddedAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance());
+ this.getJpaProject().synchronizeContextModel();
+ assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey());
+ }
+
+ public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception {
+ createTestType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ assertTrue(persistentAttribute.getMapping().isDefault());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.setPrimaryAnnotation(BasicAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance());
+
+ assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMapping().getKey());
+ }
+
+ public void testGetAccessField() throws Exception {
+ createTestEntityAnnotatedField();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ assertEquals(AccessType.FIELD, persistentAttribute.getAccess());
+ assertEquals(AccessType.FIELD, persistentAttribute.getDefaultAccess());
+ assertEquals(null, persistentAttribute.getSpecifiedAccess());
+ }
+
+ public void testGetAccessProperty() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ assertEquals(AccessType.PROPERTY, persistentAttribute.getAccess());
+ assertEquals(AccessType.PROPERTY, persistentAttribute.getDefaultAccess());
+ assertEquals(null, persistentAttribute.getSpecifiedAccess());
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java
new file mode 100644
index 0000000000..9f0e196434
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java
@@ -0,0 +1,759 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.AccessType;
+import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddableAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EntityAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory;
+import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+
+@SuppressWarnings("nls")
+public class GenericJavaPersistentTypeTests extends ContextModelTestCase
+{
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef();
+ mappingFileRef.setFileName(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString());
+ getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef);
+ getPersistenceXmlResource().save(null);
+ }
+
+ private ICompilationUnit createTestEntity() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityAnnotatedField() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Id");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityAnnotatedMethod() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendGetIdMethodAnnotationTo(StringBuilder sb) {
+ sb.append("@Id");
+ }
+ });
+ }
+ private ICompilationUnit createTestEntityAnnotatedFieldAndMethod() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendGetIdMethodAnnotationTo(StringBuilder sb) {
+ sb.append("@Id");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Id");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestSubType() throws Exception {
+ return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY);
+ }
+ @Override
+ public void appendExtendsImplementsTo(StringBuilder sb) {
+ sb.append("extends " + TYPE_NAME + " ");
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ });
+ }
+
+ private ICompilationUnit createTestSubTypeWithFieldAnnotation() throws Exception {
+ return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendExtendsImplementsTo(StringBuilder sb) {
+ sb.append("extends " + TYPE_NAME + " ");
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Id");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestSubTypeWithMethodAnnotation() throws Exception {
+ return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendExtendsImplementsTo(StringBuilder sb) {
+ sb.append("extends " + TYPE_NAME + " ");
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendGetIdMethodAnnotationTo(StringBuilder sb) {
+ sb.append("@Id");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestSubTypeNonPersistent() throws Exception {
+ return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() {
+ @Override
+ public void appendExtendsImplementsTo(StringBuilder sb) {
+ sb.append("extends " + TYPE_NAME + " ");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestSubTypePersistentExtendsNonPersistent() throws Exception {
+ return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild2.java", "AnnotationTestTypeChild2", new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendExtendsImplementsTo(StringBuilder sb) {
+ sb.append("extends AnnotationTestTypeChild ");
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendGetIdMethodAnnotationTo(StringBuilder sb) {
+ sb.append("@Id");
+ }
+ });
+ }
+
+ public GenericJavaPersistentTypeTests(String name) {
+ super(name);
+ }
+
+ public void testGetName() throws Exception {
+ createTestType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(FULLY_QUALIFIED_TYPE_NAME, getJavaPersistentType().getName());
+ }
+
+ public void testGetAccessNothingAnnotated() throws Exception {
+ createTestType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess());
+ }
+
+ public void testAccessField() throws Exception {
+ createTestEntityAnnotatedField();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess());
+ }
+
+ public void testAccessProperty() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess());
+ }
+
+ public void testAccessFieldAndMethodAnnotated() throws Exception {
+ createTestEntityAnnotatedFieldAndMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess());
+ }
+
+ public void testAccessInheritance() throws Exception {
+ createTestEntityAnnotatedMethod();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ ClassRef classRef = classRefs.next();
+
+ JavaPersistentType javaPersistentType = classRef.getJavaPersistentType();
+ assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName());
+
+ assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess());
+ }
+
+ public void testAccessInheritance2() throws Exception {
+ createTestEntityAnnotatedField();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ ClassRef classRef = classRefs.next();
+
+ JavaPersistentType javaPersistentType = classRef.getJavaPersistentType();
+ assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName());
+
+ assertEquals(AccessType.FIELD, javaPersistentType.getAccess());
+ }
+
+ public void testAccessInheritance3() throws Exception {
+ createTestEntityAnnotatedField();
+ createTestSubTypeWithMethodAnnotation();
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ ClassRef classRef = classRefs.next();
+
+ JavaPersistentType javaPersistentType = classRef.getJavaPersistentType();
+ assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName());
+
+ assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess());
+ }
+
+ public void testAccessInheritance4() throws Exception {
+ createTestEntityAnnotatedMethod();
+ createTestSubTypeWithFieldAnnotation();
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ ClassRef classRef = classRefs.next();
+ JavaPersistentType javaPersistentType = classRef.getJavaPersistentType();
+
+ assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName());
+
+ assertEquals(AccessType.FIELD, javaPersistentType.getAccess());
+ }
+
+ //inherited class having annotations set wins over the default access set on persistence-unit-defaults
+ public void testAccessInheritancePersistenceUnitDefaultAccess() throws Exception {
+ createTestEntityAnnotatedMethod();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD);
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ ClassRef classRef = classRefs.next();
+ JavaPersistentType javaPersistentType = classRef.getJavaPersistentType();
+
+ assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName());
+
+ assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess());
+ }
+
+ public void testAccessXmlNoAccessNoAnnotations() throws Exception {
+ OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ createTestEntity();
+
+ JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType();
+ assertEquals(AccessType.FIELD, javaPersistentType.getAccess());
+ }
+
+ public void testAccessXmlEntityAccessNoAnnotations() throws Exception {
+ OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ createTestEntity();
+ JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType();
+
+ entityPersistentType.setSpecifiedAccess(AccessType.FIELD);
+ assertEquals(AccessType.FIELD, javaPersistentType.getAccess());
+
+ entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY);
+ assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess());
+ }
+
+ public void testAccessXmlPersistenceUnitDefaultsAccessNoAnnotations() throws Exception {
+ OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ createTestEntity();
+ JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType();
+ assertEquals(AccessType.FIELD, javaPersistentType.getAccess());
+
+ getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD);
+ assertEquals(AccessType.FIELD, javaPersistentType.getAccess());
+
+ getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY);
+ assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess());
+ }
+
+ public void testAccessXmlEntityPropertyAccessAndFieldAnnotations() throws Exception {
+ //xml access set to property, field annotations, JavaPersistentType access is field
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ createTestEntityAnnotatedField();
+ JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
+
+ ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY);
+ assertEquals(AccessType.FIELD, javaPersistentType.getAccess());
+ }
+
+ public void testAccessXmlEntityFieldAccessAndPropertyAnnotations() throws Exception {
+ //xml access set to field, property annotations, JavaPersistentType access is property
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ createTestEntityAnnotatedMethod();
+ JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
+
+ ormPersistentType.setSpecifiedAccess(AccessType.FIELD);
+ assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess());
+ }
+
+ public void testAccessXmlPersistenceUnitDefaultsAccessFieldAnnotations() throws Exception {
+ OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ createTestEntityAnnotatedField();
+ JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType();
+
+ getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY);
+ assertEquals(AccessType.FIELD, javaPersistentType.getAccess());
+ }
+
+ //inheritance wins over entity-mappings specified access
+ public void testAccessXmlEntityMappingsAccessWithInheritance() throws Exception {
+ OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ OrmPersistentType childEntityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild");
+
+ createTestEntityAnnotatedMethod();
+ createTestSubType();
+ JavaPersistentType childJavaPersistentType = childEntityPersistentType.getJavaPersistentType();
+
+ getEntityMappings().setSpecifiedAccess(AccessType.FIELD);
+ assertEquals(AccessType.PROPERTY, entityPersistentType.getJavaPersistentType().getAccess());
+ assertEquals(AccessType.PROPERTY, childJavaPersistentType.getAccess());
+ }
+
+ public void testAccessXmlMetadataCompleteFieldAnnotations() throws Exception {
+ //xml access set to property, java has field annotations so the access should be field
+ OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ createTestEntityAnnotatedField();
+ JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType();
+
+ getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY);
+ getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true);
+ assertEquals(AccessType.FIELD, javaPersistentType.getAccess());
+
+ }
+
+ public void testAccessNoXmlAccessXmlMetdataCompletePropertyAnnotations() throws Exception {
+ //xml access not set, metadata complete set. JavaPersistentType access is property because properties are annotated
+ OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ createTestEntityAnnotatedMethod();
+ JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType();
+
+ getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true);
+ assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess());
+ }
+
+ public void testSuperPersistentType() throws Exception {
+ createTestEntityAnnotatedMethod();
+ createTestSubTypeWithFieldAnnotation();
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ ClassRef classRef = classRefs.next();
+ JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType();
+
+ classRef = classRefs.next();
+ JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType();
+
+ assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType());
+ assertNull(rootJavaPersistentType.getSuperPersistentType());
+ }
+
+ public void testSuperPersistentType2() throws Exception {
+ createTestEntityAnnotatedMethod();
+ createTestSubTypeWithFieldAnnotation();
+
+ //super is not added to the persistenceUnit, but it should still be found
+ //as the superPersistentType because of impliedClassRefs and changes for bug 190317
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ JavaPersistentType javaPersistentType = classRefs.next().getJavaPersistentType();
+
+ assertNotNull(javaPersistentType.getSuperPersistentType());
+ }
+
+ //Entity extends Non-Entity extends Entity
+ public void testSuperPersistentType3() throws Exception {
+ createTestEntityAnnotatedMethod();
+ createTestSubTypeNonPersistent();
+ createTestSubTypePersistentExtendsNonPersistent();
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2");
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ ClassRef classRef = classRefs.next();
+ JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType();
+
+ classRef = classRefs.next();
+ JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType();
+
+ assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType());
+ assertNull(rootJavaPersistentType.getSuperPersistentType());
+ }
+
+ public void testInheritanceHierarchy() throws Exception {
+ createTestEntityAnnotatedMethod();
+ createTestSubTypeNonPersistent();
+ createTestSubTypePersistentExtendsNonPersistent();
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2");
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType();
+ JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType();
+
+ Iterator<PersistentType> inheritanceHierarchy = childJavaPersistentType.inheritanceHierarchy();
+
+ assertEquals(childJavaPersistentType, inheritanceHierarchy.next());
+ assertEquals(rootJavaPersistentType, inheritanceHierarchy.next());
+ }
+
+ public void testInheritanceHierarchy2() throws Exception {
+ createTestEntityAnnotatedMethod();
+ createTestSubTypeNonPersistent();
+ createTestSubTypePersistentExtendsNonPersistent();
+
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType();
+ JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType();
+
+ Iterator<PersistentType> inheritanceHierarchy = childJavaPersistentType.inheritanceHierarchy();
+
+ assertEquals(childJavaPersistentType, inheritanceHierarchy.next());
+ assertEquals(rootJavaPersistentType, inheritanceHierarchy.next());
+ }
+
+ public void testGetMapping() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey());
+ }
+
+ public void testGetMappingNull() throws Exception {
+ createTestType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey());
+ }
+
+ public void testMappingKey() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+ }
+
+ public void testMappingKeyNull() throws Exception {
+ createTestType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+ }
+
+ public void testSetMappingKey() throws Exception {
+ createTestType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+
+ getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ assertNotNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME));
+
+ assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+ }
+
+ public void testSetMappingKey2() throws Exception {
+ createTestEntityAnnotatedField();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+
+ getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ assertNotNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME));
+
+ assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+ }
+
+ public void testSetMappingKeyNull() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+
+ getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME));
+
+ assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+ }
+
+ public void testGetMappingKeyMappingChangeInResourceModel() throws Exception {
+ createTestEntityAnnotatedField();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+
+ JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ resourceType.setPrimaryAnnotation(EmbeddableAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance());
+ this.getJpaProject().synchronizeContextModel();
+
+ assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+ }
+
+ public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception {
+ createTestType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+
+ JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ resourceType.setPrimaryAnnotation(EntityAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance());
+ this.getJpaProject().synchronizeContextModel();
+
+ assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey());
+ }
+
+ public void testIsMapped() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertTrue(getJavaPersistentType().isMapped());
+
+ getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY);
+ assertFalse(getJavaPersistentType().isMapped());
+ }
+
+ public void testAttributes() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().attributes();
+
+ assertEquals("id", attributes.next().getName());
+ assertFalse(attributes.hasNext());
+ }
+
+ public void testAttributes2() throws Exception {
+ createTestEntityAnnotatedFieldAndMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().attributes();
+
+ assertEquals("id", attributes.next().getName());
+ assertEquals("name", attributes.next().getName());
+ assertFalse(attributes.hasNext());
+ }
+
+ public void testAttributesSize() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(1, getJavaPersistentType().attributesSize());
+ }
+
+ public void testAttributesSize2() throws Exception {
+ createTestEntityAnnotatedFieldAndMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(2, getJavaPersistentType().attributesSize());
+ }
+
+ public void testAttributeNamed() throws Exception {
+ createTestEntityAnnotatedMethod();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("id");
+
+ assertEquals("id", attribute.getName());
+ assertNull(getJavaPersistentType().getAttributeNamed("name"));
+ assertNull(getJavaPersistentType().getAttributeNamed("foo"));
+ }
+
+ public void testAttributeNamed2() throws Exception {
+ createTestEntityAnnotatedField();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("name");
+
+ assertEquals("name", attribute.getName());
+
+ assertNull(getJavaPersistentType().getAttributeNamed("foo"));
+ }
+
+ public void testRenameAttribute() throws Exception {
+ ICompilationUnit testType = createTestEntityAnnotatedField();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().attributes();
+ JavaPersistentAttribute idAttribute = attributes.next();
+ JavaPersistentAttribute nameAttribute = attributes.next();
+
+
+ assertEquals("id", idAttribute.getName());
+ assertEquals("name", nameAttribute.getName());
+
+ IField idField = testType.findPrimaryType().getField("id");
+ idField.rename("id2", false, null);
+
+ attributes = getJavaPersistentType().attributes();
+ JavaPersistentAttribute nameAttribute2 = attributes.next();
+ JavaPersistentAttribute id2Attribute = attributes.next();
+
+ assertNotSame(idAttribute, id2Attribute);
+ assertEquals("id2", id2Attribute.getName());
+ assertEquals(nameAttribute, nameAttribute2);
+ assertEquals("name", nameAttribute2.getName());
+ assertFalse(attributes.hasNext());
+ }
+
+ public void testSuperPersistentTypeGeneric() throws Exception {
+ createTestGenericEntity();
+ createTestGenericMappedSuperclass();
+
+ addXmlClassRef(PACKAGE_NAME + ".Entity1");
+ addXmlClassRef(PACKAGE_NAME + ".Entity2");
+
+ JavaPersistentType javaPersistentType = getJavaPersistentType();
+ assertEquals("test.Entity1", javaPersistentType.getName());
+ assertNotNull(javaPersistentType.getSuperPersistentType());
+
+ assertEquals("test.Entity2", javaPersistentType.getSuperPersistentType().getName());
+ }
+
+ private void createTestGenericEntity() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class Entity1 ");
+ sb.append("extends Entity2<Integer> {}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter);
+ }
+
+ private void createTestGenericMappedSuperclass() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.MAPPED_SUPERCLASS);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@MappedSuperclass");
+ sb.append(CR);
+ sb.append("public class Entity2<K> {}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity2.java", sourceWriter);
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaAssociationOverrideTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaAssociationOverrideTests.java
new file mode 100644
index 0000000000..dcec135aca
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaAssociationOverrideTests.java
@@ -0,0 +1,446 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.context.AssociationOverride;
+import org.eclipse.jpt.jpa.core.context.JoinColumn;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyAssociationOverride;
+import org.eclipse.jpt.jpa.core.context.VirtualAssociationOverride;
+import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverride;
+import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverrideContainer;
+import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
+import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumn;
+import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumnRelationshipStrategy;
+import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAssociationOverride;
+import org.eclipse.jpt.jpa.core.resource.java.AssociationOverrideAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaAssociationOverrideTests extends ContextModelTestCase
+{
+ private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE_NAME";
+
+
+ private ICompilationUnit createTestMappedSuperclass() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@MappedSuperclass");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@OneToOne");
+ sb.append(CR);
+ sb.append(" private AnnotationTestTypeChild address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithAssociationOverride() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ASSOCIATION_OVERRIDE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ sb.append("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\")");
+ }
+ });
+ }
+
+ private void createTestSubType() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class ").append("AnnotationTestTypeChild").append(" ");
+ sb.append("extends " + TYPE_NAME + " ");
+ sb.append("{}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter);
+ }
+
+
+
+ public JavaAssociationOverrideTests(String name) {
+ super(name);
+ }
+
+ public void testUpdateName() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME_ + "AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer();
+ VirtualAssociationOverride virtualOverride = overrideContainer.virtualOverrides().next();
+ AssociationOverride javaAssociationOverride = virtualOverride.convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE);
+
+ assertEquals("address", javaAssociationOverride.getName());
+ assertEquals("address", associationOverrideResource.getName());
+ assertTrue(overrideContainer.overrides().hasNext());
+
+ //set name in the resource model, verify context model updated
+ associationOverrideResource.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ assertEquals("FOO", javaAssociationOverride.getName());
+ assertEquals("FOO", associationOverrideResource.getName());
+
+ //set name to null in the resource model
+ associationOverrideResource.setName(null);
+ getJpaProject().synchronizeContextModel();
+ assertEquals(0, overrideContainer.specifiedOverridesSize());
+ assertNull(associationOverrideResource.getName());
+
+ associationOverrideResource.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(1, overrideContainer.specifiedOverridesSize());
+ javaAssociationOverride = overrideContainer.specifiedOverrides().next();
+ assertEquals("FOO", javaAssociationOverride.getName());
+ assertEquals("FOO", associationOverrideResource.getName());
+
+ typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ assertFalse(overrideContainer.specifiedOverrides().hasNext());
+ assertFalse(typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).hasNext());
+ }
+
+ public void testModifyName() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer();
+ VirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next();
+ AssociationOverride javaAssociationOverride = virtualAssociationOverride.convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE);
+
+ assertEquals("address", javaAssociationOverride.getName());
+ assertEquals("address", associationOverrideResource.getName());
+ assertTrue(overrideContainer.overrides().hasNext());
+
+ //set name in the context model, verify resource model modified
+ javaAssociationOverride.setName("foo");
+ assertEquals("foo", javaAssociationOverride.getName());
+ assertEquals("foo", associationOverrideResource.getName());
+
+ //set name to null in the context model
+ javaAssociationOverride.setName(null);
+ assertNull(javaAssociationOverride.getName());
+ associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE);
+ assertNull(associationOverrideResource.getName());
+ }
+
+ public void testAddSpecifiedJoinColumn() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer();
+ JavaVirtualAssociationOverride virtualOverride = overrideContainer.virtualOverrides().next();
+ JavaAssociationOverride specifiedOverride = virtualOverride.convertToSpecified();
+ JavaJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ AssociationOverrideAnnotation associationOverrideAnnotation = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE);
+
+
+ JavaJoinColumn joinColumn1 = joiningStrategy.addSpecifiedJoinColumn(0);
+ joinColumn1.setSpecifiedName("FOO");
+
+ assertEquals("FOO", associationOverrideAnnotation.joinColumnAt(0).getName());
+
+ JavaJoinColumn joinColumn2 = joiningStrategy.addSpecifiedJoinColumn(0);
+ joinColumn2.setSpecifiedName("BAR");
+
+ assertEquals("BAR", associationOverrideAnnotation.joinColumnAt(0).getName());
+ assertEquals("FOO", associationOverrideAnnotation.joinColumnAt(1).getName());
+
+ JavaJoinColumn joinColumn3 = joiningStrategy.addSpecifiedJoinColumn(1);
+ joinColumn3.setSpecifiedName("BAZ");
+
+ assertEquals(4, associationOverrideAnnotation.joinColumnsSize());
+ assertEquals("BAR", associationOverrideAnnotation.joinColumnAt(0).getName());
+ assertEquals("BAZ", associationOverrideAnnotation.joinColumnAt(1).getName());
+ assertEquals("FOO", associationOverrideAnnotation.joinColumnAt(2).getName());
+ assertEquals("address_id", associationOverrideAnnotation.joinColumnAt(3).getName()); // the old default join column
+
+ assertEquals(4, joiningStrategy.specifiedJoinColumnsSize());
+ ListIterator<JavaJoinColumn> joinColumns = joiningStrategy.specifiedJoinColumns();
+ assertEquals(joinColumn2, joinColumns.next());
+ assertEquals(joinColumn3, joinColumns.next());
+ assertEquals(joinColumn1, joinColumns.next());
+
+ joinColumns = joiningStrategy.specifiedJoinColumns();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertEquals("address_id", joinColumns.next().getName()); // the old default join column
+ }
+
+ public void testRemoveSpecifiedJoinColumn() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer();
+ JavaVirtualAssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next();
+ JavaAssociationOverride specifiedOverride = javaAssociationOverride.convertToSpecified();
+ JavaJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE);
+
+ assertEquals(1, associationOverrideResource.joinColumnsSize());
+
+ joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO");
+ joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR");
+ joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ");
+
+ assertEquals(4, associationOverrideResource.joinColumnsSize());
+
+ joiningStrategy.removeSpecifiedJoinColumn(0);
+ assertEquals(3, associationOverrideResource.joinColumnsSize());
+ assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName());
+ assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName());
+
+ joiningStrategy.removeSpecifiedJoinColumn(0);
+ assertEquals(2, associationOverrideResource.joinColumnsSize());
+ assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName());
+
+ joiningStrategy.removeSpecifiedJoinColumn(0);
+ assertEquals(1, associationOverrideResource.joinColumnsSize());
+
+ joiningStrategy.removeSpecifiedJoinColumn(0);
+ assertEquals(0, associationOverrideResource.joinColumnsSize());
+ }
+
+ public void testMoveSpecifiedJoinColumn() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer();
+ JavaVirtualAssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next();
+ JavaAssociationOverride specifiedOverride = javaAssociationOverride.convertToSpecified();
+ JavaJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE);
+
+ joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO");
+ joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR");
+ joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ");
+
+ assertEquals(4, associationOverrideResource.joinColumnsSize());
+
+
+ joiningStrategy.moveSpecifiedJoinColumn(2, 0);
+ ListIterator<JavaJoinColumn> joinColumns = joiningStrategy.specifiedJoinColumns();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+
+ assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName());
+ assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName());
+ assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName());
+
+
+ joiningStrategy.moveSpecifiedJoinColumn(0, 1);
+ joinColumns = joiningStrategy.specifiedJoinColumns();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+
+ assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName());
+ assertEquals("BAR", associationOverrideResource.joinColumnAt(1).getName());
+ assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName());
+ }
+
+ public void testUpdateJoinColumns() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer();
+ JavaVirtualAssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next();
+ JavaAssociationOverride specifiedOverride = javaAssociationOverride.convertToSpecified();
+ JavaJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE);
+
+ ListIterator<JavaJoinColumn> joinColumns = joiningStrategy.specifiedJoinColumns();
+ JoinColumn joinColumn = joinColumns.next();
+ assertEquals("address_id", joinColumn.getSpecifiedName());
+ assertEquals("id", joinColumn.getSpecifiedReferencedColumnName());
+
+
+ associationOverrideResource.addJoinColumn(0);
+ associationOverrideResource.addJoinColumn(1);
+ associationOverrideResource.addJoinColumn(2);
+
+ associationOverrideResource.joinColumnAt(0).setName("FOO");
+ associationOverrideResource.joinColumnAt(1).setName("BAR");
+ associationOverrideResource.joinColumnAt(2).setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+
+ joinColumns = joiningStrategy.specifiedJoinColumns();
+ assertEquals("FOO", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("address_id", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ associationOverrideResource.moveJoinColumn(2, 0);
+ getJpaProject().synchronizeContextModel();
+ joinColumns = joiningStrategy.specifiedJoinColumns();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertEquals("address_id", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ associationOverrideResource.moveJoinColumn(0, 1);
+ getJpaProject().synchronizeContextModel();
+ joinColumns = joiningStrategy.specifiedJoinColumns();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertEquals("address_id", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ associationOverrideResource.removeJoinColumn(1);
+ getJpaProject().synchronizeContextModel();
+ joinColumns = joiningStrategy.specifiedJoinColumns();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ assertEquals("address_id", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ associationOverrideResource.removeJoinColumn(1);
+ getJpaProject().synchronizeContextModel();
+ joinColumns = joiningStrategy.specifiedJoinColumns();
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("address_id", joinColumns.next().getName());
+ assertFalse(joinColumns.hasNext());
+
+ associationOverrideResource.removeJoinColumn(0);
+ getJpaProject().synchronizeContextModel();
+ joinColumns = joiningStrategy.specifiedJoinColumns();
+ assertEquals("address_id", joinColumns.next().getName());
+
+ associationOverrideResource.removeJoinColumn(0);
+ getJpaProject().synchronizeContextModel();
+ assertFalse(joiningStrategy.specifiedJoinColumns().hasNext());
+ }
+
+ public void testGetName() throws Exception {
+ createTestEntityWithAssociationOverride();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+ AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next();
+ assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE);
+
+ associationOverrideResource.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ specifiedAssociationOverride = overrideContainer.specifiedOverrides().next();
+ assertEquals("FOO", specifiedAssociationOverride.getName());
+ }
+
+ public void testSetName() throws Exception {
+ createTestEntityWithAssociationOverride();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+ AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next();
+ assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName());
+
+ specifiedAssociationOverride.setName("FOO");
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE);
+
+ assertEquals("FOO", associationOverrideResource.getName());
+ }
+
+ public void testDefaultName() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer();
+ assertEquals("AnnotationTestTypeChild", entity.getName());
+ assertEquals(1, overrideContainer.virtualOverridesSize());
+
+ ReadOnlyAssociationOverride associationOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("address", associationOverride.getName());
+ }
+
+ public void testIsVirtual() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer();
+ assertEquals("AnnotationTestTypeChild", entity.getName());
+ assertEquals(1, overrideContainer.virtualOverridesSize());
+
+ ReadOnlyAssociationOverride associationOverride = overrideContainer.virtualOverrides().next();
+ assertTrue(associationOverride.isVirtual());
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaAttributeOverrideTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaAttributeOverrideTests.java
new file mode 100644
index 0000000000..b1fea4810d
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaAttributeOverrideTests.java
@@ -0,0 +1,260 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.context.AttributeOverride;
+import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer;
+import org.eclipse.jpt.jpa.core.context.BasicMapping;
+import org.eclipse.jpt.jpa.core.context.Column;
+import org.eclipse.jpt.jpa.core.context.Entity;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverrideContainer;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAttributeOverride;
+import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaAttributeOverrideTests extends ContextModelTestCase
+{
+ private static final String ATTRIBUTE_OVERRIDE_NAME = "MY_ATTRIBUTE_OVERRIDE_NAME";
+ private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "MY_ATTRIBUTE_OVERRIDE_COLUMN_NAME";
+
+ private ICompilationUnit createTestMappedSuperclass() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@MappedSuperclass");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithAttributeOverride() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ sb.append("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))");
+ }
+ });
+ }
+
+ private void createTestSubType() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class ").append("AnnotationTestTypeChild").append(" ");
+ sb.append("extends " + TYPE_NAME + " ");
+ sb.append("{}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter);
+ }
+
+
+
+ public JavaAttributeOverrideTests(String name) {
+ super(name);
+ }
+
+ public void testGetName() throws Exception {
+ createTestEntityWithAttributeOverride();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+ AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next();
+ assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE);
+
+ attributeOverrideResource.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverride = overrideContainer.specifiedOverrides().next();
+ assertEquals("FOO", specifiedAttributeOverride.getName());
+ }
+
+ public void testSetName() throws Exception {
+ createTestEntityWithAttributeOverride();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+ AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next();
+ assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName());
+
+ specifiedAttributeOverride.setName("FOO");
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE);
+
+ assertEquals("FOO", attributeOverrideResource.getName());
+ }
+
+ public void testColumnGetName() throws Exception {
+ createTestEntityWithAttributeOverride();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+ AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next();
+ Column column = specifiedAttributeOverride.getColumn();
+ assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getName());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE);
+ ColumnAnnotation columnResource = attributeOverrideResource.getColumn();
+ columnResource.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+
+
+ column = overrideContainer.specifiedOverrides().next().getColumn();
+ assertEquals("FOO", column.getName());
+ }
+
+ public void testColumnSetName() throws Exception {
+ createTestEntityWithAttributeOverride();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+ AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next();
+ Column column = specifiedAttributeOverride.getColumn();
+ assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getName());
+
+ column.setSpecifiedName("FOO");
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE);
+ ColumnAnnotation columnResource = attributeOverrideResource.getColumn();
+
+ assertEquals("FOO", columnResource.getName());
+
+ column.setSpecifiedName(null);
+
+ attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE);
+ assertNull(attributeOverrideResource.getColumn());
+ assertNotNull(specifiedAttributeOverride.getColumn());
+ }
+
+ public void testColumnDefaultName() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Entity entity = getJavaEntity();
+ AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer();
+ assertEquals("AnnotationTestTypeChild", entity.getName());
+ assertEquals(2, overrideContainer.virtualOverridesSize());
+
+ ReadOnlyAttributeOverride attributeOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("id", attributeOverride.getColumn().getDefaultName());
+
+
+ JavaPersistentType mappedSuperclass = CollectionTools.list(getPersistenceUnit().specifiedClassRefs()).get(1).getJavaPersistentType();
+ BasicMapping basicMapping = (BasicMapping) mappedSuperclass.getAttributeNamed("id").getMapping();
+ basicMapping.getColumn().setSpecifiedName("FOO");
+
+ attributeOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("FOO", attributeOverride.getColumn().getDefaultName());
+ }
+
+ public void testColumnDefaultTableName() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Entity entity = getJavaEntity();
+ AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer();
+ assertEquals("AnnotationTestTypeChild", entity.getName());
+ assertEquals(2, overrideContainer.virtualOverridesSize());
+
+ ReadOnlyAttributeOverride attributeOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("AnnotationTestTypeChild", attributeOverride.getColumn().getDefaultTable());
+
+
+ JavaPersistentType mappedSuperclass = CollectionTools.list(getPersistenceUnit().specifiedClassRefs()).get(1).getJavaPersistentType();
+ BasicMapping basicMapping = (BasicMapping) mappedSuperclass.getAttributeNamed("id").getMapping();
+ basicMapping.getColumn().setSpecifiedTable("BAR");
+
+ attributeOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("BAR", attributeOverride.getColumn().getDefaultTable());
+ }
+
+ public void testDefaultName() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Entity entity = getJavaEntity();
+ AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer();
+ assertEquals("AnnotationTestTypeChild", entity.getName());
+ assertEquals(2, overrideContainer.virtualOverridesSize());
+
+ ReadOnlyAttributeOverride attributeOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("id", attributeOverride.getName());
+ }
+
+ public void testIsVirtual() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Entity entity = getJavaEntity();
+ AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer();
+ assertEquals("AnnotationTestTypeChild", entity.getName());
+ assertEquals(2, overrideContainer.virtualOverridesSize());
+
+ ReadOnlyAttributeOverride attributeOverride = overrideContainer.virtualOverrides().next();
+ assertTrue(attributeOverride.isVirtual());
+ }
+
+ public void testSetColumn() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+ JavaVirtualAttributeOverride attributeOverride = overrideContainer.virtualOverrides().next();
+ attributeOverride.convertToSpecified().getColumn().setSpecifiedName("FOO");
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE);
+
+ assertEquals("FOO", attributeOverrideResource.getColumn().getName());
+ assertEquals("FOO", overrideContainer.specifiedOverrides().next().getColumn().getSpecifiedName());
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaBasicMappingTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaBasicMappingTests.java
new file mode 100644
index 0000000000..b7dd1d28b7
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaBasicMappingTests.java
@@ -0,0 +1,995 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.AccessType;
+import org.eclipse.jpt.jpa.core.context.BasicMapping;
+import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping;
+import org.eclipse.jpt.jpa.core.context.EmbeddedMapping;
+import org.eclipse.jpt.jpa.core.context.EnumType;
+import org.eclipse.jpt.jpa.core.context.EnumeratedConverter;
+import org.eclipse.jpt.jpa.core.context.FetchType;
+import org.eclipse.jpt.jpa.core.context.IdMapping;
+import org.eclipse.jpt.jpa.core.context.LobConverter;
+import org.eclipse.jpt.jpa.core.context.ManyToManyMapping;
+import org.eclipse.jpt.jpa.core.context.ManyToOneMapping;
+import org.eclipse.jpt.jpa.core.context.OneToManyMapping;
+import org.eclipse.jpt.jpa.core.context.OneToOneMapping;
+import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.TemporalConverter;
+import org.eclipse.jpt.jpa.core.context.TemporalType;
+import org.eclipse.jpt.jpa.core.context.TransientMapping;
+import org.eclipse.jpt.jpa.core.context.VersionMapping;
+import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EnumeratedAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.LobAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.TemporalAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation;
+import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory;
+import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaBasicMappingTests extends ContextModelTestCase
+{
+
+ private ICompilationUnit createTestEntity() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithBasicMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Basic").append(CR);
+ }
+ });
+ }
+ private ICompilationUnit createTestEntityWithBasicMappingFetchOptionalSpecified() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.FETCH_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Basic(fetch=FetchType.EAGER, optional=false)").append(CR);
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithLob() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.LOB);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Lob").append(CR);
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithEnumerated() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ENUMERATED, JPA.ENUM_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Enumerated(EnumType.STRING)").append(CR);
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithTemporal() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.TEMPORAL, JPA.TEMPORAL_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Temporal(TemporalType.TIMESTAMP)").append(CR);
+ }
+ });
+ }
+
+ public JavaBasicMappingTests(String name) {
+ super(name);
+ }
+
+ public void testDefaultBasicGetDefaultFetch() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertEquals(FetchType.EAGER, basicMapping.getDefaultFetch());
+ }
+
+ public void testSpecifiedBasicGetDefaultFetch() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertEquals(FetchType.EAGER, basicMapping.getDefaultFetch());
+ }
+
+ public void testGetFetch() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertEquals(FetchType.EAGER, basicMapping.getFetch());
+
+ basicMapping.setSpecifiedFetch(FetchType.LAZY);
+ assertEquals(FetchType.LAZY, basicMapping.getFetch());
+ }
+
+ public void testGetSpecifiedFetch() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertNull(basicMapping.getSpecifiedFetch());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC);
+ basic.setFetch(org.eclipse.jpt.jpa.core.resource.java.FetchType.LAZY);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(FetchType.LAZY, basicMapping.getSpecifiedFetch());
+ }
+
+ public void testGetSpecifiedFetch2() throws Exception {
+ createTestEntityWithBasicMappingFetchOptionalSpecified();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertEquals(FetchType.EAGER, basicMapping.getSpecifiedFetch());
+ }
+
+ public void testSetSpecifiedFetch() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertNull(basicMapping.getSpecifiedFetch());
+
+ basicMapping.setSpecifiedFetch(FetchType.LAZY);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC);
+
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.FetchType.LAZY, basic.getFetch());
+
+ basicMapping.setSpecifiedFetch(null);
+ assertNotNull(attributeResource.getAnnotation(JPA.BASIC));
+ }
+
+ public void testSetSpecifiedFetch2() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ createOrmXmlFile();
+ getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY);
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertNull(basicMapping.getSpecifiedFetch());
+ assertTrue(basicMapping.isDefault());
+
+ basicMapping.setSpecifiedFetch(FetchType.LAZY);
+
+ JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableProperties().next();
+ BasicAnnotation basic = (BasicAnnotation) resourceAttribute.getAnnotation(JPA.BASIC);
+
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.FetchType.LAZY, basic.getFetch());
+
+ basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertEquals(FetchType.LAZY, basicMapping.getSpecifiedFetch());
+ assertFalse(basicMapping.isDefault());
+
+ basicMapping.setSpecifiedFetch(null);
+ assertNotNull(resourceAttribute.getAnnotation(JPA.BASIC));
+
+ basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertFalse(basicMapping.isDefault());
+ }
+
+ protected void createOrmXmlFile() throws Exception {
+ XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef();
+ mappingFileRef.setFileName(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString());
+ getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef);
+ getPersistenceXmlResource().save(null);
+ }
+
+ public void testSetBasicToDefault() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ assertFalse(basicMapping.isDefault());
+
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+
+ assertFalse(basicMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY);
+
+ assertNotSame(basicMapping, persistentAttribute.getMapping());
+
+ basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertTrue(basicMapping.isDefault());
+ assertEquals("FOO", basicMapping.getColumn().getSpecifiedName());
+ assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testBasicMorphToDefaultBasic() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setConverter(EnumeratedConverter.class);
+ ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(EnumType.STRING);
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY);
+ assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getEnumType());
+
+ assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedFetch());
+ assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedOptional());
+ assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testBasicMorphToId() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals("FOO", ((IdMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ assertEquals(TemporalType.TIME, ((TemporalConverter) ((IdMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType());
+
+ assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testBasicMorphToVersion() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ basicMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+ assertFalse(basicMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ assertEquals(TemporalType.TIME, ((TemporalConverter) ((VersionMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType());
+
+ assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testBasicMorphToEmbedded() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+ assertFalse(basicMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping);
+
+ assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testBasicMorphToEmbeddedId() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+ assertFalse(basicMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping);
+
+ assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testBasicMorphToTransient() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+ assertFalse(basicMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof TransientMapping);
+
+ assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testBasicMorphToOneToOne() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping);
+
+//TODO assertEquals(FetchType.EAGER, ((IOneToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch());
+// assertEquals(Boolean.FALSE, ((IOneToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional());
+ assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testBasicMorphToOneToMany() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping);
+
+//TODO assertEquals(FetchType.EAGER, ((IOneToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch());
+// assertNotNull(attributeResource.mappingAnnotation(OneToMany.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+ public void testBasicMorphToManyToOne() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping);
+
+//TODO assertEquals(FetchType.EAGER, ((IManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch());
+// assertEquals(Boolean.FALSE, ((IManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional());
+ assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testBasicMorphToManyToMany() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertFalse(basicMapping.isDefault());
+ basicMapping.getColumn().setSpecifiedName("FOO");
+ attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+ basicMapping.setSpecifiedFetch(FetchType.EAGER);
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+ assertFalse(basicMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping);
+
+//TODO assertEquals(FetchType.EAGER, ((IManyToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch());
+// assertNotNull(attributeResource.mappingAnnotation(ManyToMany.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testDefaultBasicGetDefaultOptional() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertEquals(true, basicMapping.isDefaultOptional());
+ }
+
+ public void testSpecifiedBasicGetDefaultOptional() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertEquals(true, basicMapping.isDefaultOptional());
+ }
+
+ public void testGetOptional() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertEquals(true, basicMapping.isOptional());
+
+ basicMapping.setSpecifiedOptional(Boolean.TRUE);
+ assertEquals(true, basicMapping.isOptional());
+ }
+
+ public void testGetSpecifiedOptional() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertNull(basicMapping.getSpecifiedOptional());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC);
+ basic.setOptional(Boolean.FALSE);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional());
+ }
+
+ public void testGetSpecifiedOptional2() throws Exception {
+ createTestEntityWithBasicMappingFetchOptionalSpecified();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional());
+ }
+
+ public void testSetSpecifiedOptional() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertNull(basicMapping.getSpecifiedOptional());
+
+ basicMapping.setSpecifiedOptional(Boolean.FALSE);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC);
+
+ assertEquals(Boolean.FALSE, basic.getOptional());
+
+ basicMapping.setSpecifiedOptional(null);
+ assertNotNull(attributeResource.getAnnotation(JPA.BASIC));
+ }
+
+ public void testSetSpecifiedOptional2() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertNull(basicMapping.getSpecifiedOptional());
+ assertTrue(basicMapping.isDefault());
+
+ basicMapping.setSpecifiedOptional(Boolean.TRUE);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC);
+
+ assertEquals(Boolean.TRUE, basic.getOptional());
+
+ basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertEquals(Boolean.TRUE, basicMapping.getSpecifiedOptional());
+ assertFalse(basicMapping.isDefault());
+
+ basicMapping.setSpecifiedOptional(null);
+ assertNotNull(attributeResource.getAnnotation(JPA.BASIC));
+
+ basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertFalse(basicMapping.isDefault());
+ }
+
+
+ public void testGetSpecifiedOptionalUpdatesFromResourceModelChange() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertNull(basicMapping.getSpecifiedOptional());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC);
+ basic.setOptional(Boolean.FALSE);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional());
+
+ basic.setOptional(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(basicMapping.getSpecifiedOptional());
+ assertFalse(basicMapping.isDefault());
+ assertSame(basicMapping, persistentAttribute.getMapping());
+
+ basic.setOptional(Boolean.FALSE);
+ attributeResource.setPrimaryAnnotation(null, EmptyIterable.<String>instance());
+ getJpaProject().synchronizeContextModel();
+
+ assertTrue(persistentAttribute.getMapping().isDefault());
+ assertEquals(true, ((BasicMapping) persistentAttribute.getMapping()).isOptional());
+ }
+
+
+ public void testIsLob() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertFalse(basicMapping.getConverter().getType() == LobConverter.class);
+ }
+
+ public void testIsLob2() throws Exception {
+ createTestEntityWithLob();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertTrue(basicMapping.getConverter().getType() == LobConverter.class);
+ }
+
+ public void testSetLob() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ basicMapping.setConverter(LobConverter.class);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+
+ basicMapping.setConverter(null);
+ assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testIsLobUpdatesFromResourceModelChange() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertFalse(basicMapping.getConverter().getType() == LobConverter.class);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+
+ assertTrue(basicMapping.getConverter().getType() == LobConverter.class);
+
+ attributeResource.removeAnnotation(LobAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+
+ assertFalse(basicMapping.getConverter().getType() == LobConverter.class);
+ }
+
+ public void testDefaultBasicGetDefaultConverter() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertNull(basicMapping.getConverter().getType());
+ }
+
+ public void testSpecifiedBasicGetDefaultConverter() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertNull(basicMapping.getConverter().getType());
+ }
+
+ public void testGetEnumerated() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertNull(basicMapping.getConverter().getType());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ EnumeratedAnnotation enumeratedAnnotation = (EnumeratedAnnotation) attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) basicMapping.getConverter()).getDefaultEnumType());
+
+ enumeratedAnnotation.setValue(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING);
+ getJpaProject().synchronizeContextModel();
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType());
+ }
+
+ public void testGetSpecifiedEnumerated() throws Exception {
+ createTestEntityWithEnumerated();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType());
+ }
+
+ public void testSetSpecifiedEnumerated() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertNull(basicMapping.getConverter().getType());
+
+ basicMapping.setConverter(EnumeratedConverter.class);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+
+ assertNotNull(enumerated);
+ assertEquals(null, enumerated.getValue());
+
+ ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(EnumType.STRING);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING, enumerated.getValue());
+
+ ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(null);
+ assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ assertNull(enumerated.getValue());
+
+ basicMapping.setConverter(null);
+ assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testGetSpecifiedEnumeratedUpdatesFromResourceModelChange() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertNull(basicMapping.getConverter().getType());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME);
+ enumerated.setValue(org.eclipse.jpt.jpa.core.resource.java.EnumType.STRING);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType());
+
+ enumerated.setValue(null);
+ getJpaProject().synchronizeContextModel();
+ assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME));
+ assertNull(((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType());
+ assertFalse(basicMapping.isDefault());
+ assertSame(basicMapping, persistentAttribute.getMapping());
+ }
+
+ public void testGetTemporal() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertEquals(TemporalConverter.class, basicMapping.getConverter().getType());
+ }
+
+ public void testGetTemporal2() throws Exception {
+ createTestEntityWithTemporal();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertEquals(TemporalConverter.class, basicMapping.getConverter().getType());
+ assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) basicMapping.getConverter()).getTemporalType());
+ }
+
+ public void testSetTemporal() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+ assertNull(basicMapping.getConverter().getType());
+
+ basicMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME, temporal.getValue());
+
+ basicMapping.setConverter(null);
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testGetTemporalUpdatesFromResourceModelChange() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertNull(basicMapping.getConverter().getType());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ temporal.setValue(org.eclipse.jpt.jpa.core.resource.java.TemporalType.DATE);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(TemporalConverter.class, basicMapping.getConverter().getType());
+ assertEquals(TemporalType.DATE, ((TemporalConverter) basicMapping.getConverter()).getTemporalType());
+
+ attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(basicMapping.getConverter().getType());
+ assertFalse(basicMapping.isDefault());
+ assertSame(basicMapping, persistentAttribute.getMapping());
+ }
+
+ public void testGetColumn() throws Exception {
+ createTestEntityWithBasicMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedName());
+ assertEquals("id", basicMapping.getColumn().getName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+ column.setName("foo");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals("foo", basicMapping.getColumn().getSpecifiedName());
+ assertEquals("foo", basicMapping.getColumn().getName());
+ assertEquals("id", basicMapping.getColumn().getDefaultName());
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaCascadeTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaCascadeTests.java
new file mode 100644
index 0000000000..23634e6659
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaCascadeTests.java
@@ -0,0 +1,321 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaCascade;
+import org.eclipse.jpt.jpa.core.context.java.JavaOneToOneMapping;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaCascadeTests
+ extends ContextModelTestCase
+{
+ private ICompilationUnit createTestEntityWithOneToOneMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@OneToOne").append(CR);
+ }
+ });
+ }
+
+
+ public JavaCascadeTests(String name) {
+ super(name);
+ }
+
+
+ public void testUpdateCascadeAll() throws Exception {
+ createTestEntityWithOneToOneMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping();
+ JavaCascade cascade = mapping.getCascade();
+
+ assertFalse(cascade.isAll());
+ assertFalse(annotation.isCascadeAll());
+
+ //set all in the resource model, verify context model updated
+ annotation.setCascadeAll(true);
+ getJpaProject().synchronizeContextModel();
+ assertTrue(annotation.isCascadeAll());
+ assertTrue(cascade.isAll());
+
+ //set all to false in the resource model
+ annotation.setCascadeAll(false);
+ getJpaProject().synchronizeContextModel();
+ assertFalse(annotation.isCascadeAll());
+ assertFalse(cascade.isAll());
+ }
+
+ public void testModifyCascadeAll() throws Exception {
+ createTestEntityWithOneToOneMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping();
+ JavaCascade cascade = mapping.getCascade();
+
+ assertFalse(cascade.isAll());
+ assertFalse(annotation.isCascadeAll());
+
+ //set all in the context model, verify resource model updated
+ cascade.setAll(true);
+ assertTrue(annotation.isCascadeAll());
+ assertTrue(cascade.isAll());
+
+ //set all to false in the context model
+ cascade.setAll(false);
+ assertFalse(annotation.isCascadeAll());
+ assertFalse(cascade.isAll());
+ }
+
+ public void testUpdateCascadePersist() throws Exception {
+ createTestEntityWithOneToOneMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping();
+ JavaCascade cascade = mapping.getCascade();
+
+ assertFalse(cascade.isPersist());
+ assertFalse(annotation.isCascadePersist());
+
+ //set persist in the resource model, verify context model updated
+ annotation.setCascadePersist(true);
+ getJpaProject().synchronizeContextModel();
+ assertTrue(annotation.isCascadePersist());
+ assertTrue(cascade.isPersist());
+
+ //set persist to false in the resource model
+ annotation.setCascadePersist(false);
+ getJpaProject().synchronizeContextModel();
+ assertFalse(annotation.isCascadePersist());
+ assertFalse(cascade.isPersist());
+ }
+
+ public void testModifyCascadePersist() throws Exception {
+ createTestEntityWithOneToOneMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping();
+ JavaCascade cascade = mapping.getCascade();
+
+ assertFalse(cascade.isPersist());
+ assertFalse(annotation.isCascadePersist());
+
+ //set persist in the context model, verify resource model updated
+ cascade.setPersist(true);
+ assertTrue(annotation.isCascadePersist());
+ assertTrue(cascade.isPersist());
+
+ //set persist to false in the context model
+ cascade.setPersist(false);
+ assertFalse(annotation.isCascadePersist());
+ assertFalse(cascade.isPersist());
+ }
+
+ public void testUpdateCascadeMerge() throws Exception {
+ createTestEntityWithOneToOneMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping();
+ JavaCascade cascade = mapping.getCascade();
+
+ assertFalse(cascade.isMerge());
+ assertFalse(annotation.isCascadeMerge());
+
+ //set merge in the resource model, verify context model updated
+ annotation.setCascadeMerge(true);
+ getJpaProject().synchronizeContextModel();
+ assertTrue(annotation.isCascadeMerge());
+ assertTrue(cascade.isMerge());
+
+ //set merge to false in the resource model
+ annotation.setCascadeMerge(false);
+ getJpaProject().synchronizeContextModel();
+ assertFalse(annotation.isCascadeMerge());
+ assertFalse(cascade.isMerge());
+ }
+
+ public void testModifyCascadeMerge() throws Exception {
+ createTestEntityWithOneToOneMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping();
+ JavaCascade cascade = mapping.getCascade();
+
+ assertFalse(cascade.isMerge());
+ assertFalse(annotation.isCascadeMerge());
+
+ //set merge in the context model, verify resource model updated
+ cascade.setMerge(true);
+ assertTrue(annotation.isCascadeMerge());
+ assertTrue(cascade.isMerge());
+
+ //set merge to false in the context model
+ cascade.setMerge(false);
+ assertFalse(annotation.isCascadeMerge());
+ assertFalse(cascade.isMerge());
+ }
+
+ public void testUpdateCascadeRemove() throws Exception {
+ createTestEntityWithOneToOneMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping();
+ JavaCascade cascade = mapping.getCascade();
+
+ assertFalse(cascade.isRemove());
+ assertFalse(annotation.isCascadeRemove());
+
+ //set remove in the resource model, verify context model updated
+ annotation.setCascadeRemove(true);
+ getJpaProject().synchronizeContextModel();
+ assertTrue(annotation.isCascadeRemove());
+ assertTrue(cascade.isRemove());
+
+ //set remove to false in the resource model
+ annotation.setCascadeRemove(false);
+ getJpaProject().synchronizeContextModel();
+ assertFalse(annotation.isCascadeRemove());
+ assertFalse(cascade.isRemove());
+ }
+
+ public void testModifyCascadeRemove() throws Exception {
+ createTestEntityWithOneToOneMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping();
+ JavaCascade cascade = mapping.getCascade();
+
+ assertFalse(cascade.isRemove());
+ assertFalse(annotation.isCascadeRemove());
+
+ //set remove in the context model, verify resource model updated
+ cascade.setRemove(true);
+ assertTrue(annotation.isCascadeRemove());
+ assertTrue(cascade.isRemove());
+
+ //set remove to false in the context model
+ cascade.setRemove(false);
+ assertFalse(annotation.isCascadeRemove());
+ assertFalse(cascade.isRemove());
+ }
+
+ public void testUpdateCascadeRefresh() throws Exception {
+ createTestEntityWithOneToOneMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping();
+ JavaCascade cascade = mapping.getCascade();
+
+ assertFalse(cascade.isRefresh());
+ assertFalse(annotation.isCascadeRefresh());
+
+ //set refresh in the resource model, verify context model updated
+ annotation.setCascadeRefresh(true);
+ getJpaProject().synchronizeContextModel();
+ assertTrue(annotation.isCascadeRefresh());
+ assertTrue(cascade.isRefresh());
+
+ //set refresh to false in the resource model
+ annotation.setCascadeRefresh(false);
+ getJpaProject().synchronizeContextModel();
+ assertFalse(annotation.isCascadeRefresh());
+ assertFalse(cascade.isRefresh());
+ }
+
+ public void testModifyCascadeRefresh() throws Exception {
+ createTestEntityWithOneToOneMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping();
+ JavaCascade cascade = mapping.getCascade();
+
+ assertFalse(cascade.isRefresh());
+ assertFalse(annotation.isCascadeRefresh());
+
+ //set refresh in the context model, verify resource model updated
+ cascade.setRefresh(true);
+ assertTrue(annotation.isCascadeRefresh());
+ assertTrue(cascade.isRefresh());
+
+ //set refresh to false in the context model
+ cascade.setRefresh(false);
+ assertFalse(annotation.isCascadeRefresh());
+ assertFalse(cascade.isRefresh());
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaColumnTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaColumnTests.java
new file mode 100644
index 0000000000..d245552243
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaColumnTests.java
@@ -0,0 +1,843 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.context.BasicMapping;
+import org.eclipse.jpt.jpa.core.context.Entity;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyBaseColumn;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyColumn;
+import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaColumnTests extends ContextModelTestCase
+{
+ private static final String COLUMN_NAME = "MY_COLUMN";
+ private static final String TABLE_NAME = "MY_TABLE";
+ private static final String COLUMN_DEFINITION = "MY_COLUMN_DEFINITION";
+
+
+ private ICompilationUnit createTestEntity() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithDefaultBasicColumn() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.COLUMN);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Column(name=\"" + COLUMN_NAME + "\")");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithBasicColumnTableSet() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.COLUMN);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Basic");
+ sb.append("@Column(table=\"" + TABLE_NAME + "\")");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithBasicColumnColumnDefinitionSet() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.COLUMN);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Basic");
+ sb.append("@Column(columnDefinition=\"" + COLUMN_DEFINITION + "\")");
+ }
+ });
+ }
+
+ public JavaColumnTests(String name) {
+ super(name);
+ }
+
+ public void testGetSpecifiedNameNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedName());
+ }
+
+ public void testGetSpecifiedName() throws Exception {
+ createTestEntityWithDefaultBasicColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(COLUMN_NAME, basicMapping.getColumn().getSpecifiedName());
+ }
+
+ public void testGetDefaultNameSpecifiedNameNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(basicMapping.getPersistentAttribute().getName(), basicMapping.getColumn().getDefaultName());
+ assertEquals("id", basicMapping.getColumn().getDefaultName());
+ }
+
+ public void testGetDefaultName() throws Exception {
+ createTestEntityWithDefaultBasicColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+ assertEquals("id", basicMapping.getColumn().getDefaultName());
+
+ basicMapping.getColumn().setSpecifiedName("foo");
+ assertEquals("id", basicMapping.getColumn().getDefaultName());
+ }
+
+ public void testGetNameSpecifiedNameNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals("id", basicMapping.getColumn().getName());
+ }
+
+ public void testGetName() throws Exception {
+ createTestEntityWithDefaultBasicColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(COLUMN_NAME, basicMapping.getColumn().getName());
+ }
+
+ public void testSetSpecifiedName() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ basicMapping.getColumn().setSpecifiedName("foo");
+
+ assertEquals("foo", basicMapping.getColumn().getSpecifiedName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN);
+
+ assertEquals("foo", column.getName());
+ }
+
+ public void testSetSpecifiedNameNull() throws Exception {
+ createTestEntityWithDefaultBasicColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ basicMapping.getColumn().setSpecifiedName(null);
+
+ assertNull(basicMapping.getColumn().getSpecifiedName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(JPA.COLUMN));
+ }
+
+ public void testGetNameUpdatesFromResourceChange() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+
+ columnAnnotation.setName("foo");
+ getJpaProject().synchronizeContextModel();
+ assertEquals("foo", basicMapping.getColumn().getSpecifiedName());
+ assertEquals("foo", basicMapping.getColumn().getName());
+
+ columnAnnotation.setName(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(basicMapping.getColumn().getSpecifiedName());
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ public void testGetSpecifiedTableNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedTable());
+ }
+
+ public void testGetSpecifiedTable() throws Exception {
+ createTestEntityWithBasicColumnTableSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(TABLE_NAME, basicMapping.getColumn().getSpecifiedTable());
+ }
+
+ public void testGetDefaultTableSpecifiedTableNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(((Entity) basicMapping.getTypeMapping()).getName(), basicMapping.getColumn().getDefaultTable());
+ assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable());
+ }
+
+ public void testGetDefaultTable() throws Exception {
+ createTestEntityWithDefaultBasicColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+ assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable());
+
+ basicMapping.getColumn().setSpecifiedTable("foo");
+ assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable());
+ }
+
+ public void testGetTable() throws Exception {
+ createTestEntityWithBasicColumnTableSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(TABLE_NAME, basicMapping.getColumn().getTable());
+ }
+
+ public void testSetSpecifiedTable() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ basicMapping.getColumn().setSpecifiedTable("foo");
+
+ assertEquals("foo", basicMapping.getColumn().getSpecifiedTable());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN);
+
+ assertEquals("foo", column.getTable());
+ }
+
+ public void testSetSpecifiedTableNull() throws Exception {
+ createTestEntityWithBasicColumnTableSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ basicMapping.getColumn().setSpecifiedTable(null);
+
+ assertNull(basicMapping.getColumn().getSpecifiedTable());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(JPA.COLUMN));
+ }
+
+ public void testGetTableUpdatesFromResourceChange() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedTable());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+
+ column.setTable("foo");
+ getJpaProject().synchronizeContextModel();
+ assertEquals("foo", basicMapping.getColumn().getSpecifiedTable());
+ assertEquals("foo", basicMapping.getColumn().getTable());
+
+ column.setTable(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(basicMapping.getColumn().getSpecifiedTable());
+ }
+
+ public void testGetColumnDefinition() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(COLUMN_DEFINITION, basicMapping.getColumn().getColumnDefinition());
+ }
+
+ public void testSetColumnDefinition() throws Exception {
+ createTestEntityWithBasicColumnTableSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ basicMapping.getColumn().setColumnDefinition("foo");
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN);
+
+ assertEquals("foo", column.getColumnDefinition());
+
+ basicMapping.getColumn().setColumnDefinition(null);
+ assertNull(column.getColumnDefinition());
+ }
+
+ public void testGetColumnDefinitionUpdatesFromResourceChange() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getColumnDefinition());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+
+ column.setColumnDefinition("foo");
+ getJpaProject().synchronizeContextModel();
+ assertEquals("foo", basicMapping.getColumn().getColumnDefinition());
+
+ column.setColumnDefinition(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(basicMapping.getColumn().getColumnDefinition());
+
+ }
+
+ public void testGetLength() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, basicMapping.getColumn().getLength());
+ basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(55));
+ assertEquals(55, basicMapping.getColumn().getLength());
+ }
+
+ public void testGetDefaultLength() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, basicMapping.getColumn().getDefaultLength());
+ basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(55));
+
+ assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, basicMapping.getColumn().getDefaultLength());
+ }
+
+ public void testGetSpecifiedLength() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedLength());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+ columnAnnotation.setLength(Integer.valueOf(66));
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedLength());
+ assertEquals(66, basicMapping.getColumn().getLength());
+
+ columnAnnotation.setLength(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(basicMapping.getColumn().getSpecifiedLength());
+ }
+
+ public void testSetSpecifiedLength() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedLength());
+
+ basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(100));
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN);
+
+ assertEquals(Integer.valueOf(100), columnAnnotation.getLength());
+
+ basicMapping.getColumn().setColumnDefinition(null);
+ basicMapping.getColumn().setSpecifiedLength(null);
+
+ assertNull(columnAnnotation.getLength());
+ assertNull(attributeResource.getAnnotation(JPA.COLUMN));
+ }
+
+ public void testGetPrecision() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, basicMapping.getColumn().getPrecision());
+ basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(55));
+ assertEquals(55, basicMapping.getColumn().getPrecision());
+ }
+
+ public void testGetDefaultPrecision() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, basicMapping.getColumn().getDefaultPrecision());
+ basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(55));
+
+ assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, basicMapping.getColumn().getDefaultPrecision());
+ }
+
+ public void testGetSpecifiedPrecision() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedPrecision());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+ columnAnnotation.setPrecision(Integer.valueOf(66));
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedPrecision());
+ assertEquals(66, basicMapping.getColumn().getPrecision());
+
+ columnAnnotation.setPrecision(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(basicMapping.getColumn().getSpecifiedPrecision());
+ }
+
+ public void testSetSpecifiedPrecision() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedPrecision());
+
+ basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(100));
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN);
+
+ assertEquals(Integer.valueOf(100), columnAnnotation.getPrecision());
+
+ basicMapping.getColumn().setColumnDefinition(null);
+ basicMapping.getColumn().setSpecifiedPrecision(null);
+
+ assertNull(columnAnnotation.getPrecision());
+ assertNull(attributeResource.getAnnotation(JPA.COLUMN));
+ }
+
+ public void testGetScale() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyColumn.DEFAULT_SCALE, basicMapping.getColumn().getScale());
+ basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(55));
+ assertEquals(55, basicMapping.getColumn().getScale());
+ }
+
+ public void testGetDefaultScale() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyColumn.DEFAULT_SCALE, basicMapping.getColumn().getDefaultScale());
+ basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(55));
+
+ assertEquals(ReadOnlyColumn.DEFAULT_SCALE, basicMapping.getColumn().getDefaultScale());
+ }
+
+ public void testGetSpecifiedScale() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedScale());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+ columnAnnotation.setScale(Integer.valueOf(66));
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedScale());
+ assertEquals(66, basicMapping.getColumn().getScale());
+
+ columnAnnotation.setScale(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(basicMapping.getColumn().getSpecifiedScale());
+ }
+
+ public void testSetSpecifiedScale() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedScale());
+
+ basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(100));
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN);
+
+ assertEquals(Integer.valueOf(100), columnAnnotation.getScale());
+
+ basicMapping.getColumn().setColumnDefinition(null);
+ basicMapping.getColumn().setSpecifiedScale(null);
+
+ assertNull(columnAnnotation.getScale());
+ assertNull(attributeResource.getAnnotation(JPA.COLUMN));
+ }
+
+ public void testGetUnique() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isUnique());
+ basicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE);
+ assertEquals(true, basicMapping.getColumn().isUnique());
+ }
+
+ public void testGetDefaultUnique() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isDefaultUnique());
+ basicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE);
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isDefaultUnique());
+ }
+
+ public void testGetSpecifiedUnique() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedUnique());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+ columnAnnotation.setUnique(Boolean.TRUE);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedUnique());
+ assertEquals(true, basicMapping.getColumn().isUnique());
+
+ columnAnnotation.setUnique(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(basicMapping.getColumn().getSpecifiedUnique());
+ }
+
+ public void testSetSpecifiedUnique() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedUnique());
+
+ basicMapping.getColumn().setSpecifiedUnique(Boolean.FALSE);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN);
+
+ assertEquals(Boolean.FALSE, columnAnnotation.getUnique());
+
+ basicMapping.getColumn().setColumnDefinition(null);
+ basicMapping.getColumn().setSpecifiedUnique(null);
+
+ assertNull(columnAnnotation.getUnique());
+ assertNull(attributeResource.getAnnotation(JPA.COLUMN));
+ }
+
+ public void testGetInsertable() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isInsertable());
+ basicMapping.getColumn().setSpecifiedInsertable(Boolean.TRUE);
+ assertEquals(true, basicMapping.getColumn().isInsertable());
+ }
+
+ public void testGetDefaultInsertable() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isDefaultInsertable());
+ basicMapping.getColumn().setSpecifiedInsertable(Boolean.TRUE);
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isDefaultInsertable());
+ }
+
+ public void testGetSpecifiedInsertable() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedInsertable());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+ columnAnnotation.setInsertable(Boolean.TRUE);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedInsertable());
+ assertEquals(true, basicMapping.getColumn().isInsertable());
+
+ columnAnnotation.setInsertable(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(basicMapping.getColumn().getSpecifiedInsertable());
+ }
+
+ public void testSetSpecifiedInsertable() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedInsertable());
+
+ basicMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN);
+
+ assertEquals(Boolean.FALSE, columnAnnotation.getInsertable());
+
+ basicMapping.getColumn().setColumnDefinition(null);
+ basicMapping.getColumn().setSpecifiedInsertable(null);
+
+ assertNull(columnAnnotation.getInsertable());
+ assertNull(attributeResource.getAnnotation(JPA.COLUMN));
+ }
+
+ public void testGetNullable() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isNullable());
+ basicMapping.getColumn().setSpecifiedNullable(Boolean.TRUE);
+ assertEquals(true, basicMapping.getColumn().isNullable());
+ }
+
+ public void testGetDefaultNullable() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isDefaultNullable());
+ basicMapping.getColumn().setSpecifiedNullable(Boolean.TRUE);
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isDefaultNullable());
+ }
+
+ public void testGetSpecifiedNullable() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedNullable());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+ columnAnnotation.setNullable(Boolean.TRUE);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedNullable());
+ assertEquals(true, basicMapping.getColumn().isNullable());
+
+ columnAnnotation.setNullable(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(basicMapping.getColumn().getSpecifiedNullable());
+ }
+
+ public void testSetSpecifiedNullable() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedNullable());
+
+ basicMapping.getColumn().setSpecifiedNullable(Boolean.FALSE);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN);
+
+ assertEquals(Boolean.FALSE, columnAnnotation.getNullable());
+
+ basicMapping.getColumn().setColumnDefinition(null);
+ basicMapping.getColumn().setSpecifiedNullable(null);
+
+ assertNull(columnAnnotation.getNullable());
+ assertNull(attributeResource.getAnnotation(JPA.COLUMN));
+ }
+
+ public void testGetUpdatable() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isUpdatable());
+ basicMapping.getColumn().setSpecifiedUpdatable(Boolean.TRUE);
+ assertEquals(true, basicMapping.getColumn().isUpdatable());
+ }
+
+ public void testGetDefaultUpdatable() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isDefaultUpdatable());
+ basicMapping.getColumn().setSpecifiedUpdatable(Boolean.TRUE);
+
+ assertEquals(ReadOnlyBaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isDefaultUpdatable());
+ }
+
+ public void testGetSpecifiedUpdatable() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedUpdatable());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+ columnAnnotation.setUpdatable(Boolean.TRUE);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedUpdatable());
+ assertEquals(true, basicMapping.getColumn().isUpdatable());
+
+ columnAnnotation.setUpdatable(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(basicMapping.getColumn().getSpecifiedUpdatable());
+ }
+
+ public void testSetSpecifiedUpdatable() throws Exception {
+ createTestEntityWithBasicColumnColumnDefinitionSet();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping();
+
+ assertNull(basicMapping.getColumn().getSpecifiedUpdatable());
+
+ basicMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN);
+
+ assertEquals(Boolean.FALSE, columnAnnotation.getUpdatable());
+
+ basicMapping.getColumn().setColumnDefinition(null);
+ basicMapping.getColumn().setSpecifiedUpdatable(null);
+
+ assertNull(columnAnnotation.getUpdatable());
+ assertNull(attributeResource.getAnnotation(JPA.COLUMN));
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java
new file mode 100644
index 0000000000..e37119eb0d
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java
@@ -0,0 +1,458 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.context.DiscriminatorColumn;
+import org.eclipse.jpt.jpa.core.context.DiscriminatorType;
+import org.eclipse.jpt.jpa.core.context.InheritanceType;
+import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.resource.java.DiscriminatorColumnAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaDiscriminatorColumnTests extends ContextModelTestCase
+{
+ private static final String DISCRIMINATOR_COLUMN_NAME = "MY_DISCRIMINATOR_COLUMN";
+ private static final String COLUMN_DEFINITION = "MY_COLUMN_DEFINITION";
+
+
+ private ICompilationUnit createTestEntity() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithDiscriminatorColumn() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.DISCRIMINATOR_COLUMN);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ sb.append("@DiscriminatorColumn(name=\"" + DISCRIMINATOR_COLUMN_NAME + "\")");
+ }
+ });
+ }
+
+ private void createTestAbstractEntity() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public abstract class ").append(TYPE_NAME).append(" ");
+ sb.append("{}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter);
+ }
+
+ private void createTestSubType() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class ").append("AnnotationTestTypeChild").append(" ");
+ sb.append("extends " + TYPE_NAME + " ");
+ sb.append("{}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter);
+ }
+
+
+ public JavaDiscriminatorColumnTests(String name) {
+ super(name);
+ }
+
+ public void testGetSpecifiedNameNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName());
+ }
+
+ public void testGetSpecifiedName() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(DISCRIMINATOR_COLUMN_NAME, getJavaEntity().getDiscriminatorColumn().getSpecifiedName());
+ }
+
+ public void testGetDefaultNameSpecifiedNameNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultName());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName());
+ }
+
+ public void testGetDefaultName() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultName());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName());
+
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedName("foo");
+ assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName());
+ }
+
+ public void testGetNameSpecifiedNameNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(null, getJavaEntity().getDiscriminatorColumn().getName());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getName());
+ }
+
+ public void testGetName() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(DISCRIMINATOR_COLUMN_NAME, getJavaEntity().getDiscriminatorColumn().getName());
+ }
+
+ public void testSetSpecifiedName() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedName("foo");
+
+ assertEquals("foo", getJavaEntity().getDiscriminatorColumn().getSpecifiedName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN);
+
+ assertEquals("foo", discriminatorColumn.getName());
+ }
+
+ public void testSetSpecifiedNameNull() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null);
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN);
+
+ assertNull(discriminatorColumn);
+ }
+
+ public void testGetDefaultDiscriminatorType() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultDiscriminatorType());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertEquals(DiscriminatorType.STRING, getJavaEntity().getDiscriminatorColumn().getDefaultDiscriminatorType());
+ }
+
+ public void testGetDiscriminatorType() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(DiscriminatorType.STRING, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType());
+
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR);
+ assertEquals(DiscriminatorType.CHAR, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType());
+ }
+
+ public void testGetSpecifiedDiscriminatorType() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN);
+ discriminatorColumn.setDiscriminatorType(org.eclipse.jpt.jpa.core.resource.java.DiscriminatorType.CHAR);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(DiscriminatorType.CHAR, getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType());
+ }
+
+ public void testSetSpecifiedDiscriminatorType() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType());
+
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN);
+
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.DiscriminatorType.CHAR, discriminatorColumn.getDiscriminatorType());
+
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null);
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(null);
+ assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN));
+ }
+
+ public void testGetDiscriminatorTypeUpdatesFromResourceChange() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN);
+
+ column.setDiscriminatorType(org.eclipse.jpt.jpa.core.resource.java.DiscriminatorType.INTEGER);
+ getJpaProject().synchronizeContextModel();
+ assertEquals(DiscriminatorType.INTEGER, getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType());
+ assertEquals(DiscriminatorType.INTEGER, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType());
+
+ column.setDiscriminatorType(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType());
+ assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType());
+ }
+
+ public void testGetLength() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(0, getJavaEntity().getDiscriminatorColumn().getLength());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getLength());
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(55));
+ assertEquals(55, getJavaEntity().getDiscriminatorColumn().getLength());
+ }
+
+ public void testGetDefaultLength() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(0, getJavaEntity().getDiscriminatorColumn().getDefaultLength());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getDefaultLength());
+
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(55));
+
+ assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getDefaultLength());
+ }
+
+ public void testGetSpecifiedLength() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN);
+ discriminatorColumn.setLength(Integer.valueOf(66));
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(Integer.valueOf(66), getJavaEntity().getDiscriminatorColumn().getSpecifiedLength());
+ assertEquals(66, getJavaEntity().getDiscriminatorColumn().getLength());
+ discriminatorColumn.setName(null);
+ discriminatorColumn.setLength(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength());
+ }
+
+ public void testSetSpecifiedLength() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength());
+
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(100));
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN);
+
+ assertEquals(Integer.valueOf(100), discriminatorColumn.getLength());
+
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null);
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(null);
+ assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN));
+ }
+
+ public void testGetLengthUpdatesFromResourceChange() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN);
+
+ column.setLength(Integer.valueOf(78));
+ getJpaProject().synchronizeContextModel();
+ assertEquals(Integer.valueOf(78), getJavaEntity().getDiscriminatorColumn().getSpecifiedLength());
+ assertEquals(78, getJavaEntity().getDiscriminatorColumn().getLength());
+
+ column.setLength(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength());
+ assertEquals(0, getJavaEntity().getDiscriminatorColumn().getLength());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getLength());
+ }
+
+
+ public void testGetColumnDefinition() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getColumnDefinition());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN);
+ column.setColumnDefinition(COLUMN_DEFINITION);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(COLUMN_DEFINITION, getJavaEntity().getDiscriminatorColumn().getColumnDefinition());
+
+ column.setColumnDefinition(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getColumnDefinition());
+
+ typeResource.removeAnnotation(JPA.DISCRIMINATOR_COLUMN);
+ }
+
+ public void testSetColumnDefinition() throws Exception {
+ createTestEntityWithDiscriminatorColumn();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().getDiscriminatorColumn().setColumnDefinition("foo");
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN);
+
+ assertEquals("foo", column.getColumnDefinition());
+
+ getJavaEntity().getDiscriminatorColumn().setColumnDefinition(null);
+ column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN);
+ assertNull(column.getColumnDefinition());
+ }
+
+ public void testDefaults() throws Exception {
+ createTestAbstractEntity();
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(PACKAGE_NAME + "." + "AnnotationTestTypeChild");
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping();
+ JavaEntity childEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping();
+
+ //test defaults with single-table inheritance, no specified discriminator column set
+ assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy());
+ assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName());
+ assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength());
+ assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType());
+
+ assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy());
+ assertEquals(DiscriminatorColumn.DEFAULT_NAME, childEntity.getDiscriminatorColumn().getDefaultName());
+ assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, childEntity.getDiscriminatorColumn().getDefaultLength());
+ assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType());
+
+
+ //test defaults with single-table inheritance, specified discriminator column set on root
+ abstractEntity.getDiscriminatorColumn().setSpecifiedName("DTYPE2");
+ abstractEntity.getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(5));
+ abstractEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR);
+
+ assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy());
+ assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName());
+ assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength());
+ assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType());
+ assertEquals("DTYPE2", abstractEntity.getDiscriminatorColumn().getSpecifiedName());
+ assertEquals(Integer.valueOf(5), abstractEntity.getDiscriminatorColumn().getSpecifiedLength());
+ assertEquals(DiscriminatorType.CHAR, abstractEntity.getDiscriminatorColumn().getSpecifiedDiscriminatorType());
+
+ assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy());
+ assertEquals("DTYPE2", childEntity.getDiscriminatorColumn().getDefaultName());
+ assertEquals(5, childEntity.getDiscriminatorColumn().getDefaultLength());
+ assertEquals(DiscriminatorType.CHAR, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType());
+ assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedName());
+ assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedLength());
+ assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedDiscriminatorType());
+
+
+ //test defaults with table-per-class inheritance, discriminator column does not apply
+ abstractEntity.getDiscriminatorColumn().setSpecifiedName(null);
+ abstractEntity.getDiscriminatorColumn().setSpecifiedLength(null);
+ abstractEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(null);
+ abstractEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS);
+
+ assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getInheritanceStrategy());
+ assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultName());
+ assertEquals(0, abstractEntity.getDiscriminatorColumn().getDefaultLength());
+ assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType());
+
+ assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getDefaultInheritanceStrategy());
+ assertEquals(null, childEntity.getDiscriminatorColumn().getDefaultName());
+ assertEquals(0, childEntity.getDiscriminatorColumn().getDefaultLength());
+ assertEquals(null, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType());
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddableTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddableTests.java
new file mode 100644
index 0000000000..1d97e61490
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddableTests.java
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.Embeddable;
+import org.eclipse.jpt.jpa.core.context.Entity;
+import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
+import org.eclipse.jpt.jpa.core.internal.context.java.JavaNullTypeMapping;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddableAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaEmbeddableTests extends ContextModelTestCase
+{
+
+ private ICompilationUnit createTestEmbeddable() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.EMBEDDABLE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Embeddable");
+ }
+ });
+ }
+
+
+ public JavaEmbeddableTests(String name) {
+ super(name);
+ }
+
+ public void testMorphToEntity() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY);
+ assertTrue(getJavaPersistentType().getMapping() instanceof Entity);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToMappedSuperclass() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaPersistentType().setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY);
+ assertTrue(getJavaPersistentType().getMapping() instanceof MappedSuperclass);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToNull() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY);
+ assertTrue(getJavaPersistentType().getMapping() instanceof JavaNullTypeMapping);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testEmbeddable() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertTrue(getJavaPersistentType().getMapping() instanceof Embeddable);
+ }
+
+ public void testOverridableAttributeNames() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping();
+ Iterator<String> overridableAttributeNames = embeddable.overridableAttributeNames();
+ assertEquals(overridableAttributeNames.next(), "id");
+ assertEquals(overridableAttributeNames.next(), "name");
+ assertFalse(overridableAttributeNames.hasNext());
+ }
+
+ public void testOverridableAssociationNames() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping();
+ Iterator<String> overridableAssociationNames = embeddable.overridableAssociationNames();
+ assertFalse(overridableAssociationNames.hasNext());
+ }
+
+ public void testTableNameIsInvalid() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping();
+
+ assertFalse(embeddable.tableNameIsInvalid(FULLY_QUALIFIED_TYPE_NAME));
+ assertFalse(embeddable.tableNameIsInvalid("FOO"));
+ }
+
+ public void testAttributeMappingKeyAllowed() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping();
+ assertTrue(embeddable.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY));
+ assertTrue(embeddable.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY));
+ assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY));
+ assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY));
+ assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY));
+ assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY));
+ assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY));
+ assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY));
+ assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY));
+ assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY));
+ }
+
+
+ public void testAssociatedTables() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping();
+
+ assertFalse(embeddable.associatedTables().hasNext());
+ }
+
+ public void testAssociatedTablesIncludingInherited() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping();
+
+ assertFalse(embeddable.allAssociatedTables().hasNext());
+ }
+
+ public void testAssociatedTableNamesIncludingInherited() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping();
+
+ assertFalse(embeddable.allAssociatedTableNames().hasNext());
+ }
+
+ //TODO need to create a subclass mappedSuperclass and test this
+ public void testAllOverridableAssociationNames() throws Exception {
+ createTestEmbeddable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping();
+ Iterator<String> overridableAssociationNames = embeddable.overridableAssociationNames();
+ assertFalse(overridableAssociationNames.hasNext());
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java
new file mode 100644
index 0000000000..07dde40292
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java
@@ -0,0 +1,659 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer;
+import org.eclipse.jpt.jpa.core.context.BasicMapping;
+import org.eclipse.jpt.jpa.core.context.Embeddable;
+import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping;
+import org.eclipse.jpt.jpa.core.context.EmbeddedMapping;
+import org.eclipse.jpt.jpa.core.context.IdMapping;
+import org.eclipse.jpt.jpa.core.context.ManyToManyMapping;
+import org.eclipse.jpt.jpa.core.context.ManyToOneMapping;
+import org.eclipse.jpt.jpa.core.context.OneToManyMapping;
+import org.eclipse.jpt.jpa.core.context.OneToOneMapping;
+import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.TransientMapping;
+import org.eclipse.jpt.jpa.core.context.VersionMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverrideContainer;
+import org.eclipse.jpt.jpa.core.context.java.JavaEmbeddedIdMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaEmbeddedMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping;
+import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.AttributeOverridesAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaEmbeddedIdMappingTests extends ContextModelTestCase
+{
+
+ public static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable";
+ public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME;
+
+ private ICompilationUnit createTestEntityWithEmbeddedIdMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED_ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@EmbeddedId").append(CR);
+ sb.append(CR);
+ sb.append(" private " + EMBEDDABLE_TYPE_NAME +" myEmbeddedId;").append(CR);
+ sb.append(CR);
+ }
+ });
+ }
+
+ private void createEmbeddableType() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.EMBEDDABLE);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Embeddable");
+ sb.append(CR);
+ sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {");
+ sb.append(CR);
+ sb.append(" private String city;").append(CR);
+ sb.append(CR);
+ sb.append(" private String state;").append(CR);
+ sb.append(CR);
+ sb.append(" ");
+ sb.append("}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter);
+ }
+
+
+ public JavaEmbeddedIdMappingTests(String name) {
+ super(name);
+ }
+
+ public void testMorphToBasicMapping() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedIdMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof BasicMapping);
+ assertFalse(persistentAttribute.getMapping().isDefault());
+
+ assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToDefault() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedIdMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(((JavaEmbeddedMapping) persistentAttribute.getMapping()).getAttributeOverrideContainer().overrides().hasNext());
+ assertTrue(persistentAttribute.getMapping().isDefault());
+
+ assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testDefaultEmbeddedIdMapping() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping();
+ assertFalse(embeddedIdMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping);
+ assertTrue(persistentAttribute.getMapping().isDefault());
+
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+ assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping);
+ assertTrue(persistentAttribute.getMapping().isDefault());
+ }
+
+ public void testMorphToVersionMapping() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedIdMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof VersionMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToTransientMapping() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedIdMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof TransientMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToIdMapping() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedIdMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IdMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToEmbeddedMapping() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedIdMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToOneToOneMapping() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedIdMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToOneToManyMapping() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedIdMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToManyToOneMapping() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedIdMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToManyToManyMapping() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedIdMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testSpecifiedAttributeOverrides() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping();
+ JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer();
+ ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ //add an annotation to the resource model and verify the context model is updated
+ AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("BAZ", specifiedAttributeOverrides.next().getName());
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ //move an annotation to the resource model and verify the context model is updated
+ attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAZ", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("BAZ", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+
+ attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertFalse(specifiedAttributeOverrides.hasNext());
+ }
+
+ public void testVirtualAttributeOverrides() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ JavaEmbeddedIdMapping embeddedMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping();
+ JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertEquals("myEmbeddedId", attributeResource.getName());
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME));
+
+ assertEquals(2, attributeOverrideContainer.virtualOverridesSize());
+ ReadOnlyAttributeOverride defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next();
+ assertEquals("city", defaultAttributeOverride.getName());
+ assertEquals("city", defaultAttributeOverride.getColumn().getName());
+ assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable());
+ assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition());
+ assertEquals(true, defaultAttributeOverride.getColumn().isInsertable());
+ assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable());
+ assertEquals(false, defaultAttributeOverride.getColumn().isUnique());
+ assertEquals(true, defaultAttributeOverride.getColumn().isNullable());
+ assertEquals(255, defaultAttributeOverride.getColumn().getLength());
+ assertEquals(0, defaultAttributeOverride.getColumn().getPrecision());
+ assertEquals(0, defaultAttributeOverride.getColumn().getScale());
+
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping();
+
+ BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping();
+ cityMapping.getColumn().setSpecifiedName("FOO");
+ cityMapping.getColumn().setSpecifiedTable("BAR");
+ cityMapping.getColumn().setColumnDefinition("COLUMN_DEF");
+ cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE);
+ cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE);
+ cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE);
+ cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE);
+ cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5));
+ cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6));
+ cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7));
+
+ assertEquals("myEmbeddedId", attributeResource.getName());
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME));
+
+ assertEquals(2, attributeOverrideContainer.virtualOverridesSize());
+ defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next();
+ assertEquals("city", defaultAttributeOverride.getName());
+ assertEquals("FOO", defaultAttributeOverride.getColumn().getName());
+ assertEquals("BAR", defaultAttributeOverride.getColumn().getTable());
+ assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition());
+ assertEquals(false, defaultAttributeOverride.getColumn().isInsertable());
+ assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable());
+ assertEquals(true, defaultAttributeOverride.getColumn().isUnique());
+ assertEquals(false, defaultAttributeOverride.getColumn().isNullable());
+ assertEquals(5, defaultAttributeOverride.getColumn().getLength());
+ assertEquals(6, defaultAttributeOverride.getColumn().getPrecision());
+ assertEquals(7, defaultAttributeOverride.getColumn().getScale());
+
+ cityMapping.getColumn().setSpecifiedName(null);
+ cityMapping.getColumn().setSpecifiedTable(null);
+ cityMapping.getColumn().setColumnDefinition(null);
+ cityMapping.getColumn().setSpecifiedInsertable(null);
+ cityMapping.getColumn().setSpecifiedUpdatable(null);
+ cityMapping.getColumn().setSpecifiedUnique(null);
+ cityMapping.getColumn().setSpecifiedNullable(null);
+ cityMapping.getColumn().setSpecifiedLength(null);
+ cityMapping.getColumn().setSpecifiedPrecision(null);
+ cityMapping.getColumn().setSpecifiedScale(null);
+ defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next();
+ assertEquals("city", defaultAttributeOverride.getName());
+ assertEquals("city", defaultAttributeOverride.getColumn().getName());
+ assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable());
+ assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition());
+ assertEquals(true, defaultAttributeOverride.getColumn().isInsertable());
+ assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable());
+ assertEquals(false, defaultAttributeOverride.getColumn().isUnique());
+ assertEquals(true, defaultAttributeOverride.getColumn().isNullable());
+ assertEquals(255, defaultAttributeOverride.getColumn().getLength());
+ assertEquals(0, defaultAttributeOverride.getColumn().getPrecision());
+ assertEquals(0, defaultAttributeOverride.getColumn().getScale());
+
+ AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ annotation.setName("city");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(1, attributeOverrideContainer.virtualOverridesSize());
+ }
+
+ public void testSpecifiedAttributeOverridesSize() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping();
+ AttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer();
+ assertEquals(0, attributeOverrideContainer.specifiedOverridesSize());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ //add an annotation to the resource model and verify the context model is updated
+ AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("FOO");
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(2, attributeOverrideContainer.specifiedOverridesSize());
+ }
+
+ public void testAttributeOverridesSize() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping();
+ AttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer();
+ assertEquals(2, attributeOverrideContainer.overridesSize());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ //add an annotation to the resource model and verify the context model is updated
+ AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("FOO");
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(4, attributeOverrideContainer.overridesSize());
+
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("city");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(4, attributeOverrideContainer.overridesSize());
+ }
+
+ public void testVirtualAttributeOverridesSize() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping();
+ JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer();
+ assertEquals(2, attributeOverrideContainer.virtualOverridesSize());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ //add an annotation to the resource model and verify the context model is updated
+ AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("FOO");
+
+ assertEquals(2, attributeOverrideContainer.virtualOverridesSize());
+
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("city");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(1, attributeOverrideContainer.virtualOverridesSize());
+
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("state");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(0, attributeOverrideContainer.virtualOverridesSize());
+ }
+
+ public void testAttributeOverrideSetVirtual() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping();
+ JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer();
+ attributeOverrideContainer.virtualOverrides().next().convertToSpecified();
+ attributeOverrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertFalse(attributeOverrides.hasNext());
+
+ attributeOverrideContainer.specifiedOverrides().next().convertToVirtual();
+ attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertFalse(attributeOverrides.hasNext());
+
+ assertEquals("city", attributeOverrideContainer.virtualOverrides().next().getName());
+ assertEquals(1, attributeOverrideContainer.virtualOverridesSize());
+
+ attributeOverrideContainer.specifiedOverrides().next().convertToVirtual();
+ attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ assertFalse(attributeOverrides.hasNext());
+
+ ListIterator<JavaVirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides();
+ assertEquals("city", virtualAttributeOverrides.next().getName());
+ assertEquals("state", virtualAttributeOverrides.next().getName());
+ assertEquals(2, attributeOverrideContainer.virtualOverridesSize());
+ }
+
+ public void testAttributeOverrideSetVirtual2() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping();
+ JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer();
+ ListIterator<JavaVirtualAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides();
+ virtualAttributeOverrides.next();
+ virtualAttributeOverrides.next().convertToSpecified();
+ attributeOverrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertFalse(attributeOverrides.hasNext());
+ }
+
+
+ public void testMoveSpecifiedAttributeOverride() throws Exception {
+ createTestEntityWithEmbeddedIdMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping();
+ JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer();
+ attributeOverrideContainer.virtualOverrides().next().convertToSpecified();
+ attributeOverrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME);
+
+ Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertFalse(attributeOverrides.hasNext());
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddedMappingTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddedMappingTests.java
new file mode 100644
index 0000000000..aed44ba7cf
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEmbeddedMappingTests.java
@@ -0,0 +1,863 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer;
+import org.eclipse.jpt.jpa.core.context.BasicMapping;
+import org.eclipse.jpt.jpa.core.context.Embeddable;
+import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping;
+import org.eclipse.jpt.jpa.core.context.EmbeddedMapping;
+import org.eclipse.jpt.jpa.core.context.IdMapping;
+import org.eclipse.jpt.jpa.core.context.ManyToManyMapping;
+import org.eclipse.jpt.jpa.core.context.ManyToOneMapping;
+import org.eclipse.jpt.jpa.core.context.OneToManyMapping;
+import org.eclipse.jpt.jpa.core.context.OneToOneMapping;
+import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.TransientMapping;
+import org.eclipse.jpt.jpa.core.context.VersionMapping;
+import org.eclipse.jpt.jpa.core.context.VirtualAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverrideContainer;
+import org.eclipse.jpt.jpa.core.context.java.JavaEmbeddedMapping;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping;
+import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.AttributeOverridesAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaEmbeddedMappingTests extends ContextModelTestCase
+{
+
+ public static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable";
+ public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME;
+
+ private ICompilationUnit createTestEntityWithEmbeddedMapping() throws Exception {
+
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Embedded").append(CR);
+ sb.append(" private " + EMBEDDABLE_TYPE_NAME + " myEmbedded;").append(CR);
+ sb.append(CR);
+ }
+ });
+ }
+
+ private void createEmbeddableType() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.EMBEDDABLE);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Embeddable");
+ sb.append(CR);
+ sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {");
+ sb.append(CR);
+ sb.append(" private String city;").append(CR);
+ sb.append(CR);
+ sb.append(" private String state;").append(CR);
+ sb.append(CR);
+ sb.append(" ");
+ sb.append("}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter);
+ }
+
+ private void createTestEntityCustomer() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ID);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.EMBEDDED);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class ").append("Customer").append(" ");
+ sb.append("{").append(CR);
+ sb.append(CR);
+ sb.append(" @Id").append(CR);
+ sb.append(" private String id;").append(CR);
+ sb.append(CR);
+ sb.append(" private String name;").append(CR);
+ sb.append(CR);
+ sb.append(" @Embedded").append(CR);
+ sb.append(" private Address address;").append(CR);
+ sb.append(CR);
+ sb.append("}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter);
+ }
+
+ private void createTestEmbeddableAddress() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.EMBEDDABLE);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.EMBEDDED);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Embeddable");
+ sb.append(CR);
+ sb.append("public class ").append("Address").append(" ");
+ sb.append("{").append(CR);
+ sb.append(CR);
+ sb.append(" private String street;").append(CR);
+ sb.append(CR);
+ sb.append(" private String city;").append(CR);
+ sb.append(CR);
+ sb.append(" private String state;").append(CR);
+ sb.append(CR);
+ sb.append(" @Embedded").append(CR);
+ sb.append(" private ZipCode zipCode;").append(CR);
+ sb.append(CR);
+ sb.append("}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter);
+ }
+
+ private void createTestEmbeddableZipCode() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.EMBEDDABLE);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Embeddable");
+ sb.append(CR);
+ sb.append("public class ").append("ZipCode").append(" ");
+ sb.append("{").append(CR);
+ sb.append(CR);
+ sb.append(" private String zip;").append(CR);
+ sb.append(CR);
+ sb.append(" private String plusfour;").append(CR);
+ sb.append(CR);
+ sb.append("}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter);
+ }
+
+
+ public JavaEmbeddedMappingTests(String name) {
+ super(name);
+ }
+
+ public void testMorphToBasicMapping() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping();
+ assertFalse(embeddedMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof BasicMapping);
+ assertFalse(persistentAttribute.getMapping().isDefault());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToDefault() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(((EmbeddedMapping) persistentAttribute.getMapping()).getAttributeOverrideContainer().overrides().hasNext());
+ assertTrue(persistentAttribute.getMapping().isDefault());
+
+ assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testDefaultEmbeddedMapping() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping();
+ assertFalse(embeddedMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping);
+ assertTrue(persistentAttribute.getMapping().isDefault());
+
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+ assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping);
+ assertTrue(persistentAttribute.getMapping().isDefault());
+ }
+
+ public void testDefaultEmbeddedMappingGenericEmbeddable() throws Exception {
+ createTestEntityWithDefaultEmbeddedMapping();
+ createTestGenericEmbeddable();
+ addXmlClassRef(PACKAGE_NAME + ".Entity1");
+ addXmlClassRef(PACKAGE_NAME + ".Embeddable1");
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ assertTrue(persistentAttribute.getMapping().isDefault());
+ assertNotNull(persistentAttribute.getMapping());
+ assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey());
+ assertTrue(persistentAttribute.getMapping().isDefault());
+ }
+
+ private void createTestEntityWithDefaultEmbeddedMapping() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class Entity1 { ").append(CR);
+ sb.append("private Embeddable1<Integer> myEmbeddable;").append(CR);
+ sb.append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter);
+ }
+
+ private void createTestGenericEmbeddable() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.EMBEDDABLE);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Embeddable");
+ sb.append(CR);
+ sb.append("public class Embeddable1<T> {}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Embeddable1.java", sourceWriter);
+ }
+
+ public void testMorphToVersionMapping() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof VersionMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToTransientMapping() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof TransientMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToIdMapping() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IdMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToEmbeddedIdMapping() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToOneToOneMapping() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToOneToManyMapping() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToManyToOneMapping() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToManyToManyMapping() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ assertFalse(embeddedMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping);
+
+ assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testSpecifiedAttributeOverrides() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping();
+ JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer();
+
+ ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ //add an annotation to the resource model and verify the context model is updated
+ AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("BAZ", specifiedAttributeOverrides.next().getName());
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ //move an annotation to the resource model and verify the context model is updated
+ attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAZ", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("BAZ", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+
+ attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides();
+ assertFalse(specifiedAttributeOverrides.hasNext());
+ }
+
+ public void testVirtualAttributeOverrides() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping();
+ AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertEquals("myEmbedded", attributeResource.getName());
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME));
+
+ assertEquals(2, attributeOverrideContainer.virtualOverridesSize());
+ ReadOnlyAttributeOverride defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next();
+ assertEquals("city", defaultAttributeOverride.getName());
+ assertEquals("city", defaultAttributeOverride.getColumn().getName());
+ assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable());
+ assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition());
+ assertEquals(true, defaultAttributeOverride.getColumn().isInsertable());
+ assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable());
+ assertEquals(false, defaultAttributeOverride.getColumn().isUnique());
+ assertEquals(true, defaultAttributeOverride.getColumn().isNullable());
+ assertEquals(255, defaultAttributeOverride.getColumn().getLength());
+ assertEquals(0, defaultAttributeOverride.getColumn().getPrecision());
+ assertEquals(0, defaultAttributeOverride.getColumn().getScale());
+
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping();
+
+ BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping();
+ cityMapping.getColumn().setSpecifiedName("FOO");
+ cityMapping.getColumn().setSpecifiedTable("BAR");
+ cityMapping.getColumn().setColumnDefinition("COLUMN_DEF");
+ cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE);
+ cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE);
+ cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE);
+ cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE);
+ cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5));
+ cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6));
+ cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7));
+
+ assertEquals("myEmbedded", attributeResource.getName());
+ assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME));
+
+ assertEquals(2, attributeOverrideContainer.virtualOverridesSize());
+ defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next();
+ assertEquals("city", defaultAttributeOverride.getName());
+ assertEquals("FOO", defaultAttributeOverride.getColumn().getName());
+ assertEquals("BAR", defaultAttributeOverride.getColumn().getTable());
+ assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition());
+ assertEquals(false, defaultAttributeOverride.getColumn().isInsertable());
+ assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable());
+ assertEquals(true, defaultAttributeOverride.getColumn().isUnique());
+ assertEquals(false, defaultAttributeOverride.getColumn().isNullable());
+ assertEquals(5, defaultAttributeOverride.getColumn().getLength());
+ assertEquals(6, defaultAttributeOverride.getColumn().getPrecision());
+ assertEquals(7, defaultAttributeOverride.getColumn().getScale());
+
+ cityMapping.getColumn().setSpecifiedName(null);
+ cityMapping.getColumn().setSpecifiedTable(null);
+ cityMapping.getColumn().setColumnDefinition(null);
+ cityMapping.getColumn().setSpecifiedInsertable(null);
+ cityMapping.getColumn().setSpecifiedUpdatable(null);
+ cityMapping.getColumn().setSpecifiedUnique(null);
+ cityMapping.getColumn().setSpecifiedNullable(null);
+ cityMapping.getColumn().setSpecifiedLength(null);
+ cityMapping.getColumn().setSpecifiedPrecision(null);
+ cityMapping.getColumn().setSpecifiedScale(null);
+ defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next();
+ assertEquals("city", defaultAttributeOverride.getName());
+ assertEquals("city", defaultAttributeOverride.getColumn().getName());
+ assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable());
+ assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition());
+ assertEquals(true, defaultAttributeOverride.getColumn().isInsertable());
+ assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable());
+ assertEquals(false, defaultAttributeOverride.getColumn().isUnique());
+ assertEquals(true, defaultAttributeOverride.getColumn().isNullable());
+ assertEquals(255, defaultAttributeOverride.getColumn().getLength());
+ assertEquals(0, defaultAttributeOverride.getColumn().getPrecision());
+ assertEquals(0, defaultAttributeOverride.getColumn().getScale());
+
+ AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ annotation.setName("city");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(1, attributeOverrideContainer.virtualOverridesSize());
+ }
+
+ public void testSpecifiedAttributeOverridesSize() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping();
+ AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer();
+ assertEquals(0, attributeOverrideContainer.specifiedOverridesSize());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ //add an annotation to the resource model and verify the context model is updated
+ AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("FOO");
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(2, attributeOverrideContainer.specifiedOverridesSize());
+ }
+
+ public void testAttributeOverridesSize() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping();
+ AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer();
+ assertEquals(2, attributeOverrideContainer.overridesSize());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ //add an annotation to the resource model and verify the context model is updated
+ AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("FOO");
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(4, attributeOverrideContainer.overridesSize());
+
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("city");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(4, attributeOverrideContainer.overridesSize());
+ }
+
+ public void testVirtualAttributeOverridesSize() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping();
+ AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer();
+ assertEquals(2, attributeOverrideContainer.virtualOverridesSize());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ //add an annotation to the resource model and verify the context model is updated
+ AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(2, attributeOverrideContainer.virtualOverridesSize());
+
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("city");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(1, attributeOverrideContainer.virtualOverridesSize());
+
+ attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("state");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(0, attributeOverrideContainer.virtualOverridesSize());
+ }
+
+ public void testAttributeOverrideSetVirtual() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping();
+ AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer();
+ attributeOverrideContainer.virtualOverrides().next().convertToSpecified();
+ attributeOverrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertFalse(attributeOverrides.hasNext());
+
+ attributeOverrideContainer.specifiedOverrides().next().convertToVirtual();
+ attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertFalse(attributeOverrides.hasNext());
+
+ assertEquals("city", attributeOverrideContainer.virtualOverrides().next().getName());
+ assertEquals(1, attributeOverrideContainer.virtualOverridesSize());
+
+ attributeOverrideContainer.specifiedOverrides().next().convertToVirtual();
+ attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ assertFalse(attributeOverrides.hasNext());
+
+ Iterator<VirtualAttributeOverride> virtualAttributeOverrides = (Iterator<VirtualAttributeOverride>) attributeOverrideContainer.virtualOverrides();
+ assertEquals("city", virtualAttributeOverrides.next().getName());
+ assertEquals("state", virtualAttributeOverrides.next().getName());
+ assertEquals(2, attributeOverrideContainer.virtualOverridesSize());
+ }
+
+ public void testAttributeOverrideSetVirtual2() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping();
+ AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer();
+ ListIterator<VirtualAttributeOverride> virtualAttributeOverrides = (ListIterator<VirtualAttributeOverride>) attributeOverrideContainer.virtualOverrides();
+ virtualAttributeOverrides.next();
+ virtualAttributeOverrides.next().convertToSpecified();
+ attributeOverrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertFalse(attributeOverrides.hasNext());
+ }
+
+ public void testMoveSpecifiedAttributeOverride() throws Exception {
+ createTestEntityWithEmbeddedMapping();
+ createEmbeddableType();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME);
+
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping();
+ AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer();
+ attributeOverrideContainer.virtualOverrides().next().convertToSpecified();
+ attributeOverrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME);
+
+ Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertFalse(attributeOverrides.hasNext());
+ }
+
+ //1.0 projects do not support dot-notation, this tests to make sure that support does not exist
+ public void testNestedVirtualAttributeOverrides() throws Exception {
+ createTestEntityCustomer();
+ createTestEmbeddableAddress();
+ createTestEmbeddableZipCode();
+
+ addXmlClassRef(PACKAGE_NAME + ".Customer");
+ addXmlClassRef(PACKAGE_NAME + ".Address");
+ addXmlClassRef(PACKAGE_NAME + ".ZipCode");
+ ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs();
+ PersistentType customerPersistentType = specifiedClassRefs.next().getJavaPersistentType();
+ EmbeddedMapping embeddedMapping = (EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping();
+ AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer();
+
+ assertEquals(3, attributeOverrideContainer.virtualOverridesSize());
+ ListIterator<VirtualAttributeOverride> virtualAttributeOverrides = (ListIterator<VirtualAttributeOverride>) attributeOverrideContainer.virtualOverrides();
+ ReadOnlyAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("street", virtualAttributeOverride.getName());
+ virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("city", virtualAttributeOverride.getName());
+ virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("state", virtualAttributeOverride.getName());
+ assertEquals(false, virtualAttributeOverrides.hasNext());
+
+
+ PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType();
+ EmbeddedMapping nestedEmbeddedMapping = (EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping();
+ AttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer();
+ assertEquals(2, nestedAttributeOverrideContainer.virtualOverridesSize());
+ virtualAttributeOverrides = (ListIterator<VirtualAttributeOverride>) nestedAttributeOverrideContainer.virtualOverrides();
+ virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("zip", virtualAttributeOverride.getName());
+ virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("plusfour", virtualAttributeOverride.getName());
+
+ PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType();
+ BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping();
+ plusFourMapping.getColumn().setSpecifiedName("BLAH");
+ plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE");
+ plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION");
+ plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE);
+ plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE);
+ plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE);
+ plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE);
+ plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5));
+ plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6));
+ plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7));
+
+ //check the nested embedded (Address.zipCode) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour
+ virtualAttributeOverride = ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour");
+ assertEquals("plusfour", virtualAttributeOverride.getName());
+ assertEquals("BLAH", virtualAttributeOverride.getColumn().getName());
+ assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable());
+ assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition());
+ assertEquals(false, virtualAttributeOverride.getColumn().isInsertable());
+ assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable());
+ assertEquals(true, virtualAttributeOverride.getColumn().isUnique());
+ assertEquals(false, virtualAttributeOverride.getColumn().isNullable());
+ assertEquals(5, virtualAttributeOverride.getColumn().getLength());
+ assertEquals(6, virtualAttributeOverride.getColumn().getPrecision());
+ assertEquals(7, virtualAttributeOverride.getColumn().getScale());
+
+ //check the top-level embedded (Customer.address) attribute override to verify there is no attribute override named zipCode.plusfour
+ virtualAttributeOverride = ((EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getOverrideNamed("zipCode.plusfour");
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEntityTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEntityTests.java
new file mode 100644
index 0000000000..0b34da79c5
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaEntityTests.java
@@ -0,0 +1,3417 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.AccessType;
+import org.eclipse.jpt.jpa.core.context.AssociationOverride;
+import org.eclipse.jpt.jpa.core.context.AssociationOverrideContainer;
+import org.eclipse.jpt.jpa.core.context.AttributeOverride;
+import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer;
+import org.eclipse.jpt.jpa.core.context.BasicMapping;
+import org.eclipse.jpt.jpa.core.context.DiscriminatorType;
+import org.eclipse.jpt.jpa.core.context.Embeddable;
+import org.eclipse.jpt.jpa.core.context.Entity;
+import org.eclipse.jpt.jpa.core.context.IdMapping;
+import org.eclipse.jpt.jpa.core.context.InheritanceType;
+import org.eclipse.jpt.jpa.core.context.JoinColumn;
+import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
+import org.eclipse.jpt.jpa.core.context.NamedNativeQuery;
+import org.eclipse.jpt.jpa.core.context.NamedQuery;
+import org.eclipse.jpt.jpa.core.context.OneToOneMapping;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.PrimaryKeyJoinColumn;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumn;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumnRelationship;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumnRelationshipStrategy;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyTable;
+import org.eclipse.jpt.jpa.core.context.SecondaryTable;
+import org.eclipse.jpt.jpa.core.context.Table;
+import org.eclipse.jpt.jpa.core.context.VirtualAssociationOverride;
+import org.eclipse.jpt.jpa.core.context.VirtualAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverride;
+import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverrideContainer;
+import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverrideContainer;
+import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
+import org.eclipse.jpt.jpa.core.context.java.JavaIdMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaNamedNativeQuery;
+import org.eclipse.jpt.jpa.core.context.java.JavaNamedQuery;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.java.JavaPrimaryKeyJoinColumn;
+import org.eclipse.jpt.jpa.core.context.java.JavaSecondaryTable;
+import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAssociationOverride;
+import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAttributeOverride;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.internal.context.java.JavaNullTypeMapping;
+import org.eclipse.jpt.jpa.core.resource.java.AssociationOverrideAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.AssociationOverridesAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.AttributeOverridesAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.DiscriminatorColumnAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.DiscriminatorValueAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EntityAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.IdClassAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.InheritanceAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.NamedNativeQueriesAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.NamedNativeQueryAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.NamedQueriesAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.NamedQueryAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.PrimaryKeyJoinColumnAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.PrimaryKeyJoinColumnsAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.SecondaryTableAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.SecondaryTablesAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.SequenceGeneratorAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.TableAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.TableGeneratorAnnotation;
+import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory;
+import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaEntityTests extends ContextModelTestCase
+{
+ private static final String ENTITY_NAME = "entityName";
+ private static final String TABLE_NAME = "MY_TABLE";
+ private static final String DISCRIMINATOR_VALUE = "MY_DISCRIMINATOR_VALUE";
+ protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild";
+ protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME;
+
+
+ public JavaEntityTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestEntity() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityInvalidNamedQueries() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.NAMED_QUERIES, JPA.NAMED_QUERY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("@NamedQueries(value={@NamedQuery(query=\"asdf\", name=\"foo\"), @NamedQuer})");
+ }
+ });
+ }
+
+ private void createTestAbstractEntity() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public abstract class ").append(TYPE_NAME).append(" ");
+ sb.append("{}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter);
+ }
+
+ private ICompilationUnit createTestEntityAnnotationOnProperty() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendGetIdMethodAnnotationTo(StringBuilder sb) {
+ sb.append("@Id");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestMappedSuperclass() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(
+ JPA.MAPPED_SUPERCLASS,
+ JPA.BASIC,
+ JPA.VERSION,
+ JPA.TRANSIENT,
+ JPA.EMBEDDED,
+ JPA.EMBEDDED_ID,
+ JPA.ONE_TO_ONE,
+ JPA.ONE_TO_MANY,
+ JPA.MANY_TO_ONE,
+ JPA.MANY_TO_MANY,
+ JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@MappedSuperclass");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("private String foo;").append(CR);
+ sb.append(CR);
+ sb.append(" @Basic");
+ sb.append(CR);
+ sb.append(" private int basic;").append(CR);
+ sb.append(CR);
+ sb.append(" @Version");
+ sb.append(CR);
+ sb.append(" private int version;").append(CR);
+ sb.append(CR);
+ sb.append(" @Transient");
+ sb.append(CR);
+ sb.append(" private int transient;").append(CR);
+ sb.append(CR);
+ sb.append(" @Embedded");
+ sb.append(CR);
+ sb.append(" private int embedded;").append(CR);
+ sb.append(CR);
+ sb.append(" @EmbeddedId");
+ sb.append(CR);
+ sb.append(" private int embeddedId;").append(CR);
+ sb.append(CR);
+ sb.append(" @OneToOne");
+ sb.append(CR);
+ sb.append(" private " + SUB_TYPE_NAME + " oneToOne;").append(CR);
+ sb.append(CR);
+ sb.append(" @OneToMany");
+ sb.append(CR);
+ sb.append(" private int oneToMany;").append(CR);
+ sb.append(CR);
+ sb.append(" @ManyToOne");
+ sb.append(CR);
+ sb.append(" private int manyToOne;").append(CR);
+ sb.append(CR);
+ sb.append(" @ManyToMany");
+ sb.append(CR);
+ sb.append(" private int manyToMany;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestAbstractEntityTablePerClass() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE, JPA.ONE_TO_ONE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)");
+ sb.append("abstract");
+ }
+
+ @Override
+ public void appendGetIdMethodAnnotationTo(StringBuilder sb) {
+ sb.append("private String foo;").append(CR);
+ sb.append(CR);
+ sb.append(" @OneToOne");
+ sb.append(CR);
+ sb.append(" private int address;").append(CR);
+ sb.append(CR);
+ sb.append(" @OneToOne");
+ sb.append(CR);
+ sb.append(" private int address2;").append(CR);
+ sb.append(CR);
+ sb.append(" ");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithName() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity(name=\"" + ENTITY_NAME + "\")");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithTable() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.TABLE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ sb.append("@Table(name=\"" + TABLE_NAME + "\")");
+ }
+ });
+ }
+
+ private void createTestSubType() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class ").append("AnnotationTestTypeChild").append(" ");
+ sb.append("extends " + TYPE_NAME + " ");
+ sb.append("{}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter);
+ }
+
+ private ICompilationUnit createTestEntityWithInheritance() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR);
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithDiscriminatorValue() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.DISCRIMINATOR_VALUE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ sb.append("@DiscriminatorValue(value=\"" + DISCRIMINATOR_VALUE + "\")");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithSecondaryTable() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.SECONDARY_TABLE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ sb.append("@SecondaryTable(name=\"foo\")");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithSecondaryTables() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ sb.append("@SecondaryTables({@SecondaryTable(name=\"foo\"), @SecondaryTable(name=\"bar\")})");
+ }
+ });
+ }
+
+ private ICompilationUnit createAbstractTestEntity() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR);
+ sb.append("abstract");
+ }
+ });
+ }
+
+ private void createTestIdClass() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("public class ").append("TestTypeId").append(" ");
+ sb.append("{}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "TestTypeId.java", sourceWriter);
+ }
+
+ public void testMorphToMappedSuperclass() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping();
+ entity.getTable().setSpecifiedName("FOO");
+ entity.addSpecifiedSecondaryTable(0);
+ entity.addSpecifiedPrimaryKeyJoinColumn(0);
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED);
+ entity.setSpecifiedDiscriminatorValue("asdf");
+ entity.getDiscriminatorColumn().setSpecifiedName("BAR");
+ entity.getGeneratorContainer().addTableGenerator();
+ entity.getGeneratorContainer().addSequenceGenerator();
+ entity.getIdClassReference().setSpecifiedIdClassName("myIdClass");
+ entity.getQueryContainer().addNamedNativeQuery(0);
+ entity.getQueryContainer().addNamedQuery(0);
+
+ getJavaPersistentType().setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY);
+ assertTrue(getJavaPersistentType().getMapping() instanceof MappedSuperclass);
+
+ assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToEmbeddable() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping();
+ entity.getTable().setSpecifiedName("FOO");
+ entity.addSpecifiedSecondaryTable(0);
+ entity.addSpecifiedPrimaryKeyJoinColumn(0);
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED);
+ entity.setSpecifiedDiscriminatorValue("asdf");
+ entity.getDiscriminatorColumn().setSpecifiedName("BAR");
+ entity.getGeneratorContainer().addTableGenerator();
+ entity.getGeneratorContainer().addSequenceGenerator();
+ entity.getIdClassReference().setSpecifiedIdClassName("myIdClass");
+ entity.getQueryContainer().addNamedNativeQuery(0);
+ entity.getQueryContainer().addNamedQuery(0);
+
+ getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY);
+ assertTrue(getJavaPersistentType().getMapping() instanceof Embeddable);
+
+ assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping();
+ entity.getTable().setSpecifiedName("FOO");
+ entity.addSpecifiedSecondaryTable(0);
+ entity.addSpecifiedPrimaryKeyJoinColumn(0);
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED);
+ entity.setSpecifiedDiscriminatorValue("asdf");
+ entity.getDiscriminatorColumn().setSpecifiedName("BAR");
+ entity.getGeneratorContainer().addTableGenerator();
+ entity.getGeneratorContainer().addSequenceGenerator();
+ entity.getIdClassReference().setSpecifiedIdClassName("myIdClass");
+ entity.getQueryContainer().addNamedNativeQuery(0);
+ entity.getQueryContainer().addNamedQuery(0);
+
+ getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY);
+ assertTrue(getJavaPersistentType().getMapping() instanceof JavaNullTypeMapping);
+
+ assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testAccessNoAnnotations() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess());
+ }
+
+ public void testAccessAnnotationsOnSuper() throws Exception {
+ createTestEntityAnnotationOnProperty();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME_ + "AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef();
+ mappingFileRef.setFileName(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString());
+ getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef);
+
+ JavaPersistentType childPersistentType = getJavaPersistentType();
+ PersistentType superPersistentType = childPersistentType.getSuperPersistentType();
+
+ assertEquals(AccessType.PROPERTY, superPersistentType.getAccess());
+ assertEquals(AccessType.PROPERTY, childPersistentType.getAccess());
+
+ ((IdMapping) superPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("FOO");
+ JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ resourceType.persistableProperties().next().removeAnnotation(JPA.ID);
+ getJpaProject().synchronizeContextModel();
+ //no mapping(Id) annotation, but still a Column annotation, so access should still be property
+ assertEquals(AccessType.PROPERTY, superPersistentType.getAccess());
+ assertEquals(AccessType.PROPERTY, childPersistentType.getAccess());
+
+ ((BasicMapping) superPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName(null);
+ assertEquals(AccessType.FIELD, superPersistentType.getAccess());
+ assertEquals(AccessType.FIELD, childPersistentType.getAccess());
+
+ getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY);
+ assertEquals(AccessType.PROPERTY, superPersistentType.getAccess());
+ assertEquals(AccessType.PROPERTY, childPersistentType.getAccess());
+
+ getEntityMappings().setSpecifiedAccess(AccessType.FIELD);
+ //still accessType of PROPERTY because the java class is not specified in this orm.xml
+ assertEquals(AccessType.PROPERTY, superPersistentType.getAccess());
+ assertEquals(AccessType.PROPERTY, childPersistentType.getAccess());
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ removeXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ //only parent specified in orm.xml, i think this outcome is right??
+ assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess());
+ assertEquals(AccessType.FIELD, childPersistentType.getAccess());
+
+ OrmPersistentType childOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild");
+ removeXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ //both parent and child specified in orm.xml
+ assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess());
+ assertEquals(AccessType.FIELD, childOrmPersistentType.getJavaPersistentType().getAccess());
+ }
+
+ public void testAccessWithXmlSettings() throws Exception {
+ createTestEntityAnnotationOnProperty();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef();
+ mappingFileRef.setFileName(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString());
+ getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef);
+
+ assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess());
+
+ ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("FOO");
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ typeResource.persistableProperties().next().removeAnnotation(JPA.ID);
+ getJpaProject().synchronizeContextModel();
+ //no mapping(Id) annotation, but still a Column annotation, so access should still be property
+ assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess());
+
+ ((BasicMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName(null);
+ getJpaProject().synchronizeContextModel();
+ assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess());
+
+ getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY);
+ assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess());
+
+ getEntityMappings().setSpecifiedAccess(AccessType.FIELD);
+ //still accessType of PROPERTY because the java class is not specified in this orm.xml
+ assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess());
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ //now class is specified in orm.xml, so entityMappings access setting wins over persistence-unit-defaults
+ assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess());
+
+ ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY);
+
+ //accessType should be PROPERTY now, java gets the access from xml entity if it is specified
+ assertEquals(AccessType.PROPERTY, ormPersistentType.getJavaPersistentType().getAccess());
+ }
+
+ public void testGetSpecifiedNameNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getSpecifiedName());
+ }
+
+ public void testGetSpecifiedName() throws Exception {
+ createTestEntityWithName();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(ENTITY_NAME, getJavaEntity().getSpecifiedName());
+ }
+
+ public void testGetDefaultNameSpecifiedNameNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(TYPE_NAME, getJavaEntity().getDefaultName());
+ }
+
+ public void testGetDefaultName() throws Exception {
+ createTestEntityWithName();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(TYPE_NAME, getJavaEntity().getDefaultName());
+ }
+
+ public void testGetNameSpecifiedNameNull() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(TYPE_NAME, getJavaEntity().getName());
+ }
+
+ public void testGetName() throws Exception {
+ createTestEntityWithName();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(ENTITY_NAME, getJavaEntity().getName());
+ }
+
+ public void testSetSpecifiedName() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().setSpecifiedName("foo");
+
+ assertEquals("foo", getJavaEntity().getSpecifiedName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals("foo", ((EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)).getName());
+ }
+
+ public void testSetSpecifiedNameNull() throws Exception {
+ createTestEntityWithName();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().setSpecifiedName(null);
+
+ assertNull(getJavaEntity().getSpecifiedName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(((EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)).getName());
+ }
+
+ public void testUpdateFromSpecifiedNameChangeInResourceModel() throws Exception {
+ createTestEntityWithName();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ EntityAnnotation entity = (EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME);
+ entity.setName("foo");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals("foo", getJavaEntity().getSpecifiedName());
+ }
+
+ public void testGetTableName() throws Exception {
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ createTestEntityWithName();
+
+ assertEquals(ENTITY_NAME, getJavaEntity().getPrimaryTableName());
+ }
+
+ public void testGetTableName2() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(TYPE_NAME, getJavaEntity().getPrimaryTableName());
+ }
+
+ public void testGetTableName3() throws Exception {
+ createTestEntityWithTable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(TABLE_NAME, getJavaEntity().getPrimaryTableName());
+ }
+
+ public void testSetTableNameWithNullTable() throws Exception {
+ ICompilationUnit cu = createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Table table = getJavaEntity().getTable();
+ assertEquals(TYPE_NAME, table.getName());
+ assertSourceDoesNotContain("@Table", cu);
+
+ table.setSpecifiedName(TABLE_NAME);
+ assertSourceContains("@Table(name = \"" + TABLE_NAME + "\")", cu);
+
+ assertEquals(TABLE_NAME, getJavaEntity().getPrimaryTableName());
+ assertEquals(TABLE_NAME, table.getName());
+
+ table.setSpecifiedCatalog(TABLE_NAME);
+ }
+
+ public void testGetInheritanceStrategy() throws Exception {
+ createTestEntityWithInheritance();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getInheritanceStrategy());
+ }
+
+ public void testGetDefaultInheritanceStrategy() throws Exception {
+ createTestEntity();
+ createTestSubType();
+
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs();
+ Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping();
+ Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping();
+
+ assertNotSame(childEntity, rootEntity);
+ assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy());
+
+ //change root inheritance strategy, verify default is changed for child entity
+ rootEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS);
+
+ assertEquals(InheritanceType.SINGLE_TABLE, rootEntity.getDefaultInheritanceStrategy());
+ assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getDefaultInheritanceStrategy());
+ assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getInheritanceStrategy());
+ assertNull(childEntity.getSpecifiedInheritanceStrategy());
+ }
+
+ public void testGetSpecifiedInheritanceStrategy() throws Exception {
+ createTestEntityWithInheritance();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getSpecifiedInheritanceStrategy());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME);
+
+ inheritance.setStrategy(org.eclipse.jpt.jpa.core.resource.java.InheritanceType.JOINED);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(InheritanceType.JOINED, getJavaEntity().getSpecifiedInheritanceStrategy());
+
+ inheritance.setStrategy(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(getJavaEntity().getSpecifiedInheritanceStrategy());
+ }
+
+ public void testSetSpecifiedInheritanceStrategy() throws Exception {
+ createTestEntityWithInheritance();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getSpecifiedInheritanceStrategy());
+
+ getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.JOINED);
+
+ assertEquals(InheritanceType.JOINED, getJavaEntity().getSpecifiedInheritanceStrategy());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME);
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.InheritanceType.JOINED, inheritance.getStrategy());
+
+ }
+
+ public void testGetDiscriminatorValue() throws Exception {
+ createTestEntityWithDiscriminatorValue();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getDiscriminatorValue());
+ }
+
+ public void testGetDefaultDiscriminatorValue() throws Exception {
+ createTestEntityWithDiscriminatorValue();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(null, getJavaEntity().getDefaultDiscriminatorValue());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+
+ assertEquals(getJavaEntity().getName(), getJavaEntity().getDefaultDiscriminatorValue());
+
+ getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.INTEGER);
+ assertNull(getJavaEntity().getDefaultDiscriminatorValue());
+ }
+
+ public void testGetSpecifiedDiscriminatorValue() throws Exception {
+ createTestEntityWithDiscriminatorValue();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getSpecifiedDiscriminatorValue());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME);
+
+ discriminatorValue.setValue("foo");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals("foo", getJavaEntity().getSpecifiedDiscriminatorValue());
+
+ discriminatorValue.setValue(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(getJavaEntity().getSpecifiedDiscriminatorValue());
+ }
+
+ public void testSetSpecifiedDiscriminatorValue() throws Exception {
+ createTestEntityWithDiscriminatorValue();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getSpecifiedDiscriminatorValue());
+
+ getJavaEntity().setSpecifiedDiscriminatorValue("foo");
+
+ assertEquals("foo", getJavaEntity().getSpecifiedDiscriminatorValue());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", discriminatorValue.getValue());
+ }
+
+ public void testSecondaryTables() throws Exception {
+ createTestEntityWithSecondaryTable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ ListIterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables();
+
+ assertTrue(secondaryTables.hasNext());
+ assertEquals("foo", secondaryTables.next().getName());
+ assertFalse(secondaryTables.hasNext());
+ }
+
+ public void testSecondaryTablesSize() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Entity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(0, entity.secondaryTablesSize());
+
+ ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO");
+ ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR");
+ ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ");
+
+ getJpaProject().synchronizeContextModel();
+ assertEquals(3, entity.secondaryTablesSize());
+ }
+
+ public void testSpecifiedSecondaryTables() throws Exception {
+ createTestEntityWithSecondaryTables();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ ListIterator<JavaSecondaryTable> specifiedSecondaryTables = getJavaEntity().specifiedSecondaryTables();
+
+ assertTrue(specifiedSecondaryTables.hasNext());
+ assertEquals("foo", specifiedSecondaryTables.next().getName());
+ assertEquals("bar", specifiedSecondaryTables.next().getName());
+ assertFalse(specifiedSecondaryTables.hasNext());
+ }
+
+ public void testSpecifiedSecondaryTablesSize() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Entity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(0, entity.specifiedSecondaryTablesSize());
+
+ ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO");
+ ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR");
+ ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ");
+
+ getJpaProject().synchronizeContextModel();
+ assertEquals(3, entity.specifiedSecondaryTablesSize());
+ }
+
+ public void testAddSpecifiedSecondaryTable() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO");
+ getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAR");
+ getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAZ");
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ Iterator<NestableAnnotation> secondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTables.next()).getName());
+ assertEquals("BAR", ((SecondaryTableAnnotation) secondaryTables.next()).getName());
+ assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTables.next()).getName());
+ assertFalse(secondaryTables.hasNext());
+ }
+
+ public void testAddSpecifiedSecondaryTable2() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO");
+ getJavaEntity().addSpecifiedSecondaryTable(1).setSpecifiedName("BAR");
+ getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAZ");
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ Iterator<NestableAnnotation> secondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTables.next()).getName());
+ assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTables.next()).getName());
+ assertEquals("BAR", ((SecondaryTableAnnotation) secondaryTables.next()).getName());
+ assertFalse(secondaryTables.hasNext());
+ }
+
+ public void testAddSpecifiedSecondaryTablePreservePkJoinColumns() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ SecondaryTable specifiedSecondaryTable = getJavaEntity().addSpecifiedSecondaryTable(0);
+ specifiedSecondaryTable.setSpecifiedName("FOO");
+ specifiedSecondaryTable.setSpecifiedCatalog("CATALOG");
+ specifiedSecondaryTable.setSpecifiedSchema("SCHEMA");
+ specifiedSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("PK_NAME");
+
+ //add another specified secondary table, pkJoinColumns from first should be saved.
+ SecondaryTable specifiedSecondaryTable2 = getJavaEntity().addSpecifiedSecondaryTable(1);
+ specifiedSecondaryTable2.setSpecifiedName("BAR");
+
+
+ Iterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables();
+ SecondaryTable secondaryTable = secondaryTables.next();
+ assertEquals(secondaryTable, specifiedSecondaryTable);
+ assertEquals("FOO", secondaryTable.getName());
+ assertEquals("CATALOG", secondaryTable.getCatalog());
+ assertEquals("SCHEMA", secondaryTable.getSchema());
+ assertEquals(1, secondaryTable.specifiedPrimaryKeyJoinColumnsSize());
+ PrimaryKeyJoinColumn pkJoinColumn = secondaryTable.specifiedPrimaryKeyJoinColumns().next();
+ assertEquals("PK_NAME", pkJoinColumn.getName());
+
+ secondaryTable = secondaryTables.next();
+ assertEquals(secondaryTable, specifiedSecondaryTable2);
+ assertEquals("BAR", secondaryTable.getName());
+ assertEquals(0, secondaryTable.specifiedPrimaryKeyJoinColumnsSize());
+
+ }
+
+ public void testRemoveSpecifiedSecondaryTable() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO");
+ getJavaEntity().addSpecifiedSecondaryTable(1).setSpecifiedName("BAR");
+ getJavaEntity().addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ");
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(3, CollectionTools.size(typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)));
+
+ getJavaEntity().removeSpecifiedSecondaryTable(1);
+
+ Iterator<NestableAnnotation> secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME);
+ assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName());
+ assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName());
+ assertFalse(secondaryTableResources.hasNext());
+
+ Iterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables();
+ assertEquals("FOO", secondaryTables.next().getName());
+ assertEquals("BAZ", secondaryTables.next().getName());
+ assertFalse(secondaryTables.hasNext());
+
+
+ getJavaEntity().removeSpecifiedSecondaryTable(1);
+ secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME);
+ assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName());
+ assertFalse(secondaryTableResources.hasNext());
+
+ secondaryTables = getJavaEntity().secondaryTables();
+ assertEquals("FOO", secondaryTables.next().getName());
+ assertFalse(secondaryTables.hasNext());
+
+
+ getJavaEntity().removeSpecifiedSecondaryTable(0);
+ secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME);
+ assertFalse(secondaryTableResources.hasNext());
+ secondaryTables = getJavaEntity().secondaryTables();
+ assertFalse(secondaryTables.hasNext());
+
+ assertNull(typeResource.getAnnotation(SecondaryTablesAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMoveSpecifiedSecondaryTable() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ entity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO");
+ entity.addSpecifiedSecondaryTable(1).setSpecifiedName("BAR");
+ entity.addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ");
+
+ Iterator<NestableAnnotation> javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME);
+ assertEquals(3, CollectionTools.size(javaSecondaryTables));
+
+
+ entity.moveSpecifiedSecondaryTable(2, 0);
+ ListIterator<JavaSecondaryTable> secondaryTables = entity.specifiedSecondaryTables();
+ assertEquals("BAR", secondaryTables.next().getSpecifiedName());
+ assertEquals("BAZ", secondaryTables.next().getSpecifiedName());
+ assertEquals("FOO", secondaryTables.next().getSpecifiedName());
+
+ javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName());
+ assertEquals("BAZ", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName());
+ assertEquals("FOO", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName());
+
+
+ entity.moveSpecifiedSecondaryTable(0, 1);
+ secondaryTables = entity.specifiedSecondaryTables();
+ assertEquals("BAZ", secondaryTables.next().getSpecifiedName());
+ assertEquals("BAR", secondaryTables.next().getSpecifiedName());
+ assertEquals("FOO", secondaryTables.next().getSpecifiedName());
+
+ javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAZ", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName());
+ assertEquals("BAR", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName());
+ assertEquals("FOO", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName());
+ }
+
+ public void testUpdateSpecifiedSecondaryTables() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO");
+ ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR");
+ ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+
+ ListIterator<JavaSecondaryTable> secondaryTables = entity.specifiedSecondaryTables();
+ assertEquals("FOO", secondaryTables.next().getName());
+ assertEquals("BAR", secondaryTables.next().getName());
+ assertEquals("BAZ", secondaryTables.next().getName());
+ assertFalse(secondaryTables.hasNext());
+
+ typeResource.moveAnnotation(2, 0, SecondaryTablesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ secondaryTables = entity.specifiedSecondaryTables();
+ assertEquals("BAR", secondaryTables.next().getName());
+ assertEquals("BAZ", secondaryTables.next().getName());
+ assertEquals("FOO", secondaryTables.next().getName());
+ assertFalse(secondaryTables.hasNext());
+
+ typeResource.moveAnnotation(0, 1, SecondaryTablesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ secondaryTables = entity.specifiedSecondaryTables();
+ assertEquals("BAZ", secondaryTables.next().getName());
+ assertEquals("BAR", secondaryTables.next().getName());
+ assertEquals("FOO", secondaryTables.next().getName());
+ assertFalse(secondaryTables.hasNext());
+
+ typeResource.removeAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ secondaryTables = entity.specifiedSecondaryTables();
+ assertEquals("BAZ", secondaryTables.next().getName());
+ assertEquals("FOO", secondaryTables.next().getName());
+ assertFalse(secondaryTables.hasNext());
+
+ typeResource.removeAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ secondaryTables = entity.specifiedSecondaryTables();
+ assertEquals("BAZ", secondaryTables.next().getName());
+ assertFalse(secondaryTables.hasNext());
+
+ typeResource.removeAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ secondaryTables = entity.specifiedSecondaryTables();
+ assertFalse(secondaryTables.hasNext());
+ }
+
+ public void testAssociatedTables() throws Exception {
+ createTestEntityWithSecondaryTables();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(3, CollectionTools.size(getJavaEntity().associatedTables()));
+ Iterator<ReadOnlyTable> associatedTables = getJavaEntity().associatedTables();
+ ReadOnlyTable table1 = associatedTables.next();
+ SecondaryTable table2 = (SecondaryTable) associatedTables.next();
+ SecondaryTable table3 = (SecondaryTable) associatedTables.next();
+ assertEquals(TYPE_NAME, table1.getName());
+ assertEquals("foo", table2.getName());
+ assertEquals("bar", table3.getName());
+ }
+
+ public void testAssociatedTablesIncludingInherited() throws Exception {
+ createTestEntityWithSecondaryTables();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs();
+ Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping();
+ Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping();
+
+ assertEquals(3, CollectionTools.size(rootEntity.allAssociatedTables()));
+ Iterator<ReadOnlyTable> associatedTables = rootEntity.allAssociatedTables();
+ ReadOnlyTable table1 = associatedTables.next();
+ SecondaryTable table2 = (SecondaryTable) associatedTables.next();
+ SecondaryTable table3 = (SecondaryTable) associatedTables.next();
+ assertEquals(TYPE_NAME, table1.getName());
+ assertEquals("foo", table2.getName());
+ assertEquals("bar", table3.getName());
+
+ //TODO probably want this to be 3, since in this case the child descriptor really uses the
+ //parent table because it is single table inheritance strategy. Not sure yet how to deal with this.
+ assertEquals(4, CollectionTools.size(childEntity.allAssociatedTables()));
+ }
+
+ public void testAssociatedTableNamesIncludingInherited() throws Exception {
+ createTestEntityWithSecondaryTables();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs();
+ Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping();
+ Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping();
+
+ assertEquals(3, CollectionTools.size(rootEntity.allAssociatedTableNames()));
+ Iterator<String> associatedTables = rootEntity.allAssociatedTableNames();
+ String table1 = associatedTables.next();
+ String table2 = associatedTables.next();
+ String table3 = associatedTables.next();
+ assertEquals(TYPE_NAME, table1);
+ assertEquals("foo", table2);
+ assertEquals("bar", table3);
+
+ //TODO probably want this to be 3, since in this case the child descriptor really uses the
+ //parent table because it is single table inheritance strategy. Not sure yet how to deal with this.
+ assertEquals(4, CollectionTools.size(childEntity.allAssociatedTableNames()));
+ }
+
+ public void testAddSecondaryTableToResourceModel() throws Exception {
+ createTestEntityWithName();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES);
+ secondaryTable.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(1, getJavaEntity().secondaryTablesSize());
+ assertEquals("FOO", getJavaEntity().secondaryTables().next().getSpecifiedName());
+ assertEquals("FOO", getJavaEntity().secondaryTables().next().getName());
+
+ SecondaryTableAnnotation secondaryTable2 = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES);
+ secondaryTable2.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(2, getJavaEntity().secondaryTablesSize());
+ ListIterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables();
+ assertEquals("FOO", secondaryTables.next().getSpecifiedName());
+ assertEquals("BAR", secondaryTables.next().getSpecifiedName());
+
+ SecondaryTableAnnotation secondaryTable3 = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES);
+ secondaryTable3.setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(3, getJavaEntity().secondaryTablesSize());
+ secondaryTables = getJavaEntity().secondaryTables();
+ assertEquals("BAZ", secondaryTables.next().getSpecifiedName());
+ assertEquals("FOO", secondaryTables.next().getSpecifiedName());
+ assertEquals("BAR", secondaryTables.next().getSpecifiedName());
+ }
+
+ public void testRemoveSecondaryTableFromResourceModel() throws Exception {
+ createTestEntityWithSecondaryTables();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().addSpecifiedSecondaryTable(2).setSpecifiedName("baz");
+ ListIterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables();
+
+ assertEquals(3, getJavaEntity().secondaryTablesSize());
+ assertEquals("foo", secondaryTables.next().getSpecifiedName());
+ assertEquals("bar", secondaryTables.next().getSpecifiedName());
+ assertEquals("baz", secondaryTables.next().getSpecifiedName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(2, getJavaEntity().secondaryTablesSize());
+ secondaryTables = getJavaEntity().secondaryTables();
+ assertEquals("bar", secondaryTables.next().getSpecifiedName());
+ assertEquals("baz", secondaryTables.next().getSpecifiedName());
+
+ typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES);
+ getJpaProject().synchronizeContextModel();
+
+ secondaryTables = getJavaEntity().secondaryTables();
+ assertEquals(1, getJavaEntity().secondaryTablesSize());
+ assertEquals("baz", secondaryTables.next().getSpecifiedName());
+
+
+ typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES);
+ getJpaProject().synchronizeContextModel();
+
+ secondaryTables = getJavaEntity().secondaryTables();
+ assertEquals(0, getJavaEntity().secondaryTablesSize());
+ assertFalse(secondaryTables.hasNext());
+ }
+
+ public void testGetSequenceGenerator() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator());
+ assertEquals(0, getJavaEntity().getPersistenceUnit().generatorsSize());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ typeResource.addAnnotation(JPA.SEQUENCE_GENERATOR);
+ getJpaProject().synchronizeContextModel();
+
+ assertNotNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator());
+ assertEquals(2, typeResource.annotationsSize());
+ assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize());
+
+ getJavaEntity().getGeneratorContainer().getSequenceGenerator().setName("foo");
+ assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize());
+ }
+
+ public void testAddSequenceGenerator() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator());
+
+ getJavaEntity().getGeneratorContainer().addSequenceGenerator();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNotNull(typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR));
+ assertNotNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator());
+
+ //try adding another sequence generator, should get an IllegalStateException
+ try {
+ getJavaEntity().getGeneratorContainer().addSequenceGenerator();
+ } catch (IllegalStateException e) {
+ return;
+ }
+ fail("IllegalStateException not thrown");
+ }
+
+ public void testRemoveSequenceGenerator() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ typeResource.addAnnotation(JPA.SEQUENCE_GENERATOR);
+ getJpaProject().synchronizeContextModel();
+
+ getJavaEntity().getGeneratorContainer().removeSequenceGenerator();
+
+ assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator());
+ assertNull(typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR));
+
+ //try removing the sequence generator again, should get an IllegalStateException
+ try {
+ getJavaEntity().getGeneratorContainer().removeSequenceGenerator();
+ } catch (IllegalStateException e) {
+ return;
+ }
+ fail("IllegalStateException not thrown");
+ }
+
+ public void testGetTableGenerator() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator());
+ assertEquals(0, getJavaEntity().getPersistenceUnit().generatorsSize());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ typeResource.addAnnotation(JPA.TABLE_GENERATOR);
+ getJpaProject().synchronizeContextModel();
+
+ assertNotNull(getJavaEntity().getGeneratorContainer().getTableGenerator());
+ assertEquals(2, typeResource.annotationsSize());
+ assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize());
+
+ getJavaEntity().getGeneratorContainer().getTableGenerator().setName("foo");
+ assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize());
+ }
+
+ public void testAddTableGenerator() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator());
+
+ getJavaEntity().getGeneratorContainer().addTableGenerator();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNotNull(typeResource.getAnnotation(JPA.TABLE_GENERATOR));
+ assertNotNull(getJavaEntity().getGeneratorContainer().getTableGenerator());
+
+ //try adding another table generator, should get an IllegalStateException
+ try {
+ getJavaEntity().getGeneratorContainer().addTableGenerator();
+ } catch (IllegalStateException e) {
+ return;
+ }
+ fail("IllegalStateException not thrown");
+ }
+
+ public void testRemoveTableGenerator() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ typeResource.addAnnotation(JPA.TABLE_GENERATOR);
+ getJpaProject().synchronizeContextModel();
+
+ getJavaEntity().getGeneratorContainer().removeTableGenerator();
+
+ assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator());
+ assertNull(typeResource.getAnnotation(JPA.TABLE_GENERATOR));
+
+ //try removing the table generator again, should get an IllegalStateException
+ try {
+ getJavaEntity().getGeneratorContainer().removeTableGenerator();
+ } catch (IllegalStateException e) {
+ return;
+ }
+ fail("IllegalStateException not thrown");
+ }
+
+ public void testGetDiscriminatorColumn() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNotNull(getJavaEntity().getDiscriminatorColumn());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN);
+ column.setName("foo");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals("foo", getJavaEntity().getDiscriminatorColumn().getSpecifiedName());
+
+ column.setName(null);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName());
+
+ typeResource.removeAnnotation(JPA.DISCRIMINATOR_COLUMN);
+ getJpaProject().synchronizeContextModel();
+
+ assertNotNull(getJavaEntity().getDiscriminatorColumn());
+ }
+
+ public void testSpecifiedPrimaryKeyJoinColumns() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ ListIterator<JavaPrimaryKeyJoinColumn> specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns();
+
+ assertFalse(specifiedPkJoinColumns.hasNext());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ //add an annotation to the resource model and verify the context model is updated
+ PrimaryKeyJoinColumnAnnotation pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS);
+ pkJoinColumn.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns();
+ assertEquals("FOO", specifiedPkJoinColumns.next().getName());
+ assertFalse(specifiedPkJoinColumns.hasNext());
+
+ pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS);
+ pkJoinColumn.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+ specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns();
+ assertEquals("BAR", specifiedPkJoinColumns.next().getName());
+ assertEquals("FOO", specifiedPkJoinColumns.next().getName());
+ assertFalse(specifiedPkJoinColumns.hasNext());
+
+
+ pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS);
+ pkJoinColumn.setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+ specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns();
+ assertEquals("BAZ", specifiedPkJoinColumns.next().getName());
+ assertEquals("BAR", specifiedPkJoinColumns.next().getName());
+ assertEquals("FOO", specifiedPkJoinColumns.next().getName());
+ assertFalse(specifiedPkJoinColumns.hasNext());
+
+ //move an annotation to the resource model and verify the context model is updated
+ typeResource.moveAnnotation(1, 0, JPA.PRIMARY_KEY_JOIN_COLUMNS);
+ getJpaProject().synchronizeContextModel();
+ specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns();
+ assertEquals("BAR", specifiedPkJoinColumns.next().getName());
+ assertEquals("BAZ", specifiedPkJoinColumns.next().getName());
+ assertEquals("FOO", specifiedPkJoinColumns.next().getName());
+ assertFalse(specifiedPkJoinColumns.hasNext());
+
+ typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS);
+ getJpaProject().synchronizeContextModel();
+ specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns();
+ assertEquals("BAZ", specifiedPkJoinColumns.next().getName());
+ assertEquals("FOO", specifiedPkJoinColumns.next().getName());
+ assertFalse(specifiedPkJoinColumns.hasNext());
+
+ typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS);
+ getJpaProject().synchronizeContextModel();
+ specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns();
+ assertEquals("FOO", specifiedPkJoinColumns.next().getName());
+ assertFalse(specifiedPkJoinColumns.hasNext());
+
+
+ typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS);
+ getJpaProject().synchronizeContextModel();
+ specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns();
+ assertFalse(specifiedPkJoinColumns.hasNext());
+ }
+
+ public void testSpecifiedPrimaryKeyJoinColumnsSize() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(0, getJavaEntity().specifiedPrimaryKeyJoinColumnsSize());
+
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ");
+
+ assertEquals(3, getJavaEntity().specifiedPrimaryKeyJoinColumnsSize());
+ }
+
+ public void testPrimaryKeyJoinColumnsSize() throws Exception {
+ createTestEntityWithSecondaryTable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ //just the default pkJoinColumn, so 1
+ assertEquals(1, getJavaEntity().primaryKeyJoinColumnsSize());
+
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ");
+
+ //only the specified pkJoinColumns, 3
+ assertEquals(3, getJavaEntity().primaryKeyJoinColumnsSize());
+ }
+
+ public void testGetDefaultPrimaryKeyJoinColumn() throws Exception {
+ createTestEntityWithSecondaryTable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNotNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn());
+
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ");
+
+ assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn());
+ }
+
+ public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ");
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ Iterator<NestableAnnotation> pkJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+
+ assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName());
+ assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName());
+ assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName());
+ assertFalse(pkJoinColumns.hasNext());
+ }
+
+ public void testAddSpecifiedPrimaryKeyJoinColumn2() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ Iterator<NestableAnnotation> pkJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+
+ assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName());
+ assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName());
+ assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName());
+ assertFalse(pkJoinColumns.hasNext());
+ }
+ public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR");
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(3, CollectionTools.size(typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)));
+
+ getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(1);
+
+ Iterator<NestableAnnotation> pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+ assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName());
+ assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName());
+ assertFalse(pkJoinColumnResources.hasNext());
+
+ Iterator<JavaPrimaryKeyJoinColumn> pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns();
+ assertEquals("FOO", pkJoinColumns.next().getName());
+ assertEquals("BAZ", pkJoinColumns.next().getName());
+ assertFalse(pkJoinColumns.hasNext());
+
+
+ getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(1);
+ pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+ assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName());
+ assertFalse(pkJoinColumnResources.hasNext());
+
+ pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns();
+ assertEquals("FOO", pkJoinColumns.next().getName());
+ assertFalse(pkJoinColumns.hasNext());
+
+
+ getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(0);
+ pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+ assertFalse(pkJoinColumnResources.hasNext());
+ pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns();
+ assertFalse(pkJoinColumns.hasNext());
+
+ assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ entity.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO");
+ entity.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR");
+ entity.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ");
+
+ Iterator<NestableAnnotation> javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+ assertEquals(3, CollectionTools.size(javaPrimaryKeyJoinColumns));
+
+
+ entity.moveSpecifiedPrimaryKeyJoinColumn(2, 0);
+ ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns();
+ assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName());
+ assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName());
+ assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName());
+
+ javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName());
+ assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName());
+ assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName());
+
+
+ entity.moveSpecifiedPrimaryKeyJoinColumn(0, 1);
+ primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns();
+ assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName());
+ assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName());
+ assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName());
+
+ javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+ assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName());
+ assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName());
+ assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName());
+ }
+
+ public void testUpdateSpecifiedPrimaryKeyJoinColumns() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO");
+ ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR");
+ ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(2, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+
+ ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns();
+ assertEquals("FOO", primaryKeyJoinColumns.next().getName());
+ assertEquals("BAR", primaryKeyJoinColumns.next().getName());
+ assertEquals("BAZ", primaryKeyJoinColumns.next().getName());
+ assertFalse(primaryKeyJoinColumns.hasNext());
+
+ typeResource.moveAnnotation(2, 0, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns();
+ assertEquals("BAR", primaryKeyJoinColumns.next().getName());
+ assertEquals("BAZ", primaryKeyJoinColumns.next().getName());
+ assertEquals("FOO", primaryKeyJoinColumns.next().getName());
+ assertFalse(primaryKeyJoinColumns.hasNext());
+
+ typeResource.moveAnnotation(0, 1, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns();
+ assertEquals("BAZ", primaryKeyJoinColumns.next().getName());
+ assertEquals("BAR", primaryKeyJoinColumns.next().getName());
+ assertEquals("FOO", primaryKeyJoinColumns.next().getName());
+ assertFalse(primaryKeyJoinColumns.hasNext());
+
+ typeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns();
+ assertEquals("BAZ", primaryKeyJoinColumns.next().getName());
+ assertEquals("FOO", primaryKeyJoinColumns.next().getName());
+ assertFalse(primaryKeyJoinColumns.hasNext());
+
+ typeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns();
+ assertEquals("BAZ", primaryKeyJoinColumns.next().getName());
+ assertFalse(primaryKeyJoinColumns.hasNext());
+
+ typeResource.removeAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns();
+ assertFalse(primaryKeyJoinColumns.hasNext());
+ }
+
+ public void testPrimaryKeyJoinColumnIsVirtual() throws Exception {
+ createTestEntityWithSecondaryTable();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertTrue(getJavaEntity().getDefaultPrimaryKeyJoinColumn().isDefault());
+
+ getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0);
+ PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next();
+ assertFalse(specifiedPkJoinColumn.isDefault());
+
+ assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn());
+ }
+
+ public void testTableNameIsInvalid() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertFalse(getJavaEntity().tableNameIsInvalid(TYPE_NAME));
+ assertTrue(getJavaEntity().tableNameIsInvalid("FOO"));
+
+ getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAR");
+
+ assertFalse(getJavaEntity().tableNameIsInvalid("BAR"));
+ }
+
+ public void testAttributeMappingKeyAllowed() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Entity entity = (Entity) getJavaPersistentType().getMapping();
+ assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY));
+ assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY));
+ assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY));
+ assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY));
+ assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY));
+ assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY));
+ assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY));
+ assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY));
+ assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY));
+ assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY));
+ }
+
+ public void testOverridableAttributes() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<String> overridableAttributes = getJavaEntity().overridableAttributeNames();
+ assertFalse(overridableAttributes.hasNext());
+
+
+ getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS);
+
+ overridableAttributes = getJavaEntity().overridableAttributeNames();
+ assertEquals("id", overridableAttributes.next());
+ assertEquals("name", overridableAttributes.next());
+ assertFalse(overridableAttributes.hasNext());
+ }
+
+ public void testOverridableAttributeNames() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<String> overridableAttributeNames = getJavaEntity().overridableAttributeNames();
+ assertFalse(overridableAttributeNames.hasNext());
+
+
+ getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS);
+
+ overridableAttributeNames = getJavaEntity().overridableAttributeNames();
+ assertEquals("id", overridableAttributeNames.next());
+ assertEquals("name", overridableAttributeNames.next());
+ assertFalse(overridableAttributeNames.hasNext());
+ }
+
+ public void testAllOverridableAttributes() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<String> overridableAttributes = getJavaEntity().allOverridableAttributeNames();
+ assertEquals("foo", overridableAttributes.next());
+ assertEquals("basic", overridableAttributes.next());
+ assertEquals("id", overridableAttributes.next());
+ assertEquals("name", overridableAttributes.next());
+ assertFalse(overridableAttributes.hasNext());
+ }
+
+ public void testAllOverridableAttributesTablePerClass() throws Exception {
+ createTestAbstractEntityTablePerClass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<String> overridableAttributes = getJavaEntity().allOverridableAttributeNames();
+ assertEquals("id", overridableAttributes.next());
+ assertEquals("name", overridableAttributes.next());
+ assertEquals("foo", overridableAttributes.next());
+ assertFalse(overridableAttributes.hasNext());
+
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping();
+ overridableAttributes = abstractEntity.allOverridableAttributeNames();
+ assertEquals("id", overridableAttributes.next());
+ assertEquals("name", overridableAttributes.next());
+ assertEquals("foo", overridableAttributes.next());
+ assertFalse(overridableAttributes.hasNext());
+ }
+
+ public void testAllOverridableAssociationsTablePerClass() throws Exception {
+ createTestAbstractEntityTablePerClass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<String> overridableAssociations = getJavaEntity().allOverridableAssociationNames();
+ assertEquals("address", overridableAssociations.next());
+ assertEquals("address2", overridableAssociations.next());
+ assertFalse(overridableAssociations.hasNext());
+
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping();
+ overridableAssociations = abstractEntity.allOverridableAssociationNames();
+ assertEquals("address", overridableAssociations.next());
+ assertEquals("address2", overridableAssociations.next());
+ assertFalse(overridableAssociations.hasNext());
+ }
+
+ public void testAllOverridableAttributesMappedSuperclassInOrmXml() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<String> overridableAttributes = getJavaEntity().allOverridableAttributeNames();
+ assertEquals("foo", overridableAttributes.next());
+ assertEquals("basic", overridableAttributes.next());
+ assertEquals("id", overridableAttributes.next());
+ assertEquals("name", overridableAttributes.next());
+ assertFalse(overridableAttributes.hasNext());
+ }
+
+ public void testAllOverridableAttributeNames() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<String> overridableAttributeNames = getJavaEntity().allOverridableAttributeNames();
+ assertEquals("foo", overridableAttributeNames.next());
+ assertEquals("basic", overridableAttributeNames.next());
+ assertEquals("id", overridableAttributeNames.next());
+ assertEquals("name", overridableAttributeNames.next());
+ assertFalse(overridableAttributeNames.hasNext());
+ }
+
+ public void testSpecifiedAttributeOverrides() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+ ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = overrideContainer.specifiedOverrides();
+
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ //add an annotation to the resource model and verify the context model is updated
+ AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+
+ attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAZ", specifiedAttributeOverrides.next().getName());
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ //move an annotation to the resource model and verify the context model is updated
+ typeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAZ", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAZ", specifiedAttributeOverrides.next().getName());
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+ typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAR", specifiedAttributeOverrides.next().getName());
+ assertFalse(specifiedAttributeOverrides.hasNext());
+
+
+ typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAttributeOverrides = overrideContainer.specifiedOverrides();
+ assertFalse(specifiedAttributeOverrides.hasNext());
+ }
+
+ public void testVirtualAttributeOverrideDefaults() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping();
+ AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ assertEquals(SUB_TYPE_NAME, typeResource.getName());
+ assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME));
+
+ assertEquals(4, overrideContainer.virtualOverridesSize());
+ VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("foo", virtualAttributeOverride.getName());
+ assertEquals("foo", virtualAttributeOverride.getColumn().getName());
+ assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable());
+ assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition());
+ assertEquals(true, virtualAttributeOverride.getColumn().isInsertable());
+ assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable());
+ assertEquals(false, virtualAttributeOverride.getColumn().isUnique());
+ assertEquals(true, virtualAttributeOverride.getColumn().isNullable());
+ assertEquals(255, virtualAttributeOverride.getColumn().getLength());
+ assertEquals(0, virtualAttributeOverride.getColumn().getPrecision());
+ assertEquals(0, virtualAttributeOverride.getColumn().getScale());
+
+
+ MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping();
+
+ BasicMapping fooMapping = (BasicMapping) mappedSuperclass.getPersistentType().getAttributeNamed("foo").getMapping();
+ fooMapping.getColumn().setSpecifiedName("FOO");
+ fooMapping.getColumn().setSpecifiedTable("BAR");
+ fooMapping.getColumn().setColumnDefinition("COLUMN_DEF");
+ fooMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE);
+ fooMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE);
+ fooMapping.getColumn().setSpecifiedUnique(Boolean.TRUE);
+ fooMapping.getColumn().setSpecifiedNullable(Boolean.FALSE);
+ fooMapping.getColumn().setSpecifiedLength(Integer.valueOf(5));
+ fooMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6));
+ fooMapping.getColumn().setSpecifiedScale(Integer.valueOf(7));
+
+ assertEquals(SUB_TYPE_NAME, typeResource.getName());
+ assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME));
+
+ assertEquals(4, overrideContainer.virtualOverridesSize());
+ virtualAttributeOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("foo", virtualAttributeOverride.getName());
+ assertEquals("FOO", virtualAttributeOverride.getColumn().getName());
+ assertEquals("BAR", virtualAttributeOverride.getColumn().getTable());
+ assertEquals("COLUMN_DEF", virtualAttributeOverride.getColumn().getColumnDefinition());
+ assertEquals(false, virtualAttributeOverride.getColumn().isInsertable());
+ assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable());
+ assertEquals(true, virtualAttributeOverride.getColumn().isUnique());
+ assertEquals(false, virtualAttributeOverride.getColumn().isNullable());
+ assertEquals(5, virtualAttributeOverride.getColumn().getLength());
+ assertEquals(6, virtualAttributeOverride.getColumn().getPrecision());
+ assertEquals(7, virtualAttributeOverride.getColumn().getScale());
+
+ fooMapping.getColumn().setSpecifiedName(null);
+ fooMapping.getColumn().setSpecifiedTable(null);
+ fooMapping.getColumn().setColumnDefinition(null);
+ fooMapping.getColumn().setSpecifiedInsertable(null);
+ fooMapping.getColumn().setSpecifiedUpdatable(null);
+ fooMapping.getColumn().setSpecifiedUnique(null);
+ fooMapping.getColumn().setSpecifiedNullable(null);
+ fooMapping.getColumn().setSpecifiedLength(null);
+ fooMapping.getColumn().setSpecifiedPrecision(null);
+ fooMapping.getColumn().setSpecifiedScale(null);
+ assertEquals(SUB_TYPE_NAME, typeResource.getName());
+ assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME));
+
+ virtualAttributeOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("foo", virtualAttributeOverride.getName());
+ assertEquals("foo", virtualAttributeOverride.getColumn().getName());
+ assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable());
+ assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition());
+ assertEquals(true, virtualAttributeOverride.getColumn().isInsertable());
+ assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable());
+ assertEquals(false, virtualAttributeOverride.getColumn().isUnique());
+ assertEquals(true, virtualAttributeOverride.getColumn().isNullable());
+ assertEquals(255, virtualAttributeOverride.getColumn().getLength());
+ assertEquals(0, virtualAttributeOverride.getColumn().getPrecision());
+ assertEquals(0, virtualAttributeOverride.getColumn().getScale());
+
+ virtualAttributeOverride.convertToSpecified();
+ assertEquals(3, overrideContainer.virtualOverridesSize());
+ }
+
+ public void testVirtualAttributeOverridesEntityHierachy() throws Exception {
+ createTestAbstractEntityTablePerClass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping();
+ AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ assertEquals(SUB_TYPE_NAME, typeResource.getName());
+ assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME));
+
+ assertEquals(3, overrideContainer.virtualOverridesSize());
+ VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("id", virtualAttributeOverride.getName());
+ assertEquals("id", virtualAttributeOverride.getColumn().getName());
+ assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable());
+
+
+ JavaEntity superclass = (JavaEntity) getJavaPersistentType().getMapping();
+
+ BasicMapping idMapping = (BasicMapping) superclass.getPersistentType().getAttributeNamed("id").getMapping();
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.getColumn().setSpecifiedTable("BAR");
+
+ assertEquals(SUB_TYPE_NAME, typeResource.getName());
+ assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME));
+
+ assertEquals(3, overrideContainer.virtualOverridesSize());
+ virtualAttributeOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("id", virtualAttributeOverride.getName());
+ assertEquals("FOO", virtualAttributeOverride.getColumn().getName());
+ assertEquals("BAR", virtualAttributeOverride.getColumn().getTable());
+
+ idMapping.getColumn().setSpecifiedName(null);
+ idMapping.getColumn().setSpecifiedTable(null);
+ assertEquals(SUB_TYPE_NAME, typeResource.getName());
+ assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME));
+
+ virtualAttributeOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("id", virtualAttributeOverride.getName());
+ assertEquals("id", virtualAttributeOverride.getColumn().getName());
+ assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable());
+
+ virtualAttributeOverride.convertToSpecified();
+ assertEquals(2, overrideContainer.virtualOverridesSize());
+ }
+
+ public void testSpecifiedAttributeOverridesSize() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+ assertEquals(0, overrideContainer.specifiedOverridesSize());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ //add an annotation to the resource model and verify the context model is updated
+ AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("FOO");
+ attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ attributeOverride.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(2, overrideContainer.specifiedOverridesSize());
+ }
+
+ public void testVirtualAttributeOverridesSize() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+
+ assertEquals(4, overrideContainer.virtualOverridesSize());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ assertEquals(3, overrideContainer.virtualOverridesSize());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ assertEquals(2, overrideContainer.virtualOverridesSize());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ assertEquals(1, overrideContainer.virtualOverridesSize());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ assertEquals(0, overrideContainer.virtualOverridesSize());
+ }
+
+ public void testAttributeOverridesSize() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+
+ assertEquals(4, overrideContainer.overridesSize());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ assertEquals(4, overrideContainer.overridesSize());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ assertEquals(4, overrideContainer.overridesSize());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES);
+ annotation.setName("bar");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(5, overrideContainer.overridesSize());
+ }
+
+ public void testAttributeOverrideSetVirtual() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ Iterator<NestableAnnotation> attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertFalse(attributeOverrides.hasNext());
+ }
+
+ public void testAttributeOverrideSetVirtual2() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+
+ ListIterator<JavaVirtualAttributeOverride> virtualAttributeOverrides = overrideContainer.virtualOverrides();
+ virtualAttributeOverrides.next();
+ virtualAttributeOverrides.next().convertToSpecified();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ Iterator<NestableAnnotation> attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName());
+ assertFalse(attributeOverrides.hasNext());
+ }
+
+ public void testAttributeOverrideSetVirtualTrue() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ assertEquals(3, CollectionTools.size(typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)));
+
+ overrideContainer.specifiedOverrides().next().convertToVirtual();
+
+ Iterator<NestableAnnotation> attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName());
+ assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName());
+ assertFalse(attributeOverrideResources.hasNext());
+
+ Iterator<JavaAttributeOverride> attributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("basic", attributeOverrides.next().getName());
+ assertEquals("id", attributeOverrides.next().getName());
+ assertFalse(attributeOverrides.hasNext());
+
+
+ overrideContainer.specifiedOverrides().next().convertToVirtual();
+ attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName());
+ assertFalse(attributeOverrideResources.hasNext());
+
+ attributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("id", attributeOverrides.next().getName());
+ assertFalse(attributeOverrides.hasNext());
+
+
+ overrideContainer.specifiedOverrides().next().convertToVirtual();
+ attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ assertFalse(attributeOverrideResources.hasNext());
+ attributeOverrides = overrideContainer.specifiedOverrides();
+ assertFalse(attributeOverrides.hasNext());
+
+ assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMoveSpecifiedAttributeOverride() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+
+ Iterator<NestableAnnotation> javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ assertEquals(3, CollectionTools.size(javaAttributeOverrides));
+
+ overrideContainer.moveSpecifiedOverride(2, 0);
+ ListIterator<JavaAttributeOverride> attributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("basic", attributeOverrides.next().getName());
+ assertEquals("id", attributeOverrides.next().getName());
+ assertEquals("foo", attributeOverrides.next().getName());
+
+ javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ assertEquals("basic", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName());
+ assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName());
+ assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName());
+
+
+ overrideContainer.moveSpecifiedOverride(0, 1);
+ attributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("id", attributeOverrides.next().getName());
+ assertEquals("basic", attributeOverrides.next().getName());
+ assertEquals("foo", attributeOverrides.next().getName());
+
+ javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName());
+ assertEquals("basic", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName());
+ assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName());
+ }
+
+ public void testUpdateSpecifiedAttributeOverrides() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ ((AttributeOverrideAnnotation) typeResource.addAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("FOO");
+ ((AttributeOverrideAnnotation) typeResource.addAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAR");
+ ((AttributeOverrideAnnotation) typeResource.addAnnotation(2, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+
+ ListIterator<JavaAttributeOverride> attributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("FOO", attributeOverrides.next().getName());
+ assertEquals("BAR", attributeOverrides.next().getName());
+ assertEquals("BAZ", attributeOverrides.next().getName());
+ assertFalse(attributeOverrides.hasNext());
+
+ typeResource.moveAnnotation(2, 0, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ attributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAR", attributeOverrides.next().getName());
+ assertEquals("BAZ", attributeOverrides.next().getName());
+ assertEquals("FOO", attributeOverrides.next().getName());
+ assertFalse(attributeOverrides.hasNext());
+
+ typeResource.moveAnnotation(0, 1, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ attributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAZ", attributeOverrides.next().getName());
+ assertEquals("BAR", attributeOverrides.next().getName());
+ assertEquals("FOO", attributeOverrides.next().getName());
+ assertFalse(attributeOverrides.hasNext());
+
+ typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ attributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAZ", attributeOverrides.next().getName());
+ assertEquals("FOO", attributeOverrides.next().getName());
+ assertFalse(attributeOverrides.hasNext());
+
+ typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ attributeOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAZ", attributeOverrides.next().getName());
+ assertFalse(attributeOverrides.hasNext());
+
+ typeResource.removeAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ attributeOverrides = overrideContainer.specifiedOverrides();
+ assertFalse(attributeOverrides.hasNext());
+ }
+
+ public void testAttributeOverrideIsVirtual() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer();
+
+ ListIterator<JavaVirtualAttributeOverride> virtualAttributeOverrides = overrideContainer.virtualOverrides();
+ JavaVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("foo", virtualAttributeOverride.getName());
+ assertTrue(virtualAttributeOverride.isVirtual());
+
+ virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("basic", virtualAttributeOverride.getName());
+ assertTrue(virtualAttributeOverride.isVirtual());
+
+ virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("id", virtualAttributeOverride.getName());
+ assertTrue(virtualAttributeOverride.isVirtual());
+
+ virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("name", virtualAttributeOverride.getName());
+ assertTrue(virtualAttributeOverride.isVirtual());
+ assertFalse(virtualAttributeOverrides.hasNext());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next();
+ assertFalse(specifiedAttributeOverride.isVirtual());
+
+
+ virtualAttributeOverrides = overrideContainer.virtualOverrides();
+ virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("basic", virtualAttributeOverride.getName());
+ assertTrue(virtualAttributeOverride.isVirtual());
+
+ virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("id", virtualAttributeOverride.getName());
+ assertTrue(virtualAttributeOverride.isVirtual());
+
+ virtualAttributeOverride = virtualAttributeOverrides.next();
+ assertEquals("name", virtualAttributeOverride.getName());
+ assertTrue(virtualAttributeOverride.isVirtual());
+ assertFalse(virtualAttributeOverrides.hasNext());
+ }
+
+ public void testOverridableAssociationNames() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<String> overridableAssociationNames = getJavaEntity().overridableAssociationNames();
+ assertFalse(overridableAssociationNames.hasNext());
+ }
+
+ public void testAllOverridableAssociationNames() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<String> overridableAssociationNames = getJavaEntity().allOverridableAssociationNames();
+ assertEquals("oneToOne", overridableAssociationNames.next());
+ assertEquals("manyToOne", overridableAssociationNames.next());
+ assertFalse(overridableAssociationNames.hasNext());
+ }
+
+ public void testAllOverridableAssociations() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<String> overridableAssociations = getJavaEntity().allOverridableAssociationNames();
+ assertEquals("oneToOne", overridableAssociations.next());
+ assertEquals("manyToOne", overridableAssociations.next());
+ assertFalse(overridableAssociations.hasNext());
+ }
+//
+// public void testAllOverridableAssociationsMappedSuperclassInOrmXml() throws Exception {
+// createTestMappedSuperclass();
+// createTestSubType();
+// addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+// getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+//
+// Iterator<RelationshipMapping> overridableAssociations = getJavaEntity().allOverridableAssociations();
+// assertEquals("oneToOne", overridableAssociations.next().getName());
+// assertEquals("manyToOne", overridableAssociations.next().getName());
+// assertFalse(overridableAssociations.hasNext());
+// }
+
+ public void testSpecifiedAssociationOverrides() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+ ListIterator<JavaAssociationOverride> specifiedAssociationOverrides = overrideContainer.specifiedOverrides();
+
+ assertFalse(specifiedAssociationOverrides.hasNext());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ //add an annotation to the resource model and verify the context model is updated
+ AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ associationOverride.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ specifiedAssociationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAssociationOverrides.next().getName());
+ assertFalse(specifiedAssociationOverrides.hasNext());
+
+ associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ associationOverride.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+ specifiedAssociationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAssociationOverrides.next().getName());
+ assertEquals("BAR", specifiedAssociationOverrides.next().getName());
+ assertFalse(specifiedAssociationOverrides.hasNext());
+
+
+ associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ associationOverride.setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+ specifiedAssociationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAZ", specifiedAssociationOverrides.next().getName());
+ assertEquals("FOO", specifiedAssociationOverrides.next().getName());
+ assertEquals("BAR", specifiedAssociationOverrides.next().getName());
+ assertFalse(specifiedAssociationOverrides.hasNext());
+
+ //move an annotation to the resource model and verify the context model is updated
+ typeResource.moveAnnotation(1, 0, JPA.ASSOCIATION_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAssociationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("FOO", specifiedAssociationOverrides.next().getName());
+ assertEquals("BAZ", specifiedAssociationOverrides.next().getName());
+ assertEquals("BAR", specifiedAssociationOverrides.next().getName());
+ assertFalse(specifiedAssociationOverrides.hasNext());
+
+ typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAssociationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAZ", specifiedAssociationOverrides.next().getName());
+ assertEquals("BAR", specifiedAssociationOverrides.next().getName());
+ assertFalse(specifiedAssociationOverrides.hasNext());
+
+ typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAssociationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAR", specifiedAssociationOverrides.next().getName());
+ assertFalse(specifiedAssociationOverrides.hasNext());
+
+
+ typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ getJpaProject().synchronizeContextModel();
+ specifiedAssociationOverrides = overrideContainer.specifiedOverrides();
+ assertFalse(specifiedAssociationOverrides.hasNext());
+ }
+
+ public void testVirtualAssociationOverrideDefaults() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+
+ ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ classRefs.next();
+ JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping();
+ AssociationOverrideContainer overrideContainer = javaEntity.getAssociationOverrideContainer();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ assertEquals(SUB_TYPE_NAME, typeResource.getName());
+ assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME));
+
+ assertEquals(2, overrideContainer.virtualOverridesSize());
+ VirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next();
+ ReadOnlyJoinColumnRelationshipStrategy joiningStrategy = ((ReadOnlyJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy();
+ assertEquals("oneToOne", virtualAssociationOverride.getName());
+ assertEquals(1, joiningStrategy.joinColumnsSize());
+ ReadOnlyJoinColumn virtualJoinColumn = joiningStrategy.joinColumns().next();
+ assertEquals("oneToOne_id", virtualJoinColumn.getName());
+ assertEquals("id", virtualJoinColumn.getReferencedColumnName());
+ assertEquals(SUB_TYPE_NAME, virtualJoinColumn.getTable());
+ assertEquals(null, virtualJoinColumn.getColumnDefinition());
+ assertEquals(true, virtualJoinColumn.isInsertable());
+ assertEquals(true, virtualJoinColumn.isUpdatable());
+ assertEquals(false, virtualJoinColumn.isUnique());
+ assertEquals(true, virtualJoinColumn.isNullable());
+
+
+ OneToOneMapping oneToOneMapping = (OneToOneMapping) getJavaPersistentType().getAttributeNamed("oneToOne").getMapping();
+ JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("MY_JOIN_COLUMN");
+ joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN");
+ joinColumn.setSpecifiedTable("BAR");
+ joinColumn.setColumnDefinition("COLUMN_DEF");
+ joinColumn.setSpecifiedInsertable(Boolean.FALSE);
+ joinColumn.setSpecifiedUpdatable(Boolean.FALSE);
+ joinColumn.setSpecifiedUnique(Boolean.TRUE);
+ joinColumn.setSpecifiedNullable(Boolean.FALSE);
+
+ assertEquals(SUB_TYPE_NAME, typeResource.getName());
+ assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME));
+
+ assertEquals(2, overrideContainer.virtualOverridesSize());
+ virtualAssociationOverride = overrideContainer.virtualOverrides().next();
+ joiningStrategy = ((ReadOnlyJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy();
+ assertEquals("oneToOne", virtualAssociationOverride.getName());
+ assertEquals(1, joiningStrategy.joinColumnsSize());
+ virtualAssociationOverride = overrideContainer.virtualOverrides().next();
+ virtualJoinColumn = joiningStrategy.joinColumns().next();
+ assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName());
+ assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName());
+ assertEquals("BAR", virtualJoinColumn.getTable());
+ assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition());
+ assertEquals(false, virtualJoinColumn.isInsertable());
+ assertEquals(false, virtualJoinColumn.isUpdatable());
+ assertEquals(true, virtualJoinColumn.isUnique());
+ assertEquals(false, virtualJoinColumn.isNullable());
+
+ assertEquals("MY_JOIN_COLUMN", joiningStrategy.joinColumns().next().getName());
+
+
+
+
+
+
+ //idMapping.getColumn().setSpecifiedName(null);
+ //idMapping.getColumn().setSpecifiedTable(null);
+ assertEquals(SUB_TYPE_NAME, typeResource.getName());
+ assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME));
+ assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME));
+
+ virtualAssociationOverride = overrideContainer.virtualOverrides().next();
+ assertEquals("oneToOne", virtualAssociationOverride.getName());
+
+ virtualAssociationOverride.convertToSpecified();
+ assertEquals(1, overrideContainer.virtualOverridesSize());
+
+
+
+// //TODO joinColumns for default association overrides
+//// IJoinColumn defaultJoinColumn = defaultAssociationOverride.joinColumns().next();
+//// assertEquals("address", defaultJoinColumn.getName());
+//// assertEquals("address", defaultJoinColumn.getReferencedColumnName());
+//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable());
+////
+////
+//// IMappedSuperclass mappedSuperclass = (IMappedSuperclass) javaPersistentType().getMapping();
+////
+//// IOneToOneMapping addressMapping = (IOneToOneMapping) mappedSuperclass.persistentType().attributeNamed("address").getMapping();
+//// IJoinColumn joinColumn = addressMapping.addSpecifiedJoinColumn(0);
+//// joinColumn.setSpecifiedName("FOO");
+//// joinColumn.setSpecifiedReferencedColumnName("BAR");
+//// joinColumn.setSpecifiedTable("BAZ");
+////
+//// assertEquals(SUB_TYPE_NAME, typeResource.getName());
+//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME));
+//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME));
+////
+//// assertEquals(1, CollectionTools.size(javaEntity.defaultAssociationOverrides()));
+//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next();
+//// assertEquals("address", defaultAssociationOverride.getName());
+//// assertEquals("FOO", defaultJoinColumn.getName());
+//// assertEquals("BAR", defaultJoinColumn.getReferencedColumnName());
+//// assertEquals("BAZ", defaultJoinColumn.getTable());
+////
+//// joinColumn.setSpecifiedName(null);
+//// joinColumn.setSpecifiedReferencedColumnName(null);
+//// joinColumn.setSpecifiedTable(null);
+//// assertEquals(SUB_TYPE_NAME, typeResource.getName());
+//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME));
+//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME));
+////
+//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next();
+//// assertEquals("address", defaultJoinColumn.getName());
+//// assertEquals("address", defaultJoinColumn.getReferencedColumnName());
+//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable());
+////
+//// javaEntity.addSpecifiedAssociationOverride(0).setName("address");
+//// assertEquals(0, CollectionTools.size(javaEntity.defaultAssociationOverrides()));
+
+ }
+
+ public void testSpecifiedAssociationOverridesSize() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+ assertEquals(0, overrideContainer.specifiedOverridesSize());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ //add an annotation to the resource model and verify the context model is updated
+ AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ associationOverride.setName("FOO");
+ associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ associationOverride.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(2, overrideContainer.specifiedOverridesSize());
+ }
+
+ public void testVirtualAssociationOverridesSize() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+
+ assertEquals(2, overrideContainer.virtualOverridesSize());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ assertEquals(1, overrideContainer.virtualOverridesSize());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ assertEquals(0, overrideContainer.virtualOverridesSize());
+ }
+
+ public void testAssociationOverridesSize() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+
+ assertEquals(2, overrideContainer.overridesSize());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ assertEquals(2, overrideContainer.overridesSize());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ assertEquals(2, overrideContainer.overridesSize());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ AssociationOverrideAnnotation annotation = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES);
+ annotation.setName("bar");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(3, overrideContainer.overridesSize());
+ }
+
+ public void testAssociationOverrideSetVirtual() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ Iterator<NestableAnnotation> associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("oneToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName());
+ assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName());
+ assertFalse(associationOverrides.hasNext());
+ }
+
+ public void testAssociationOverrideSetVirtual2() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+ ListIterator<JavaVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.virtualOverrides();
+ virtualAssociationOverrides.next();
+ virtualAssociationOverrides.next().convertToSpecified();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ Iterator<NestableAnnotation> associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME);
+
+ assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName());
+ assertEquals("oneToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName());
+ assertFalse(associationOverrides.hasNext());
+ }
+
+ public void testAssociationOverrideSetVirtualTrue() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ assertEquals(2, CollectionTools.size(typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)));
+
+ overrideContainer.specifiedOverrides().next().convertToVirtual();
+
+ Iterator<NestableAnnotation> associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME);
+ assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrideResources.next()).getName());
+ assertFalse(associationOverrideResources.hasNext());
+
+ Iterator<JavaAssociationOverride> associationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("manyToOne", associationOverrides.next().getName());
+ assertFalse(associationOverrides.hasNext());
+
+
+ overrideContainer.specifiedOverrides().next().convertToVirtual();
+ associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME);
+ assertFalse(associationOverrideResources.hasNext());
+ associationOverrides = overrideContainer.specifiedOverrides();
+ assertFalse(associationOverrides.hasNext());
+
+ assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMoveSpecifiedAssociationOverride() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME);
+
+ Iterator<NestableAnnotation> javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME);
+ assertEquals(2, CollectionTools.size(javaAssociationOverrides));
+
+
+ overrideContainer.moveSpecifiedOverride(1, 0);
+ ListIterator<JavaAssociationOverride> associationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("manyToOne", associationOverrides.next().getName());
+ assertEquals("oneToOne", associationOverrides.next().getName());
+
+ javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME);
+ assertEquals("manyToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName());
+ assertEquals("oneToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName());
+
+
+ overrideContainer.moveSpecifiedOverride(0, 1);
+ associationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("oneToOne", associationOverrides.next().getName());
+ assertEquals("manyToOne", associationOverrides.next().getName());
+
+ javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME);
+ assertEquals("oneToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName());
+ assertEquals("manyToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName());
+ }
+
+ public void testUpdateSpecifiedAssociationOverrides() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ ((AssociationOverrideAnnotation) typeResource.addAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("FOO");
+ ((AssociationOverrideAnnotation) typeResource.addAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAR");
+ ((AssociationOverrideAnnotation) typeResource.addAnnotation(2, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+
+ ListIterator<JavaAssociationOverride> associationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("FOO", associationOverrides.next().getName());
+ assertEquals("BAR", associationOverrides.next().getName());
+ assertEquals("BAZ", associationOverrides.next().getName());
+ assertFalse(associationOverrides.hasNext());
+
+ typeResource.moveAnnotation(2, 0, AssociationOverridesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ associationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAR", associationOverrides.next().getName());
+ assertEquals("BAZ", associationOverrides.next().getName());
+ assertEquals("FOO", associationOverrides.next().getName());
+ assertFalse(associationOverrides.hasNext());
+
+ typeResource.moveAnnotation(0, 1, AssociationOverridesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ associationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAZ", associationOverrides.next().getName());
+ assertEquals("BAR", associationOverrides.next().getName());
+ assertEquals("FOO", associationOverrides.next().getName());
+ assertFalse(associationOverrides.hasNext());
+
+ typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ associationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAZ", associationOverrides.next().getName());
+ assertEquals("FOO", associationOverrides.next().getName());
+ assertFalse(associationOverrides.hasNext());
+
+ typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ associationOverrides = overrideContainer.specifiedOverrides();
+ assertEquals("BAZ", associationOverrides.next().getName());
+ assertFalse(associationOverrides.hasNext());
+
+ typeResource.removeAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ associationOverrides = overrideContainer.specifiedOverrides();
+ assertFalse(associationOverrides.hasNext());
+ }
+
+ public void testAssociationOverrideIsVirtual() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer();
+ ListIterator<JavaVirtualAssociationOverride> virtualAssociationOverrides = overrideContainer.virtualOverrides();
+ JavaVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next();
+ assertEquals("oneToOne", virtualAssociationOverride.getName());
+ assertTrue(virtualAssociationOverride.isVirtual());
+
+ virtualAssociationOverride = virtualAssociationOverrides.next();
+ assertEquals("manyToOne", virtualAssociationOverride.getName());
+ assertTrue(virtualAssociationOverride.isVirtual());
+ assertFalse(virtualAssociationOverrides.hasNext());
+
+ overrideContainer.virtualOverrides().next().convertToSpecified();
+ AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next();
+ assertFalse(specifiedAssociationOverride.isVirtual());
+
+
+ virtualAssociationOverrides = overrideContainer.virtualOverrides();
+ virtualAssociationOverride = virtualAssociationOverrides.next();
+ assertEquals("manyToOne", virtualAssociationOverride.getName());
+ assertTrue(virtualAssociationOverride.isVirtual());
+ assertFalse(virtualAssociationOverrides.hasNext());
+ }
+
+ public void testAddNamedQuery() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ NamedQuery namedQuery1 = entity.getQueryContainer().addNamedQuery(0);
+ namedQuery1.setName("FOO");
+
+ Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+
+ NamedQuery namedQuery2 = entity.getQueryContainer().addNamedQuery(0);
+ namedQuery2.setName("BAR");
+
+ javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+
+ NamedQuery namedQuery3 = entity.getQueryContainer().addNamedQuery(1);
+ namedQuery3.setName("BAZ");
+
+ javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+
+ ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries();
+ assertEquals(namedQuery2, namedQueries.next());
+ assertEquals(namedQuery3, namedQueries.next());
+ assertEquals(namedQuery1, namedQueries.next());
+
+ namedQueries = entity.getQueryContainer().namedQueries();
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+
+ entity.getQueryContainer().addNamedNativeQuery(0).setName("foo");
+ }
+
+ public void testInvalidNamedQueries() throws Exception {
+ createTestEntityInvalidNamedQueries();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ assertEquals(1, entity.getQueryContainer().namedQueriesSize());
+ }
+
+ public void testRemoveNamedQuery() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ entity.getQueryContainer().addNamedQuery(0).setName("FOO");
+ entity.getQueryContainer().addNamedQuery(1).setName("BAR");
+ entity.getQueryContainer().addNamedQuery(2).setName("BAZ");
+
+ Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals(3, CollectionTools.size(javaNamedQueries));
+
+ entity.getQueryContainer().removeNamedQuery(0);
+ javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals(2, CollectionTools.size(javaNamedQueries));
+ javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+
+ entity.getQueryContainer().removeNamedQuery(0);
+ javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals(1, CollectionTools.size(javaNamedQueries));
+ javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+
+ entity.getQueryContainer().removeNamedQuery(0);
+ javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals(0, CollectionTools.size(javaNamedQueries));
+ }
+
+ public void testAddNamedNativeQueryWithNamedQuery() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ entity.getQueryContainer().addNamedQuery(0).setName("FOO");
+
+
+ NamedNativeQueryAnnotation nativeQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES);
+ nativeQuery.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(1, entity.getQueryContainer().namedNativeQueriesSize());
+ ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries();
+ assertEquals("BAR", namedQueries.next().getName());
+ }
+
+ public void testAddNamedQueryWithNamedNativeQuery() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO");
+
+
+ NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_QUERY, JPA.NAMED_QUERIES);
+ namedQuery.setName("BAR");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(1, entity.getQueryContainer().namedQueriesSize());
+ ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries();
+ assertEquals("BAR", namedQueries.next().getName());
+ }
+
+ public void testMoveNamedQuery() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ entity.getQueryContainer().addNamedQuery(0).setName("FOO");
+ entity.getQueryContainer().addNamedQuery(1).setName("BAR");
+ entity.getQueryContainer().addNamedQuery(2).setName("BAZ");
+
+ Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals(3, CollectionTools.size(javaNamedQueries));
+
+
+ entity.getQueryContainer().moveNamedQuery(2, 0);
+ ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries();
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+
+ javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+
+
+ entity.getQueryContainer().moveNamedQuery(0, 1);
+ namedQueries = entity.getQueryContainer().namedQueries();
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+
+ javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName());
+ }
+
+ public void testUpdateNamedQueries() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(0, entity.getPersistenceUnit().queriesSize());
+
+ ((NamedQueryAnnotation) typeResource.addAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("FOO");
+ ((NamedQueryAnnotation) typeResource.addAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAR");
+ ((NamedQueryAnnotation) typeResource.addAnnotation(2, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+ ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries();
+ assertEquals("FOO", namedQueries.next().getName());
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertFalse(namedQueries.hasNext());
+ assertEquals(3, entity.getPersistenceUnit().queriesSize());
+
+ typeResource.moveAnnotation(2, 0, NamedQueriesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ namedQueries = entity.getQueryContainer().namedQueries();
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+ assertFalse(namedQueries.hasNext());
+
+ typeResource.moveAnnotation(0, 1, NamedQueriesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ namedQueries = entity.getQueryContainer().namedQueries();
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+ assertFalse(namedQueries.hasNext());
+
+ typeResource.removeAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ namedQueries = entity.getQueryContainer().namedQueries();
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+ assertFalse(namedQueries.hasNext());
+ assertEquals(2, entity.getPersistenceUnit().queriesSize());
+
+ typeResource.removeAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ namedQueries = entity.getQueryContainer().namedQueries();
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertFalse(namedQueries.hasNext());
+ assertEquals(1, entity.getPersistenceUnit().queriesSize());
+
+ typeResource.removeAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ namedQueries = entity.getQueryContainer().namedQueries();
+ assertFalse(namedQueries.hasNext());
+ assertEquals(0, entity.getPersistenceUnit().queriesSize());
+ }
+
+ public void testNamedQueriesSize() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(0, entity.getQueryContainer().namedQueriesSize());
+
+ ((NamedQueryAnnotation) typeResource.addAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("FOO");
+ ((NamedQueryAnnotation) typeResource.addAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAR");
+ ((NamedQueryAnnotation) typeResource.addAnnotation(2, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ");
+
+ getJpaProject().synchronizeContextModel();
+ assertEquals(3, entity.getQueryContainer().namedQueriesSize());
+ }
+
+ public void testAddNamedNativeQuery() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ NamedNativeQuery namedNativeQuery = entity.getQueryContainer().addNamedNativeQuery(0);
+ namedNativeQuery.setName("FOO");
+
+ Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+
+ NamedNativeQuery namedNativeQuery2 = entity.getQueryContainer().addNamedNativeQuery(0);
+ namedNativeQuery2.setName("BAR");
+
+ javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+
+ NamedNativeQuery namedNativeQuery3 = entity.getQueryContainer().addNamedNativeQuery(1);
+ namedNativeQuery3.setName("BAZ");
+
+ javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+
+ ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries();
+ assertEquals(namedNativeQuery2, namedQueries.next());
+ assertEquals(namedNativeQuery3, namedQueries.next());
+ assertEquals(namedNativeQuery, namedQueries.next());
+
+ namedQueries = entity.getQueryContainer().namedNativeQueries();
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+ }
+
+ public void testRemoveNamedNativeQuery() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO");
+ entity.getQueryContainer().addNamedNativeQuery(1).setName("BAR");
+ entity.getQueryContainer().addNamedNativeQuery(2).setName("BAZ");
+
+ Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals(3, CollectionTools.size(javaNamedQueries));
+
+ entity.getQueryContainer().removeNamedNativeQuery(0);
+ javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals(2, CollectionTools.size(javaNamedQueries));
+ javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+
+ entity.getQueryContainer().removeNamedNativeQuery(0);
+ javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals(1, CollectionTools.size(javaNamedQueries));
+ javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+
+ entity.getQueryContainer().removeNamedNativeQuery(0);
+ javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals(0, CollectionTools.size(javaNamedQueries));
+ }
+
+ public void testMoveNamedNativeQuery() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO");
+ entity.getQueryContainer().addNamedNativeQuery(1).setName("BAR");
+ entity.getQueryContainer().addNamedNativeQuery(2).setName("BAZ");
+
+ Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals(3, CollectionTools.size(javaNamedQueries));
+
+ entity.getQueryContainer().moveNamedNativeQuery(2, 0);
+ ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries();
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+
+ javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+
+
+ entity.getQueryContainer().moveNamedNativeQuery(0, 1);
+ namedQueries = entity.getQueryContainer().namedNativeQueries();
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+
+ javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+ assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName());
+ }
+
+ public void testUpdateNamedNativeQueries() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(0, entity.getPersistenceUnit().queriesSize());
+
+ ((NamedNativeQueryAnnotation) typeResource.addAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("FOO");
+ ((NamedNativeQueryAnnotation) typeResource.addAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAR");
+ ((NamedNativeQueryAnnotation) typeResource.addAnnotation(2, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ");
+ getJpaProject().synchronizeContextModel();
+ ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries();
+ assertEquals("FOO", namedQueries.next().getName());
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertFalse(namedQueries.hasNext());
+ assertEquals(3, entity.getPersistenceUnit().queriesSize());
+
+ typeResource.moveAnnotation(2, 0, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ namedQueries = entity.getQueryContainer().namedNativeQueries();
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+ assertFalse(namedQueries.hasNext());
+
+ typeResource.moveAnnotation(0, 1, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ namedQueries = entity.getQueryContainer().namedNativeQueries();
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("BAR", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+ assertFalse(namedQueries.hasNext());
+
+ typeResource.removeAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ namedQueries = entity.getQueryContainer().namedNativeQueries();
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertEquals("FOO", namedQueries.next().getName());
+ assertFalse(namedQueries.hasNext());
+ assertEquals(2, entity.getPersistenceUnit().queriesSize());
+
+ typeResource.removeAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ namedQueries = entity.getQueryContainer().namedNativeQueries();
+ assertEquals("BAZ", namedQueries.next().getName());
+ assertFalse(namedQueries.hasNext());
+ assertEquals(1, entity.getPersistenceUnit().queriesSize());
+
+ typeResource.removeAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ namedQueries = entity.getQueryContainer().namedNativeQueries();
+ assertFalse(namedQueries.hasNext());
+ assertEquals(0, entity.getPersistenceUnit().queriesSize());
+ }
+
+ public void testNamedNativeQueriesSize() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaEntity entity = getJavaEntity();
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertEquals(0, entity.getQueryContainer().namedNativeQueriesSize());
+
+ ((NamedNativeQueryAnnotation) typeResource.addAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("FOO");
+ ((NamedNativeQueryAnnotation) typeResource.addAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAR");
+ ((NamedNativeQueryAnnotation) typeResource.addAnnotation(2, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ");
+
+ getJpaProject().synchronizeContextModel();
+ assertEquals(3, entity.getQueryContainer().namedNativeQueriesSize());
+ }
+
+ public void testUpdateIdClass() throws Exception {
+ createTestEntity();
+ createTestIdClass();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName());
+ assertNull(getJavaEntity().getIdClassReference().getIdClass());
+ assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME));
+
+ IdClassAnnotation idClassAnnotation = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName());
+ assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME));
+
+ // test setting id class name to nonexistent class. test class name is set, but class is null
+ String nonExistentIdClassName = PACKAGE_NAME + ".Foo";
+ idClassAnnotation.setValue(nonExistentIdClassName);
+ getJpaProject().synchronizeContextModel();
+ assertEquals(nonExistentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName());
+ assertEquals(nonExistentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue());
+ assertNull(getJavaEntity().getIdClassReference().getIdClass());
+
+ // test setting id class name to existent class. test class name is set and class is not null
+ String existentIdClassName = PACKAGE_NAME + ".TestTypeId";
+ idClassAnnotation.setValue(existentIdClassName);
+ getJpaProject().synchronizeContextModel();
+ assertEquals(existentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName());
+ assertEquals(existentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue());
+ assertNotNull(getJavaEntity().getIdClassReference().getIdClass());
+
+ //test setting @IdClass value to null
+ idClassAnnotation.setValue(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName());
+ assertNull(getJavaEntity().getIdClassReference().getIdClass());
+
+ //reset @IdClass value and then remove @IdClass
+ idClassAnnotation = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME);
+ idClassAnnotation.setValue(existentIdClassName);
+ typeResource.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName());
+ assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME));
+ assertNull(getJavaEntity().getIdClassReference().getIdClass());
+ }
+
+ public void testModifyIdClass() throws Exception {
+ createTestEntity();
+ createTestIdClass();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+
+ assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName());
+ assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME));
+ assertNull(getJavaEntity().getIdClassReference().getIdClass());
+
+ String nonExistentIdClassName = PACKAGE_NAME_ + "Foo";
+ getJavaEntity().getIdClassReference().setSpecifiedIdClassName(nonExistentIdClassName);
+ assertEquals(nonExistentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue());
+ assertEquals(nonExistentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName());
+ assertNull(getJavaEntity().getIdClassReference().getIdClass());
+
+ String existentIdClassName = PACKAGE_NAME_ + "TestTypeId";
+ getJavaEntity().getIdClassReference().setSpecifiedIdClassName(existentIdClassName);
+ assertEquals(existentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue());
+ assertEquals(existentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName());
+ assertNotNull(getJavaEntity().getIdClassReference().getIdClass());
+
+ getJavaEntity().getIdClassReference().setSpecifiedIdClassName(null);
+ assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName());
+ assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME));
+ assertNull(getJavaEntity().getIdClassReference().getIdClass());
+ }
+
+ public void testGetPrimaryKeyColumnNameWithAttributeOverride() throws Exception {
+ createTestMappedSuperclass();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ Iterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs();
+ JavaPersistentType entityPersistentType = classRefs.next().getJavaPersistentType();
+ JavaEntity javaEntity = (JavaEntity) entityPersistentType.getMapping();
+ JavaPersistentType mappedSuperclassPersistentType = classRefs.next().getJavaPersistentType();
+
+ assertEquals("id", javaEntity.getPrimaryKeyColumnName());
+
+ ((JavaIdMapping) mappedSuperclassPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID");
+ assertEquals("MY_ID", javaEntity.getPrimaryKeyColumnName());
+
+ ListIterator<JavaVirtualAttributeOverride> virtualAttributeOverrides = javaEntity.getAttributeOverrideContainer().virtualOverrides();
+ virtualAttributeOverrides.next();
+ virtualAttributeOverrides.next();
+ JavaVirtualAttributeOverride virtualOverride = virtualAttributeOverrides.next();
+ assertEquals("id", virtualOverride.getName());
+
+ virtualOverride.convertToSpecified().getColumn().setSpecifiedName("ID");
+ assertEquals("ID", javaEntity.getPrimaryKeyColumnName());
+ }
+
+ public void testDiscriminatorValueIsUndefinedConcreteClass() throws Exception {
+ createTestEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertTrue(getJavaEntity().discriminatorValueIsUndefined());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ assertFalse(getJavaEntity().discriminatorValueIsUndefined());
+ }
+
+ public void testDiscriminatorValueIsUndefinedAbstractClass() throws Exception {
+ createTestAbstractEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ assertTrue(getJavaEntity().discriminatorValueIsUndefined());
+
+ createTestSubType();
+ addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME);
+ assertTrue(getJavaEntity().discriminatorValueIsUndefined());
+ }
+
+ public void testSpecifiedDiscriminatorColumnIsAllowed() throws Exception {
+ createAbstractTestEntity();
+ createTestSubType();
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs();
+ Entity concreteEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping();
+ assertEquals("AnnotationTestTypeChild", concreteEntity.getName());
+
+ Entity abstractEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping();
+ assertEquals(TYPE_NAME, abstractEntity.getName());
+
+ //table-per-class, no discriminator column allowed
+ assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed());
+ assertFalse(abstractEntity.specifiedDiscriminatorColumnIsAllowed());
+
+
+ //single-table, discriminator column allowed on root entity
+ abstractEntity.setSpecifiedInheritanceStrategy(null);
+ assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed());
+ assertTrue(abstractEntity.specifiedDiscriminatorColumnIsAllowed());
+ }
+
+ public void testAbstractEntityGetDefaultDiscriminatorColumnNameTablePerClassInheritance() throws Exception {
+ createAbstractTestEntity();
+ createTestSubType();
+
+ addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild");
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs();
+ Entity concreteEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping();
+ assertEquals("AnnotationTestTypeChild", concreteEntity.getName());
+
+ Entity abstractEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping();
+ assertEquals(TYPE_NAME, abstractEntity.getName());
+
+
+ assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getSpecifiedInheritanceStrategy());
+ assertEquals(null, concreteEntity.getSpecifiedInheritanceStrategy());
+ assertEquals(InheritanceType.TABLE_PER_CLASS, concreteEntity.getDefaultInheritanceStrategy());
+
+
+ assertTrue(abstractEntity.discriminatorValueIsUndefined());
+ assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed());
+ assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultName());
+ assertEquals(null, concreteEntity.getDiscriminatorColumn().getDefaultName());
+
+ assertTrue(abstractEntity.discriminatorValueIsUndefined());
+ assertEquals(null, abstractEntity.getDefaultDiscriminatorValue());
+ assertTrue(concreteEntity.discriminatorValueIsUndefined());
+ assertEquals(null, concreteEntity.getDefaultDiscriminatorValue());
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaGeneratedValueTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaGeneratedValueTests.java
new file mode 100644
index 0000000000..f904a0353d
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaGeneratedValueTests.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.context.GeneratedValue;
+import org.eclipse.jpt.jpa.core.context.GenerationType;
+import org.eclipse.jpt.jpa.core.context.IdMapping;
+import org.eclipse.jpt.jpa.core.resource.java.GeneratedValueAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaGeneratedValueTests extends ContextModelTestCase
+{
+ private static final String GENERATOR = "MY_GENERATOR";
+
+ private ICompilationUnit createTestEntityWithGeneratedValue() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.GENERATED_VALUE, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Id").append(CR);
+ sb.append("@GeneratedValue(generator=\"" + GENERATOR + "\")");
+ }
+ });
+ }
+
+ public JavaGeneratedValueTests(String name) {
+ super(name);
+ }
+
+ public void testGetGenerator() throws Exception {
+ createTestEntityWithGeneratedValue();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping();
+ assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator());
+
+ //change resource model sequenceGenerator name, verify the context model is updated
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE);
+
+ generatedValue.setGenerator("foo");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals("foo", idMapping.getGeneratedValue().getGenerator());
+ }
+
+ public void testSetSpecifiedGenerator() throws Exception {
+ createTestEntityWithGeneratedValue();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping();
+ assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator());
+
+ idMapping.getGeneratedValue().setSpecifiedGenerator("foo");
+
+ assertEquals("foo", idMapping.getGeneratedValue().getGenerator());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE);
+
+ assertEquals("foo", generatedValue.getGenerator());
+ }
+
+ public void testSetSpecifiedNameNull() throws Exception {
+ createTestEntityWithGeneratedValue();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping();
+ assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator());
+
+ idMapping.getGeneratedValue().setSpecifiedGenerator(null);
+
+ assertNotNull(idMapping.getGeneratedValue());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE);
+
+ assertNotNull(generatedValue);
+ }
+
+ public void testGetStrategy() throws Exception {
+ createTestEntityWithGeneratedValue();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping();
+ assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy());
+
+ //change resource model sequenceGenerator name, verify the context model is updated
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE);
+
+ generatedValue.setStrategy(org.eclipse.jpt.jpa.core.resource.java.GenerationType.IDENTITY);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(GenerationType.IDENTITY, idMapping.getGeneratedValue().getStrategy());
+ assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getDefaultStrategy());
+ }
+
+ public void testSetSpecifiedStrategy() throws Exception {
+ createTestEntityWithGeneratedValue();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping();
+ assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy());
+
+ idMapping.getGeneratedValue().setSpecifiedStrategy(GenerationType.IDENTITY);
+
+ assertEquals(GenerationType.IDENTITY, idMapping.getGeneratedValue().getStrategy());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE);
+
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.GenerationType.IDENTITY, generatedValue.getStrategy());
+
+ idMapping.getGeneratedValue().setSpecifiedStrategy(null);
+
+ assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy());
+ generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE);
+ assertNotNull(generatedValue);
+ assertNull(generatedValue.getStrategy());
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaIdMappingTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaIdMappingTests.java
new file mode 100644
index 0000000000..d756109f2d
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaIdMappingTests.java
@@ -0,0 +1,715 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.BasicMapping;
+import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping;
+import org.eclipse.jpt.jpa.core.context.EmbeddedMapping;
+import org.eclipse.jpt.jpa.core.context.IdMapping;
+import org.eclipse.jpt.jpa.core.context.ManyToManyMapping;
+import org.eclipse.jpt.jpa.core.context.ManyToOneMapping;
+import org.eclipse.jpt.jpa.core.context.OneToManyMapping;
+import org.eclipse.jpt.jpa.core.context.OneToOneMapping;
+import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.TemporalConverter;
+import org.eclipse.jpt.jpa.core.context.TemporalType;
+import org.eclipse.jpt.jpa.core.context.TransientMapping;
+import org.eclipse.jpt.jpa.core.context.VersionMapping;
+import org.eclipse.jpt.jpa.core.resource.java.BasicAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.GeneratedValueAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.SequenceGeneratorAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.TableGeneratorAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.TemporalAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.TransientAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.VersionAnnotation;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaIdMappingTests extends ContextModelTestCase
+{
+
+ private ICompilationUnit createTestEntityWithIdMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Id").append(CR);
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithTemporal() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.TEMPORAL, JPA.TEMPORAL_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Id").append(CR);
+ sb.append("@Temporal(TemporalType.TIMESTAMP)").append(CR);
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithIdMappingGeneratedValue() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.GENERATED_VALUE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Id").append(CR);
+ sb.append("@GeneratedValue").append(CR);
+ }
+ });
+ }
+
+ public JavaIdMappingTests(String name) {
+ super(name);
+ }
+
+ public void testMorphToBasicMapping() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ idMapping.addGeneratedValue();
+ idMapping.getGeneratorContainer().addTableGenerator();
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+ assertFalse(idMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToDefault() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ idMapping.addGeneratedValue();
+ idMapping.getGeneratorContainer().addTableGenerator();
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+ assertFalse(idMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY);
+ assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToVersionMapping() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ idMapping.addGeneratedValue();
+ idMapping.getGeneratorContainer().addTableGenerator();
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+ assertFalse(idMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName());
+ assertEquals(TemporalType.TIME, ((TemporalConverter) ((VersionMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToEmbeddedMapping() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ idMapping.addGeneratedValue();
+ idMapping.getGeneratorContainer().addTableGenerator();
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+ assertFalse(idMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToTransientMapping() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ idMapping.addGeneratedValue();
+ idMapping.getGeneratorContainer().addTableGenerator();
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+ assertFalse(idMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof TransientMapping);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToEmbeddedIdMapping() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ idMapping.addGeneratedValue();
+ idMapping.getGeneratorContainer().addTableGenerator();
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+ assertFalse(idMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToOneToOneMapping() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ idMapping.addGeneratedValue();
+ idMapping.getGeneratorContainer().addTableGenerator();
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+ assertFalse(idMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToOneToManyMapping() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ idMapping.addGeneratedValue();
+ idMapping.getGeneratorContainer().addTableGenerator();
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+ assertFalse(idMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToManyToOneMapping() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ idMapping.addGeneratedValue();
+ idMapping.getGeneratorContainer().addTableGenerator();
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+ assertFalse(idMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testMorphToManyToManyMapping() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertFalse(idMapping.isDefault());
+ idMapping.getColumn().setSpecifiedName("FOO");
+ idMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME);
+ idMapping.addGeneratedValue();
+ idMapping.getGeneratorContainer().addTableGenerator();
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+ assertFalse(idMapping.isDefault());
+
+ persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME));
+ assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME));
+ assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testGetTemporal() throws Exception {
+ createTestEntityWithTemporal();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+
+ assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) idMapping.getConverter()).getTemporalType());
+ }
+
+ public void testSetTemporal() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertNull(idMapping.getConverter().getType());
+
+ idMapping.setConverter(TemporalConverter.class);
+ ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME);
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+
+ assertEquals(org.eclipse.jpt.jpa.core.resource.java.TemporalType.TIME, temporal.getValue());
+
+ idMapping.setConverter(null);
+ assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testGetTemporalUpdatesFromResourceModelChange() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+
+ assertNull(idMapping.getConverter().getType());
+
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ temporal.setValue(org.eclipse.jpt.jpa.core.resource.java.TemporalType.DATE);
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals(TemporalType.DATE, ((TemporalConverter) idMapping.getConverter()).getTemporalType());
+
+ attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+
+ assertNull(idMapping.getConverter().getType());
+ assertFalse(idMapping.isDefault());
+ assertSame(idMapping, persistentAttribute.getMapping());
+ }
+
+ public void testGetColumn() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+
+ assertNull(idMapping.getColumn().getSpecifiedName());
+ assertEquals("id", idMapping.getColumn().getName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN);
+ column.setName("foo");
+ getJpaProject().synchronizeContextModel();
+
+ assertEquals("foo", idMapping.getColumn().getSpecifiedName());
+ assertEquals("foo", idMapping.getColumn().getName());
+ assertEquals("id", idMapping.getColumn().getDefaultName());
+ }
+
+ public void testGetSequenceGenerator() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertNull(idMapping.getGeneratorContainer().getSequenceGenerator());
+ assertEquals(0, idMapping.getPersistenceUnit().generatorsSize());
+
+ JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next();
+ resourceAttribute.addAnnotation(JPA.SEQUENCE_GENERATOR);
+ getJpaProject().synchronizeContextModel();
+ assertNotNull(idMapping.getGeneratorContainer().getSequenceGenerator());
+ assertEquals(2, resourceAttribute.annotationsSize());
+ assertEquals(1, idMapping.getPersistenceUnit().generatorsSize());
+
+ idMapping.getGeneratorContainer().getSequenceGenerator().setName("foo");
+ getJpaProject().synchronizeContextModel();
+ assertEquals(1, idMapping.getPersistenceUnit().generatorsSize());
+ }
+
+ public void testAddSequenceGenerator() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+
+ assertNull(idMapping.getGeneratorContainer().getSequenceGenerator());
+
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ assertNotNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR));
+ assertNotNull(idMapping.getGeneratorContainer().getSequenceGenerator());
+
+ //try adding another sequence generator, should get an IllegalStateException
+ try {
+ idMapping.getGeneratorContainer().addSequenceGenerator();
+ } catch (IllegalStateException e) {
+ return;
+ }
+ fail("IllegalStateException not thrown");
+ }
+
+ public void testRemoveSequenceGenerator() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(JPA.SEQUENCE_GENERATOR);
+ getJpaProject().synchronizeContextModel();
+
+
+ idMapping.getGeneratorContainer().removeSequenceGenerator();
+
+ assertNull(idMapping.getGeneratorContainer().getSequenceGenerator());
+ assertNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR));
+
+ //try removing the sequence generator again, should get an IllegalStateException
+ try {
+ idMapping.getGeneratorContainer().removeSequenceGenerator();
+ } catch (IllegalStateException e) {
+ return;
+ }
+ fail("IllegalStateException not thrown");
+ }
+
+ public void testGetTableGenerator() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+ assertNull(idMapping.getGeneratorContainer().getTableGenerator());
+ assertEquals(0, idMapping.getPersistenceUnit().generatorsSize());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(JPA.TABLE_GENERATOR);
+ getJpaProject().synchronizeContextModel();
+ assertNotNull(idMapping.getGeneratorContainer().getTableGenerator());
+ assertEquals(2, attributeResource.annotationsSize());
+ assertEquals(1, idMapping.getPersistenceUnit().generatorsSize());
+
+ idMapping.getGeneratorContainer().getTableGenerator().setName("foo");
+ assertEquals(1, idMapping.getPersistenceUnit().generatorsSize());
+ }
+
+ public void testAddTableGenerator() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+
+ assertNull(idMapping.getGeneratorContainer().getTableGenerator());
+
+ idMapping.getGeneratorContainer().addTableGenerator();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ assertNotNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR));
+ assertNotNull(idMapping.getGeneratorContainer().getTableGenerator());
+
+ //try adding another table generator, should get an IllegalStateException
+ try {
+ idMapping.getGeneratorContainer().addTableGenerator();
+ } catch (IllegalStateException e) {
+ return;
+ }
+ fail("IllegalStateException not thrown");
+ }
+
+ public void testRemoveTableGenerator() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(JPA.TABLE_GENERATOR);
+ getJpaProject().synchronizeContextModel();
+
+
+ idMapping.getGeneratorContainer().removeTableGenerator();
+
+ assertNull(idMapping.getGeneratorContainer().getTableGenerator());
+ assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR));
+
+ //try removing the table generator again, should get an IllegalStateException
+ try {
+ idMapping.getGeneratorContainer().removeTableGenerator();
+ } catch (IllegalStateException e) {
+ return;
+ }
+ fail("IllegalStateException not thrown");
+ }
+
+ public void testGetGeneratedValue() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+
+ assertNull(idMapping.getGeneratedValue());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(JPA.GENERATED_VALUE);
+ getJpaProject().synchronizeContextModel();
+
+ assertNotNull(idMapping.getGeneratedValue());
+ assertEquals(2, attributeResource.annotationsSize());
+ }
+
+ public void testGetGeneratedValue2() throws Exception {
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+ createTestEntityWithIdMappingGeneratedValue();
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ assertNotNull(idMapping.getGeneratedValue());
+ assertEquals(2, attributeResource.annotationsSize());
+ }
+
+ public void testAddGeneratedValue() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+
+ assertNull(idMapping.getGeneratedValue());
+
+ idMapping.addGeneratedValue();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ assertNotNull(attributeResource.getAnnotation(JPA.GENERATED_VALUE));
+ assertNotNull(idMapping.getGeneratedValue());
+
+ //try adding another generated value, should get an IllegalStateException
+ try {
+ idMapping.addGeneratedValue();
+ } catch (IllegalStateException e) {
+ return;
+ }
+ fail("IllegalStateException not thrown");
+ }
+
+ public void testRemoveGeneratedValue() throws Exception {
+ createTestEntityWithIdMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next();
+ IdMapping idMapping = (IdMapping) persistentAttribute.getMapping();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ attributeResource.addAnnotation(JPA.GENERATED_VALUE);
+ getJpaProject().synchronizeContextModel();
+
+ idMapping.removeGeneratedValue();
+
+ assertNull(idMapping.getGeneratedValue());
+ assertNull(attributeResource.getAnnotation(JPA.GENERATED_VALUE));
+
+ //try removing the generatedValue again, should get an IllegalStateException
+ try {
+ idMapping.removeGeneratedValue();
+ } catch (IllegalStateException e) {
+ return;
+ }
+ fail("IllegalStateException not thrown");
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaJoinColumnTests.java
new file mode 100644
index 0000000000..71dd7f285f
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaJoinColumnTests.java
@@ -0,0 +1,549 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumn;
+import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumnRelationshipStrategy;
+import org.eclipse.jpt.jpa.core.context.java.JavaOneToOneMapping;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaJoinColumnTests extends ContextModelTestCase
+{
+ public JavaJoinColumnTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestEntityWithOneToOne() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@OneToOne").append(CR);
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithValidOneToOne() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@OneToOne").append(CR);
+ sb.append(" private Project project;").append(CR);
+ }
+ });
+ }
+
+ private void createTargetEntity() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ID);
+ sb.append(";");
+ sb.append(CR);
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class Project {").append(CR);
+ sb.append(CR);
+ sb.append(" @Id").append(CR);
+ sb.append(" private int proj_id;").append(CR);
+ sb.append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter);
+ }
+
+ public void testUpdateSpecifiedName() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next();
+
+ JoinColumnAnnotation joinColumnAnnotation = (JoinColumnAnnotation) resourceAttribute.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+
+ assertEquals(0, joinColumns.specifiedJoinColumnsSize());
+ assertNull(joinColumnAnnotation);
+
+
+ //set name in the resource model, verify context model updated
+ joinColumnAnnotation = (JoinColumnAnnotation) resourceAttribute.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ joinColumnAnnotation.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next();
+ assertEquals("FOO", joinColumn.getSpecifiedName());
+ assertEquals("FOO", joinColumnAnnotation.getName());
+
+ //set name to null, annotation is NOT removed
+ joinColumn.setSpecifiedName(null);
+ assertEquals(1, joinColumns.specifiedJoinColumnsSize());
+ joinColumnAnnotation = (JoinColumnAnnotation) resourceAttribute.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ assertNull(joinColumnAnnotation.getName());
+ }
+
+ public void testModifySpecifiedName() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next();
+
+
+ JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0);
+ //set name in the context model, verify resource model modified
+ joinColumn.setSpecifiedName("foo");
+ JoinColumnAnnotation joinColumnAnnotation = (JoinColumnAnnotation) resourceAttribute.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", joinColumn.getSpecifiedName());
+ assertEquals("foo", joinColumnAnnotation.getName());
+
+ //set name to null in the context model
+ joinColumn.setSpecifiedName(null);
+ assertNull(joinColumn.getSpecifiedName());
+ joinColumnAnnotation = (JoinColumnAnnotation) resourceAttribute.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ assertNull(joinColumnAnnotation.getName());
+ }
+
+ // <attribute name>_<referenced column name>
+ // or
+ // <target entity name>_<referenced column name>
+ public void testDefaultName() throws Exception {
+ createTestEntityWithValidOneToOne();
+ createTargetEntity();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+
+// JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+// JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnJoiningStrategy();
+// JavaJoinColumn defaultJavaJoinColumn = joinColumns.getDefaultJoinColumn();
+//
+// assertNull(defaultJavaJoinColumn.getDefaultName());
+//TODO test default join column name
+// //add target entity to the persistence unit, now join table name is [table name]_[target table name]
+// addXmlClassRef(PACKAGE_NAME + ".Project");
+// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName());
+//
+// JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME);
+// JavaPersistentAttributeResource attributeResource = typeResource.attributes().next();
+// assertNull(attributeResource.annotation(JoinTable.ANNOTATION_NAME));
+//
+// //target entity does not resolve, default name is null
+// manyToManyMapping.setSpecifiedTargetEntity("Foo");
+// assertNull(joinTable.getDefaultName());
+//
+// //default target entity does resolve, so default name is again [table name]_[target table name]
+// manyToManyMapping.setSpecifiedTargetEntity(null);
+// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName());
+//
+// //add the join table annotation, verify default join table name is the same
+// attributeResource.addAnnotation(JoinTable.ANNOTATION_NAME);
+// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName());
+// assertNotNull(attributeResource.annotation(JoinTable.ANNOTATION_NAME));
+//
+// //set a table on the target entity, very default join table name updates
+// manyToManyMapping.getResolvedTargetEntity().getTable().setSpecifiedName("FOO");
+// assertEquals(TYPE_NAME + "_FOO", joinTable.getDefaultName());
+//
+// //set a table on the owning entity, very default join table name updates
+// javaEntity().getTable().setSpecifiedName("BAR");
+// assertEquals("BAR_FOO", joinTable.getDefaultName());
+ }
+
+ public void testUpdateSpecifiedReferencedColumnName() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+
+ assertEquals(0, joinColumns.specifiedJoinColumnsSize());
+ assertNull(javaJoinColumn);
+
+
+ //set referenced column name in the resource model, verify context model updated
+ javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ javaJoinColumn.setName("FOO");
+ javaJoinColumn.setReferencedColumnName("BAR");
+ getJpaProject().synchronizeContextModel();
+ JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next();
+ assertEquals("BAR", joinColumn.getSpecifiedReferencedColumnName());
+ assertEquals("BAR", javaJoinColumn.getReferencedColumnName());
+
+ //set referenced column name to null in the resource model,
+ javaJoinColumn.setReferencedColumnName(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinColumn.getSpecifiedReferencedColumnName());
+ assertNull("BAR", javaJoinColumn.getReferencedColumnName());
+ }
+
+ public void testModifySpecifiedReferencedColumnName() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0);
+ //set referenced column name in the context model, verify resource model modified
+ joinColumn.setSpecifiedName("foo");
+ joinColumn.setSpecifiedReferencedColumnName("BAR");
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", joinColumn.getSpecifiedReferencedColumnName());
+ assertEquals("BAR", javaJoinColumn.getReferencedColumnName());
+
+ //set referenced column name to null in the context model
+ joinColumn.setSpecifiedReferencedColumnName(null);
+ assertNull(joinColumn.getSpecifiedReferencedColumnName());
+ assertNull(javaJoinColumn.getReferencedColumnName());
+ }
+
+ public void testDefaultReferencedColumnName() throws Exception {
+ //TODO test default join column referenced column name
+
+ }
+
+ public void testUpdateTable() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+
+ assertEquals(0, joinColumns.specifiedJoinColumnsSize());
+ assertNull(javaJoinColumn);
+
+
+ //set table in the resource model, verify context model updated
+ javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ javaJoinColumn.setName("FOO");
+ javaJoinColumn.setTable("BAR");
+ getJpaProject().synchronizeContextModel();
+ JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next();
+ assertEquals("BAR", joinColumn.getSpecifiedTable());
+ assertEquals("BAR", javaJoinColumn.getTable());
+
+ //set table to null in the resource model,
+ javaJoinColumn.setTable(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinColumn.getSpecifiedTable());
+ assertNull("BAR", javaJoinColumn.getTable());
+ }
+
+ public void testModifyTable() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+
+ JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0);
+ //set table in the context model, verify resource model modified
+ joinColumn.setSpecifiedName("foo");
+ joinColumn.setSpecifiedTable("BAR");
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ assertEquals("BAR", joinColumn.getSpecifiedTable());
+ assertEquals("BAR", javaJoinColumn.getTable());
+
+ //set table to null in the context model
+ joinColumn.setSpecifiedTable(null);
+ assertNull(joinColumn.getSpecifiedTable());
+ assertNull(javaJoinColumn.getTable());
+ }
+
+ public void testDefaultTable() throws Exception {
+ //TODO test default join column table
+
+ }
+
+ public void testUpdateUnique() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+
+ assertEquals(0, joinColumns.specifiedJoinColumnsSize());
+ assertNull(javaJoinColumn);
+
+
+ //set unique in the resource model, verify context model updated
+ javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ javaJoinColumn.setName("FOO");
+ javaJoinColumn.setUnique(Boolean.TRUE);
+ getJpaProject().synchronizeContextModel();
+ JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next();
+ assertEquals(Boolean.TRUE, joinColumn.getSpecifiedUnique());
+ assertEquals(Boolean.TRUE, javaJoinColumn.getUnique());
+
+ //set unique to null in the resource model,
+ javaJoinColumn.setUnique(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinColumn.getSpecifiedUnique());
+ assertNull(javaJoinColumn.getUnique());
+ }
+
+ public void testModifyUnique() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+
+ JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0);
+ //set unique in the context model, verify resource model modified
+ joinColumn.setSpecifiedName("foo");
+ joinColumn.setSpecifiedUnique(Boolean.TRUE);
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ assertEquals(Boolean.TRUE, joinColumn.getSpecifiedUnique());
+ assertEquals(Boolean.TRUE, javaJoinColumn.getUnique());
+
+ //set unique to null in the context model
+ joinColumn.setSpecifiedUnique(null);
+ assertNull(joinColumn.getSpecifiedUnique());
+ assertNull(javaJoinColumn.getUnique());
+ }
+
+ public void testUpdateNullable() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+
+ assertEquals(0, joinColumns.specifiedJoinColumnsSize());
+ assertNull(javaJoinColumn);
+
+
+ //set nullable in the resource model, verify context model updated
+ javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ javaJoinColumn.setName("FOO");
+ javaJoinColumn.setNullable(Boolean.FALSE);
+ getJpaProject().synchronizeContextModel();
+ JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next();
+ assertEquals(Boolean.FALSE, joinColumn.getSpecifiedNullable());
+ assertEquals(Boolean.FALSE, javaJoinColumn.getNullable());
+
+ //set nullable to null in the resource model,
+ javaJoinColumn.setNullable(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinColumn.getSpecifiedNullable());
+ assertNull(javaJoinColumn.getNullable());
+ }
+
+ public void testModifyNullable() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+
+ JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0);
+ //set nullable in the context model, verify resource model modified
+ joinColumn.setSpecifiedName("foo");
+ joinColumn.setSpecifiedNullable(Boolean.FALSE);
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ assertEquals(Boolean.FALSE, joinColumn.getSpecifiedNullable());
+ assertEquals(Boolean.FALSE, javaJoinColumn.getNullable());
+
+ //set nullable to null in the context model
+ joinColumn.setSpecifiedNullable(null);
+ assertNull(joinColumn.getSpecifiedNullable());
+ assertNull(javaJoinColumn.getNullable());
+ }
+
+ public void testUpdateInsertable() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+
+ assertEquals(0, joinColumns.specifiedJoinColumnsSize());
+ assertNull(javaJoinColumn);
+
+
+ //set insertable in the resource model, verify context model updated
+ javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ javaJoinColumn.setName("FOO");
+ javaJoinColumn.setInsertable(Boolean.FALSE);
+ getJpaProject().synchronizeContextModel();
+ JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next();
+ assertEquals(Boolean.FALSE, joinColumn.getSpecifiedInsertable());
+ assertEquals(Boolean.FALSE, javaJoinColumn.getInsertable());
+
+ //set insertable to null in the resource model,
+ javaJoinColumn.setInsertable(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinColumn.getSpecifiedInsertable());
+ assertNull(javaJoinColumn.getInsertable());
+ }
+
+ public void testModifyInsertable() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+
+ JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0);
+ //set insertable in the context model, verify resource model modified
+ joinColumn.setSpecifiedName("foo");
+ joinColumn.setSpecifiedInsertable(Boolean.FALSE);
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ assertEquals(Boolean.FALSE, joinColumn.getSpecifiedInsertable());
+ assertEquals(Boolean.FALSE, javaJoinColumn.getInsertable());
+
+ //set insertable to null in the context model
+ joinColumn.setSpecifiedInsertable(null);
+ assertNull(joinColumn.getSpecifiedInsertable());
+ assertNull(javaJoinColumn.getInsertable());
+ }
+
+ public void testUpdateUpdatable() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+
+ assertEquals(0, joinColumns.specifiedJoinColumnsSize());
+ assertNull(javaJoinColumn);
+
+
+ //set updatable in the resource model, verify context model updated
+ javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ javaJoinColumn.setName("FOO");
+ javaJoinColumn.setUpdatable(Boolean.FALSE);
+ getJpaProject().synchronizeContextModel();
+ JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next();
+ assertEquals(Boolean.FALSE, joinColumn.getSpecifiedUpdatable());
+ assertEquals(Boolean.FALSE, javaJoinColumn.getUpdatable());
+
+ //set updatable to null in the resource model,
+ javaJoinColumn.setUpdatable(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinColumn.getSpecifiedUpdatable());
+ assertNull(javaJoinColumn.getUpdatable());
+ }
+
+ public void testModifyUpdatable() throws Exception {
+ createTestEntityWithOneToOne();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+
+ JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0);
+ //set updatable in the context model, verify resource model modified
+ joinColumn.setSpecifiedName("foo");
+ joinColumn.setSpecifiedUpdatable(Boolean.FALSE);
+
+ JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME);
+ assertEquals(Boolean.FALSE, joinColumn.getSpecifiedUpdatable());
+ assertEquals(Boolean.FALSE, javaJoinColumn.getUpdatable());
+
+ //set updatable to null in the context model
+ joinColumn.setSpecifiedUpdatable(null);
+ assertNull(joinColumn.getSpecifiedUpdatable());
+ assertNull(javaJoinColumn.getUpdatable());
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaJoinTableTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaJoinTableTests.java
new file mode 100644
index 0000000000..1192ab6221
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaJoinTableTests.java
@@ -0,0 +1,1177 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.IdMapping;
+import org.eclipse.jpt.jpa.core.context.JoinColumn;
+import org.eclipse.jpt.jpa.core.context.JoinTable;
+import org.eclipse.jpt.jpa.core.context.UniqueConstraint;
+import org.eclipse.jpt.jpa.core.context.java.JavaJoinColumn;
+import org.eclipse.jpt.jpa.core.context.java.JavaJoinTable;
+import org.eclipse.jpt.jpa.core.context.java.JavaManyToManyMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaUniqueConstraint;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.JoinTableAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.UniqueConstraintAnnotation;
+import org.eclipse.jpt.jpa.core.tests.internal.context.ContextModelTestCase;
+
+@SuppressWarnings("nls")
+public class JavaJoinTableTests extends ContextModelTestCase
+{
+ public JavaJoinTableTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestEntityWithManyToMany() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@ManyToMany").append(CR);
+ }
+ });
+ }
+
+ private ICompilationUnit createTestEntityWithValidManyToMany() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, "java.util.Collection");
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@ManyToMany").append(CR);
+ sb.append(" private Collection<Project> projects;").append(CR);
+ }
+ });
+ }
+
+ private void createTargetEntity() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ID);
+ sb.append(";");
+ sb.append(CR);
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class Project {").append(CR);
+ sb.append(CR);
+ sb.append(" @Id").append(CR);
+ sb.append(" private int proj_id;").append(CR);
+ sb.append(CR);
+ sb.append("}");
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter);
+ }
+
+ private void createTargetEntityWithBackPointer() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ID);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.MANY_TO_MANY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class Project {").append(CR);
+ sb.append(CR);
+ sb.append(" @Id").append(CR);
+ sb.append(" private int proj_id;").append(CR);
+ sb.append(" @ManyToMany(mappedBy=\"projects\"").append(CR);
+ sb.append(" private java.util.Collection<" + TYPE_NAME + "> employees;").append(CR);
+ sb.append(CR);
+ sb.append("}");
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter);
+ }
+
+ public void testUpdateSpecifiedName() throws Exception {
+ createTestEntityWithManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+
+ assertNull(joinTable.getSpecifiedName());
+ assertNull(javaJoinTable);
+
+
+ //set name in the resource model, verify context model updated
+ attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ javaJoinTable.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ assertEquals("FOO", joinTable.getSpecifiedName());
+ assertEquals("FOO", javaJoinTable.getName());
+
+ //set name to null in the resource model
+ javaJoinTable.setName(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinTable.getSpecifiedName());
+ assertNull(javaJoinTable.getName());
+
+ javaJoinTable.setName("FOO");
+ getJpaProject().synchronizeContextModel();
+ assertEquals("FOO", joinTable.getSpecifiedName());
+ assertEquals("FOO", javaJoinTable.getName());
+
+ attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinTable.getSpecifiedName());
+ assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testModifySpecifiedName() throws Exception {
+ createTestEntityWithManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+
+ assertNull(joinTable.getSpecifiedName());
+ assertNull(joinTableAnnotation);
+
+ //set name in the context model, verify resource model modified
+ joinTable.setSpecifiedName("foo");
+ joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", joinTable.getSpecifiedName());
+ assertEquals("foo", joinTableAnnotation.getName());
+
+ //set name to null in the context model
+ joinTable.setSpecifiedName(null);
+ assertNull(joinTable.getSpecifiedName());
+ joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ assertNull(joinTableAnnotation.getName());
+ }
+
+ public void testDefaultName() throws Exception {
+ createTestEntityWithValidManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+
+ //joinTable default name is null because targetEntity is not in the persistence unit
+ assertNull(joinTable.getDefaultName());
+
+ //add target entity to the persistence unit, now join table name is [table name]_[target table name]
+ createTargetEntity();
+ addXmlClassRef(PACKAGE_NAME + ".Project");
+ assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME));
+
+ //target entity does not resolve, default name is null
+ manyToManyMapping.setSpecifiedTargetEntity("Foo");
+ assertNull(joinTable.getDefaultName());
+
+ //default target entity does resolve, so default name is again [table name]_[target table name]
+ manyToManyMapping.setSpecifiedTargetEntity(null);
+ assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName());
+
+ //add the join table annotation, verify default join table name is the same
+ attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName());
+ assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME));
+
+ //set a table on the target entity, very default join table name updates
+ manyToManyMapping.getResolvedTargetEntity().getTable().setSpecifiedName("FOO");
+ assertEquals(TYPE_NAME + "_FOO", joinTable.getDefaultName());
+
+ //set a table on the owning entity, very default join table name updates
+ getJavaEntity().getTable().setSpecifiedName("BAR");
+ assertEquals("BAR_FOO", joinTable.getDefaultName());
+ }
+
+ public void testDefaultJoinColumns() throws Exception {
+ createTestEntityWithValidManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+ JoinColumn joinColumn = joinTable.joinColumns().next();
+ JoinColumn inverseJoinColumn = joinTable.inverseJoinColumns().next();
+
+ //joinTable default name is null because targetEntity is not in the persistence unit
+ assertNull(joinColumn.getDefaultName());
+ assertNull(joinColumn.getDefaultReferencedColumnName());
+ assertNull(inverseJoinColumn.getDefaultName());
+ assertNull(inverseJoinColumn.getDefaultReferencedColumnName());
+
+ //add target entity to the persistence unit, join column default name and referenced column still null because owning entity has no primary key
+ createTargetEntity();
+ addXmlClassRef(PACKAGE_NAME + ".Project");
+ assertNull(joinColumn.getDefaultName());
+ assertNull(joinColumn.getDefaultReferencedColumnName());
+ assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName());
+ assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName());
+
+ //create primary key in owning entity
+ getJavaPersistentType().getAttributeNamed("id").setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals(TYPE_NAME + "_id", joinColumn.getDefaultName());
+ assertEquals("id", joinColumn.getDefaultReferencedColumnName());
+ assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName());
+ assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName());
+
+ //set specified column name on primary key in owning entity
+ ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID");
+ assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName());
+ assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName());
+ assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName());
+ assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME));
+
+ //target entity does not resolve, inverse join column name and referenced column name is null
+ manyToManyMapping.setSpecifiedTargetEntity("Foo");
+ assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName());
+ assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName());
+ assertNull(inverseJoinColumn.getDefaultName());
+ assertNull(inverseJoinColumn.getDefaultReferencedColumnName());
+
+ //default target entity does resolve, so defaults for join column are back
+ manyToManyMapping.setSpecifiedTargetEntity(null);
+ assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName());
+ assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName());
+ assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName());
+ assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName());
+
+ //add the join table annotation, verify default join table name is the same
+ attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName());
+ assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName());
+ assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName());
+ assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName());
+ assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testDefaultJoinColumnsBidirectionalRelationship() throws Exception {
+ createTestEntityWithValidManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+ JoinColumn joinColumn = joinTable.joinColumns().next();
+ JoinColumn inverseJoinColumn = joinTable.inverseJoinColumns().next();
+
+ //joinTable default name is null because targetEntity is not in the persistence unit
+ assertNull(joinColumn.getDefaultName());
+ assertNull(joinColumn.getDefaultReferencedColumnName());
+ assertNull(inverseJoinColumn.getDefaultName());
+ assertNull(inverseJoinColumn.getDefaultReferencedColumnName());
+
+ //add target entity to the persistence unit, join column default name and referenced column still null because owning entity has no primary key
+ createTargetEntityWithBackPointer();
+ addXmlClassRef(PACKAGE_NAME + ".Project");
+ assertNull(joinColumn.getDefaultName());
+ assertNull(joinColumn.getDefaultReferencedColumnName());
+ assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName());
+ assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName());
+
+ //create primary key in owning entity
+ getJavaPersistentType().getAttributeNamed("id").setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertEquals("employees_id", joinColumn.getDefaultName());
+ assertEquals("id", joinColumn.getDefaultReferencedColumnName());
+ assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName());
+ assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName());
+
+ //set specified column name on primary key in owning entity
+ ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID");
+ assertEquals("employees_MY_ID", joinColumn.getDefaultName());
+ assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName());
+ assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName());
+ assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName());
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+ assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME));
+
+ //target entity does not resolve, inverse join column name and referenced column name is null
+ manyToManyMapping.setSpecifiedTargetEntity("Foo");
+ assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName());
+ assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName());
+ assertNull(inverseJoinColumn.getDefaultName());
+ assertNull(inverseJoinColumn.getDefaultReferencedColumnName());
+
+ //default target entity does resolve, so defaults for join column are back
+ manyToManyMapping.setSpecifiedTargetEntity(null);
+ assertEquals("employees_MY_ID", joinColumn.getDefaultName());
+ assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName());
+ assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName());
+ assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName());
+
+ //add the join table annotation, verify default join table name is the same
+ attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ assertEquals("employees_MY_ID", joinColumn.getDefaultName());
+ assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName());
+ assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName());
+ assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName());
+ assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testUpdateSpecifiedSchema() throws Exception {
+ createTestEntityWithManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+
+ assertNull(joinTable.getSpecifiedSchema());
+ assertNull(javaJoinTable);
+
+
+ //set schema in the resource model, verify context model updated
+ attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ javaJoinTable.setSchema("FOO");
+ getJpaProject().synchronizeContextModel();
+ assertEquals("FOO", joinTable.getSpecifiedSchema());
+ assertEquals("FOO", javaJoinTable.getSchema());
+
+ //set schema to null in the resource model
+ javaJoinTable.setSchema(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinTable.getSpecifiedSchema());
+ assertNull(javaJoinTable.getSchema());
+
+ javaJoinTable.setSchema("FOO");
+ getJpaProject().synchronizeContextModel();
+ assertEquals("FOO", joinTable.getSpecifiedSchema());
+ assertEquals("FOO", javaJoinTable.getSchema());
+
+ attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinTable.getSpecifiedSchema());
+ assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testModifySpecifiedSchema() throws Exception {
+ createTestEntityWithManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+
+ JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next();
+
+ JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+
+ assertNull(joinTable.getSpecifiedSchema());
+ assertNull(joinTableAnnotation);
+
+ //set schema in the context model, verify resource model modified
+ joinTable.setSpecifiedSchema("foo");
+ joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", joinTable.getSpecifiedSchema());
+ assertEquals("foo", joinTableAnnotation.getSchema());
+
+ //set schema to null in the context model
+ joinTable.setSpecifiedSchema(null);
+ assertNull(joinTable.getSpecifiedSchema());
+ joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ assertNull(joinTableAnnotation.getSchema());
+ }
+
+ public void testUpdateSpecifiedCatalog() throws Exception {
+ createTestEntityWithManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+
+ assertNull(joinTable.getSpecifiedCatalog());
+ assertNull(javaJoinTable);
+
+
+ //set catalog in the resource model, verify context model updated
+ attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ javaJoinTable.setCatalog("FOO");
+ getJpaProject().synchronizeContextModel();
+ assertEquals("FOO", joinTable.getSpecifiedCatalog());
+ assertEquals("FOO", javaJoinTable.getCatalog());
+
+ //set catalog to null in the resource model
+ javaJoinTable.setCatalog(null);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinTable.getSpecifiedCatalog());
+ assertNull(javaJoinTable.getCatalog());
+
+ javaJoinTable.setCatalog("FOO");
+ getJpaProject().synchronizeContextModel();
+ assertEquals("FOO", joinTable.getSpecifiedCatalog());
+ assertEquals("FOO", javaJoinTable.getCatalog());
+
+ attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ getJpaProject().synchronizeContextModel();
+ assertNull(joinTable.getSpecifiedCatalog());
+ assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME));
+ }
+
+ public void testModifySpecifiedCatalog() throws Exception {
+ createTestEntityWithManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+
+ JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next();
+
+ JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+
+ assertNull(joinTable.getSpecifiedCatalog());
+ assertNull(joinTableAnnotation);
+
+ //set catalog in the context model, verify resource model modified
+ joinTable.setSpecifiedCatalog("foo");
+ joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ assertEquals("foo", joinTable.getSpecifiedCatalog());
+ assertEquals("foo", joinTableAnnotation.getCatalog());
+
+ //set catalog to null in the context model
+ joinTable.setSpecifiedCatalog(null);
+ assertNull(joinTable.getSpecifiedCatalog());
+ joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ assertNull(joinTableAnnotation.getCatalog());
+ }
+
+ public void testAddSpecifiedJoinColumn() throws Exception {
+ createTestEntityWithManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+
+ JoinColumn joinColumn = joinTable.addSpecifiedJoinColumn(0);
+ joinColumn.setSpecifiedName("FOO");
+
+ JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+
+ assertEquals("FOO", joinTableResource.joinColumnAt(0).getName());
+
+ JoinColumn joinColumn2 = joinTable.addSpecifiedJoinColumn(0);
+ joinColumn2.setSpecifiedName("BAR");
+
+ assertEquals("BAR", joinTableResource.joinColumnAt(0).getName());
+ assertEquals("FOO", joinTableResource.joinColumnAt(1).getName());
+
+ JoinColumn joinColumn3 = joinTable.addSpecifiedJoinColumn(1);
+ joinColumn3.setSpecifiedName("BAZ");
+
+ assertEquals("BAR", joinTableResource.joinColumnAt(0).getName());
+ assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName());
+ assertEquals("FOO", joinTableResource.joinColumnAt(2).getName());
+
+ ListIterator<JavaJoinColumn> joinColumns = joinTable.specifiedJoinColumns();
+ assertEquals(joinColumn2, joinColumns.next());
+ assertEquals(joinColumn3, joinColumns.next());
+ assertEquals(joinColumn, joinColumns.next());
+
+ joinColumns = joinTable.specifiedJoinColumns();
+ assertEquals("BAR", joinColumns.next().getName());
+ assertEquals("BAZ", joinColumns.next().getName());
+ assertEquals("FOO", joinColumns.next().getName());
+ }
+
+ public void testRemoveSpecifiedJoinColumn() throws Exception {
+ createTestEntityWithManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+
+ JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next();
+
+ joinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO");
+ joinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR");
+ joinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ");
+
+ JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ assertEquals(3, joinTableAnnotation.joinColumnsSize());
+
+ joinTable.removeSpecifiedJoinColumn(0);
+ assertEquals(2, joinTableAnnotation.joinColumnsSize());
+ assertEquals("BAR", joinTableAnnotation.joinColumnAt(0).getName());
+ assertEquals("BAZ", joinTableAnnotation.joinColumnAt(1).getName());
+
+ joinTable.removeSpecifiedJoinColumn(0);
+ assertEquals(1, joinTableAnnotation.joinColumnsSize());
+ assertEquals("BAZ", joinTableAnnotation.joinColumnAt(0).getName());
+
+ joinTable.removeSpecifiedJoinColumn(0);
+ assertEquals(0, joinTableAnnotation.joinColumnsSize());
+ }
+
+ public void testMoveSpecifiedJoinColumn() throws Exception {
+ createTestEntityWithManyToMany();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping();
+ JavaJoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable();
+
+ JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME);
+ JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next();
+
+ joinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO");
+ joinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR");
+ joinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ");
+
+ JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME);
+ assertEquals(3, joinTableResource.joinColumnsSize());
+
+
+ joinTab