dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #34103
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17513: Added method to id manager for getting last updated object per class
------------------------------------------------------------
revno: 17513
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-11-17 20:21:36 +0100
message:
Added method to id manager for getting last updated object per class
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java
dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.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/common/GenericIdentifiableObjectStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java 2014-09-11 06:39:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java 2014-11-17 19:21:36 +0000
@@ -246,6 +246,13 @@
* @return All objects equal or newer than given date.
*/
List<T> getAllGeLastUpdatedOrderedName( Date lastUpdated );
+
+ /**
+ * Returns the date of the last updated object.
+ *
+ * @return a Date / time stamp.
+ */
+ Date getLastUpdated();
/**
* Returns the number of objects that are equal to or newer than given last updated date.
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2014-10-23 05:40:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2014-11-17 19:21:36 +0000
@@ -92,6 +92,8 @@
<T extends IdentifiableObject> Collection<T> getByLastUpdatedSorted( Class<T> clazz, Date lastUpdated );
<T extends IdentifiableObject> Collection<T> getByCreatedSorted( Class<T> clazz, Date created );
+
+ <T extends IdentifiableObject> Date getLastUpdated( Class<T> clazz );
void delete( IdentifiableObject object );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2014-10-23 05:40:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2014-11-17 19:21:36 +0000
@@ -532,6 +532,19 @@
}
@Override
+ public <T extends IdentifiableObject> Date getLastUpdated( Class<T> clazz )
+ {
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
+
+ if ( store == null )
+ {
+ return null;
+ }
+
+ return store.getLastUpdated();
+ }
+
+ @Override
public <T extends IdentifiableObject> Set<Integer> convertToId( Class<T> clazz, Collection<String> uids )
{
GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
=== 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-09-24 10:54:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java 2014-11-17 19:21:36 +0000
@@ -28,6 +28,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
@@ -41,11 +46,6 @@
import org.hisp.dhis.hibernate.HibernateGenericStore;
import org.hisp.dhis.hibernate.exception.ReadAccessDeniedException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
/**
* @author bobj
*/
@@ -394,6 +394,15 @@
}
@Override
+ public Date getLastUpdated()
+ {
+ return (Date) getClazzCriteria().setProjection( Projections.property( "lastUpdated" ) )
+ .addOrder( Order.desc( "lastUpdated" ) )
+ .setMaxResults( 1 )
+ .setCacheable( true ).uniqueResult();
+ }
+
+ @Override
@SuppressWarnings("unchecked")
public List<T> getByDataDimension( boolean dataDimension )
{
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2014-10-17 17:55:45 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2014-11-17 19:21:36 +0000
@@ -227,7 +227,7 @@
{
return sessionFactory.getCurrentSession().createCriteria( getClazz() );
}
-
+
/**
* Creates a Criteria for the implementation Class type restricted by the
* given Criterions.