← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4288: Fixed bug unit test failed in data set locking (hibernate working unstable with method called "cr...

 

------------------------------------------------------------
revno: 4288
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-08-13 02:30:59 +0700
message:
  Fixed bug unit test failed in data set locking (hibernate working unstable with method called "createAlias").
modified:
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/datalock/hibernate/HibernateDataSetLockStore.java
  dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/datalock/DataSetLockServiceTest.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-services/dhis-service-administration/src/main/java/org/hisp/dhis/datalock/hibernate/HibernateDataSetLockStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/datalock/hibernate/HibernateDataSetLockStore.java	2011-04-22 21:04:14 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/datalock/hibernate/HibernateDataSetLockStore.java	2011-08-12 19:30:59 +0000
@@ -29,6 +29,7 @@
 import java.util.Collection;
 
 import org.hibernate.Criteria;
+import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.criterion.Restrictions;
@@ -124,25 +125,25 @@
         return (DataSetLock) session.get( DataSetLock.class, id );
     }
 
-    @SuppressWarnings("unchecked")
-        public Collection<DataSetLock> getDataSetLockByDataSet( DataSet dataSet )
-    {           
+    @SuppressWarnings( "unchecked" )
+    public Collection<DataSetLock> getDataSetLockByDataSet( DataSet dataSet )
+    {
         Session session = sessionFactory.getCurrentSession();
-        
+
         Criteria criteria = session.createCriteria( DataSetLock.class );
         criteria.add( Restrictions.eq( "dataSet", dataSet ) );
-        
+
         return criteria.list();
     }
 
-    @SuppressWarnings("unchecked")
-        public Collection<DataSetLock> getDataSetLockByPeriod( Period period )
+    @SuppressWarnings( "unchecked" )
+    public Collection<DataSetLock> getDataSetLockByPeriod( Period period )
     {
         Session session = sessionFactory.getCurrentSession();
-        
+
         Period storedPeriod = reloadPeriod( period );
 
-        Criteria criteria = session.createCriteria( DataSetLock.class );        
+        Criteria criteria = session.createCriteria( DataSetLock.class );
         criteria.add( Restrictions.eq( "period", storedPeriod ) );
 
         return criteria.list();
@@ -163,28 +164,29 @@
 
     public DataSetLock getDataSetLockByDataSetPeriodAndSource( DataSet dataSet, Period period, OrganisationUnit source )
     {
-        Session session = sessionFactory.getCurrentSession();
-
         Period storedPeriod = reloadPeriod( period );
 
-        Criteria criteria = session.createCriteria( DataSetLock.class );
-        criteria.add( Restrictions.eq( "dataSet", dataSet ) );
-        criteria.add( Restrictions.eq( "period", storedPeriod ) );
-        criteria.createAlias( "sources", "s" );
-        criteria.add( Restrictions.eq( "s.id", source.getId() ) );
-
-        return (DataSetLock) criteria.uniqueResult();
+        String hql = "from DataSetLock d ";
+        hql += "where dataSet = :dataSet ";
+        hql += "and period = :period ";
+        hql += "and :source in elements(d.sources)";
+
+        Query query = sessionFactory.getCurrentSession().createQuery( hql );
+        query.setEntity( "dataSet", dataSet );
+        query.setEntity( "period", storedPeriod );
+        query.setEntity( "source", source );
+
+        return (DataSetLock) query.uniqueResult();
     }
 
     @SuppressWarnings( "unchecked" )
     public Collection<DataSetLock> getDataSetLocksBySource( OrganisationUnit source )
     {
-        Session session = sessionFactory.getCurrentSession();
-
-        Criteria criteria = session.createCriteria( DataSetLock.class );
-        criteria.createAlias( "sources", "s" );
-        criteria.add( Restrictions.eq( "s.id", source.getId() ) );
-
-        return criteria.list();
+        String hql = "from DataSetLock d where :source in elements(d.sources)";
+
+        Query query = sessionFactory.getCurrentSession().createQuery( hql );
+        query.setEntity( "source", source );
+
+        return query.list();
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/datalock/DataSetLockServiceTest.java'
--- dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/datalock/DataSetLockServiceTest.java	2011-08-11 18:39:10 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/datalock/DataSetLockServiceTest.java	2011-08-12 19:30:59 +0000
@@ -47,7 +47,6 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -106,7 +105,7 @@
         throws Exception
     {
         dataSetService = (DataSetService) getBean( DataSetService.ID );
-        
+
         dataSetLockService = (DataSetLockService) getBean( DataSetLockService.ID );
 
         periodService = (PeriodService) getBean( PeriodService.ID );
@@ -196,7 +195,7 @@
             units.add( s );
         }
     }
-    
+
     private void assertEq( DataSetLock dataSetLock, DataSet dataSet, Period period, Set<OrganisationUnit> sources )
     {
         assertEquals( dataSet, dataSetLock.getDataSet() );
@@ -420,7 +419,6 @@
     }
 
     @Test
-    @Ignore
     public void testGetDataSetLockByDataSetPeriodAndSource()
     {
         Set<OrganisationUnit> lockSources = new HashSet<OrganisationUnit>();
@@ -442,7 +440,6 @@
     }
 
     @Test
-    @Ignore
     public void testGetDataSetLocksBySource()
     {
         Set<OrganisationUnit> lockSources = new HashSet<OrganisationUnit>();