dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36104
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18483: use CollectionPersister to set manyToMany/oneToMany properties on Property class
------------------------------------------------------------
revno: 18483
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-03-05 11:09:14 +0700
message:
use CollectionPersister to set manyToMany/oneToMany properties on Property class
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2015-02-25 08:23:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2015-03-05 04:09:14 +0000
@@ -195,6 +195,16 @@
*/
private String cascade;
+ /**
+ * Is collection many-to-many.
+ */
+ private boolean manyToMany;
+
+ /**
+ * Is collection one-to-many.
+ */
+ private boolean oneToMany;
+
public Property()
{
}
@@ -534,6 +544,30 @@
this.cascade = cascade;
}
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public boolean isManyToMany()
+ {
+ return manyToMany;
+ }
+
+ public void setManyToMany( boolean manyToMany )
+ {
+ this.manyToMany = manyToMany;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public boolean isOneToMany()
+ {
+ return oneToMany;
+ }
+
+ public void setOneToMany( boolean oneToMany )
+ {
+ this.oneToMany = oneToMany;
+ }
+
public String key()
{
return isCollection() ? collectionName : name;
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java 2015-01-23 04:34:37 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java 2015-03-05 04:09:14 +0000
@@ -32,14 +32,13 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.hibernate.SessionFactory;
+import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.metadata.ClassMetadata;
-import org.hibernate.type.AnyType;
-import org.hibernate.type.AssociationType;
+import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.CollectionType;
-import org.hibernate.type.EntityType;
import org.hibernate.type.SingleColumnType;
import org.hibernate.type.TextType;
import org.hibernate.type.Type;
@@ -158,29 +157,21 @@
property.setName( hibernateProperty.getName() );
property.setCascade( hibernateProperty.getCascade() );
+ property.setCollection( type.isCollectionType() );
property.setSetterMethod( hibernateProperty.getSetter( klass ).getMethod() );
property.setGetterMethod( hibernateProperty.getGetter( klass ).getMethod() );
- if ( type.isCollectionType() )
+ if ( property.isCollection() )
{
CollectionType collectionType = (CollectionType) type;
- property.setCollection( true );
Collection collection = sessionFactoryBean.getConfiguration().getCollectionMapping( collectionType.getRole() );
property.setOwner( !collection.isInverse() );
- }
- else if ( type.isEntityType() )
- {
- EntityType entityType = (EntityType) type;
- }
- else if ( type.isAssociationType() )
- {
- AssociationType associationType = (AssociationType) type;
- }
- else if ( type.isAnyType() )
- {
- AnyType anyType = (AnyType) type;
+
+ CollectionPersister collectionPersister = ((SessionFactoryImplementor) sessionFactory).getCollectionPersister( collection.getRole() );
+ property.setOneToMany( collectionPersister.isOneToMany() );
+ property.setManyToMany( collectionPersister.isManyToMany() );
}
if ( SingleColumnType.class.isInstance( type ) )