← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9305: Made uid column unique for identifiable objects

 

------------------------------------------------------------
revno: 9305
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-12-13 15:23:40 +0100
message:
  Made uid column unique for identifiable objects
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/common/identifiableProperties.hbm


--
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/IdentityPopulator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java	2012-12-13 11:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java	2012-12-13 14:23:40 +0000
@@ -147,5 +147,30 @@
                 statement.close();
             }
         }
+        
+        createUidConstraints();
+    }
+    
+    private void createUidConstraints()
+    {
+        for ( String table : tables )
+        {
+            StatementHolder holder = statementManager.getHolder();
+            
+            try
+            {
+                final String sql = "ALTER TABLE " + table + " ADD CONSTRAINT " + table + "_uid_key UNIQUE(uid)";
+                holder.executeUpdate( sql, true );
+            }
+            catch ( Exception ex )
+            {
+                log.debug( "Could not create uid constraint on table " + table + 
+                    ", might already be created or column contains duplicates", ex );
+            }
+            finally
+            {
+                holder.close();
+            }
+        }
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2012-12-13 10:47:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2012-12-13 14:23:40 +0000
@@ -210,6 +210,7 @@
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public Collection<OrganisationUnit> getBetweenByStatus( boolean status, int first, int max )
     {
         Criteria criteria = getCriteria().add( Restrictions.eq( "active", status ) );
@@ -220,6 +221,7 @@
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public Collection<OrganisationUnit> getBetweenByLastUpdated( Date lastUpdated, int first, int max )
     {
         Criteria criteria = getCriteria().add( Restrictions.ge( "lastUpdated", lastUpdated ) );
@@ -230,6 +232,7 @@
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public Collection<OrganisationUnit> getBetweenByStatusLastUpdated( boolean status, Date lastUpdated, int first, int max )
     {
         Criteria criteria = getCriteria().add( Restrictions.ge( "lastUpdated", lastUpdated ) ).add( Restrictions.eq( "active", status ) );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/common/identifiableProperties.hbm'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/common/identifiableProperties.hbm	2012-12-13 11:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/common/identifiableProperties.hbm	2012-12-13 14:23:40 +0000
@@ -1,5 +1,5 @@
     <property name="name" column="name" not-null="true" unique="true" length="230" />
-    <property name="uid" column="uid" length="11" />
+    <property name="uid" column="uid" unique="true" length="11" />
     <property name="code" column="code" not-null="false" unique="true" length="50" />
     <property name="created" type="timestamp"/>
     <property name="lastUpdated" type="timestamp"/>
\ No newline at end of file