← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22331: Included spatial support in db in DatabaseInfo provider.

 

------------------------------------------------------------
revno: 22331
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-03-15 16:23:35 +0100
message:
  Included spatial support in db in DatabaseInfo provider.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/SystemInfo.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/database/DatabaseInfo.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/database/HibernateDatabaseInfoProvider.java
  dhis-2/dhis-support/dhis-support-system/src/main/resources/META-INF/dhis/beans.xml


--
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/system/SystemInfo.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/SystemInfo.java	2016-03-15 15:09:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/SystemInfo.java	2016-03-15 15:23:35 +0000
@@ -103,8 +103,6 @@
     private String memoryInfo;
 
     private Integer cpuCores;
-
-    private boolean spatialSupport;
     
     private String systemId;
 
@@ -133,7 +131,6 @@
         this.databaseInfo = null;
         this.memoryInfo = null;
         this.cpuCores = null;
-        this.spatialSupport = false;
         this.systemId = null;
     }
     
@@ -431,18 +428,6 @@
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public boolean isSpatialSupport()
-    {
-        return spatialSupport;
-    }
-
-    public void setSpatialSupport( boolean spatialSupport )
-    {
-        this.spatialSupport = spatialSupport;
-    }
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getSystemId()
     {
         return systemId;

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/database/DatabaseInfo.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/database/DatabaseInfo.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/database/DatabaseInfo.java	2016-03-15 15:23:35 +0000
@@ -53,6 +53,8 @@
     
     private String url;
     
+    private boolean spatialSupport;
+    
     // -------------------------------------------------------------------------
     // Constructor
     // -------------------------------------------------------------------------
@@ -141,6 +143,18 @@
         this.url = url;
     }
 
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public boolean isSpatialSupport()
+    {
+        return spatialSupport;
+    }
+
+    public void setSpatialSupport( boolean spatialSupport )
+    {
+        this.spatialSupport = spatialSupport;
+    }
+
     // -------------------------------------------------------------------------
     // toString
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/database/HibernateDatabaseInfoProvider.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/database/HibernateDatabaseInfoProvider.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/database/HibernateDatabaseInfoProvider.java	2016-03-15 15:23:35 +0000
@@ -30,6 +30,7 @@
 
 import org.hibernate.cfg.Configuration;
 import org.hisp.dhis.hibernate.HibernateConfigurationProvider;
+import org.springframework.jdbc.core.JdbcTemplate;
 
 /**
  * @author Lars Helge Overland
@@ -64,10 +65,19 @@
         this.hibernateConfigurationProvider = hibernateConfigurationProvider;
     }
 
+    private JdbcTemplate jdbcTemplate;
+    
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+    {
+        this.jdbcTemplate = jdbcTemplate;
+    }
+    
     public void init()
     {
         Configuration config = hibernateConfigurationProvider.getConfiguration();
         
+        boolean spatialSupport = isSpatialSupport();
+        
         String dialect = config.getProperty( KEY_DIALECT );
         String driverClass = config.getProperty( KEY_DRIVER_CLASS );
         String url = config.getProperty( KEY_URL );
@@ -95,6 +105,7 @@
         info.setDialect( dialect );
         info.setDriverClass( driverClass );
         info.setUrl( url );
+        info.setSpatialSupport( spatialSupport );
     }    
     
     // -------------------------------------------------------------------------
@@ -112,4 +123,21 @@
     {
         return info.getUrl() != null && info.getUrl().contains( ":mem:" );
     }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private boolean isSpatialSupport()
+    {
+        try
+        {
+            String version = jdbcTemplate.queryForObject( "select postgis_full_version()", String.class );
+            return version != null;
+        }
+        catch ( Exception ex )
+        {
+            return false;
+        }
+    }
 }

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-support/dhis-support-system/src/main/resources/META-INF/dhis/beans.xml	2015-10-05 17:01:40 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/resources/META-INF/dhis/beans.xml	2016-03-15 15:23:35 +0000
@@ -12,6 +12,7 @@
 
   <bean id="databaseInfoProvider" class="org.hisp.dhis.system.database.HibernateDatabaseInfoProvider" init-method="init">
     <property name="hibernateConfigurationProvider" ref="hibernateConfigurationProvider" />
+    <property name="jdbcTemplate" ref="jdbcTemplate" />
   </bean>
 
   <bean id="taskScheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">