dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33006
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16793: HibernateIdentifiableObjectStore. Using query for getting objects by name and short name and then...
------------------------------------------------------------
revno: 16793
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-09-24 12:54:15 +0200
message:
HibernateIdentifiableObjectStore. Using query for getting objects by name and short name and then using first object in list, as these properties might noe be unique and hence cause an exception.
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.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/common/hibernate/HibernateIdentifiableObjectStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java 2014-09-11 06:43:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java 2014-09-24 10:54:15 +0000
@@ -127,12 +127,16 @@
sessionFactory.getCurrentSession().update( object );
}
+ /**
+ * Uses query since name property might not be unique.
+ */
@Override
- @Deprecated
public final T getByName( String name )
{
- T object = getObject( Restrictions.eq( "name", name ) );
-
+ List<T> list = getList( Restrictions.eq( "name", name ) );
+
+ T object = list != null && !list.isEmpty() ? list.get( 0 ) : null;
+
if ( !isReadAllowed( object ) )
{
AuditLogUtil.infoWrapper( log, currentUserService.getCurrentUsername(), object, AuditLogUtil.ACTION_READ_DENIED );
@@ -142,12 +146,16 @@
return object;
}
+ /**
+ * Uses query since name property might not be unique.
+ */
@Override
- @Deprecated
public final T getByShortName( String shortName )
{
- T object = getObject( Restrictions.eq( "shortName", shortName ) );
+ List<T> list = getList( Restrictions.eq( "shortName", shortName ) );
+ T object = list != null && !list.isEmpty() ? list.get( 0 ) : null;
+
if ( !isReadAllowed( object ) )
{
AuditLogUtil.infoWrapper( log, currentUserService.getCurrentUsername(), object, AuditLogUtil.ACTION_READ_DENIED );