← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22162: TranslationStore.hasTranslations, no need to fetch all obejcts to determine if any exists.

 

------------------------------------------------------------
revno: 22162
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-03-07 18:46:04 +0100
message:
  TranslationStore.hasTranslations, no need to fetch all obejcts to determine if any exists.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationStoreTest.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-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java	2016-03-07 16:43:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java	2016-03-07 17:46:04 +0000
@@ -184,6 +184,7 @@
 
         Criteria criteria = session.createCriteria( Translation.class );
         criteria.add( Restrictions.eq( "className", className ) );
+        criteria.setMaxResults( 1 );
 
         criteria.setCacheable( true );
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationStoreTest.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationStoreTest.java	2016-03-07 17:46:04 +0000
@@ -163,4 +163,19 @@
 
         assertEquals( 5, translationStore.getAll().size() );
     }
+
+    @Test
+    public void testHasTranslations()
+    {
+        translation1a = new Translation( className1, locale1, "name", "cheers", className1 + uid1 );
+        translation1b = new Translation( className1, locale1, "shortName", "goodbye", className1 + uid1 );
+        translation2a = new Translation( className1, locale2, "name", "hello", className1 + uid1 );
+
+        translationStore.save( translation1a );
+        translationStore.save( translation1b );
+        translationStore.save( translation2a );
+        
+        assertTrue( translationStore.hasTranslations( className1 ) );
+        assertFalse( translationStore.hasTranslations( className2 ) );
+    }
 }