← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15250: IdentifiableObjectStore, added property which can be overridden by impls for whether backing obje...

 

------------------------------------------------------------
revno: 15250
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-05-13 11:42:58 +0200
message:
  IdentifiableObjectStore, added property which can be overridden by impls for whether backing object has persisted id properties - some impls do not. Makes it possible to search for an object solely based on uid.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml


--
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-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java	2014-03-23 18:26:50 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java	2014-05-13 09:42:58 +0000
@@ -52,7 +52,30 @@
     extends HibernateGenericStore<T> implements GenericNameableObjectStore<T>
 {
     private static final Log log = LogFactory.getLog( HibernateIdentifiableObjectStore.class );
-    
+
+    private boolean transientIdentifiableProperties = false;
+
+    /**
+     * Indicates whether the object represented by the implementation does not
+     * have persisted identifiable object properties.
+     */
+    public boolean isTransientIdentifiableProperties()
+    {
+        return transientIdentifiableProperties;
+    }
+
+    /**
+     * Can be overridden programmatically or injected through container.
+     */
+    public void setTransientIdentifiableProperties( boolean transientIdentifiableProperties )
+    {
+        this.transientIdentifiableProperties = transientIdentifiableProperties;
+    }
+
+    // -------------------------------------------------------------------------
+    // IdentifiableObjectStore implementation
+    // -------------------------------------------------------------------------
+
     @Override
     public int save( T object )
     {
@@ -70,6 +93,11 @@
     @Override
     public final T getByUid( String uid )
     {
+        if ( isTransientIdentifiableProperties() )
+        {
+            return null;
+        }
+        
         T object = getObject( Restrictions.eq( "uid", uid ) );
 
         if ( !isReadAllowed( object ) )
@@ -84,6 +112,11 @@
     @Override
     public final T getByUidNoAcl( String uid )
     {
+        if ( isTransientIdentifiableProperties() )
+        {
+            return null;
+        }
+        
         return getObject( Restrictions.eq( "uid", uid ) );
     }
 
@@ -126,6 +159,11 @@
     @Override
     public final T getByCode( String code )
     {
+        if ( isTransientIdentifiableProperties() )
+        {
+            return null;
+        }
+        
         T object = getObject( Restrictions.eq( "code", code ) );
 
         if ( !isReadAllowed( object ) )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2014-04-29 08:09:43 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2014-05-13 09:42:58 +0000
@@ -43,6 +43,7 @@
     <property name="sessionFactory" ref="sessionFactory" />
     <property name="jdbcTemplate" ref="jdbcTemplate" />
     <property name="cacheable" value="true" />
+    <property name="transientIdentifiableProperties" value="true" />
   </bean>
 
   <bean id="org.hisp.dhis.dataelement.DataElementGroupStore" class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">
@@ -116,6 +117,7 @@
     <property name="clazz" value="org.hisp.dhis.period.Period" />
     <property name="sessionFactory" ref="sessionFactory" />
     <property name="cacheable" value="true" />
+    <property name="transientIdentifiableProperties" value="true" />
   </bean>
 
   <bean id="org.hisp.dhis.dataset.DataSetStore" class="org.hisp.dhis.dataset.hibernate.HibernateDataSetStore">

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2014-05-10 11:40:24 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2014-05-13 09:42:58 +0000
@@ -384,6 +384,7 @@
 		<property name="clazz"
 			value="org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder" />
 		<property name="sessionFactory" ref="sessionFactory" />
+		<property name="transientIdentifiableProperties" value="true" />
 	</bean>
 	
 	<!-- EventReport -->