dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40403
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20483: Converting resource tables
------------------------------------------------------------
revno: 20483
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-02 19:00:44 +0200
message:
Converting resource tables
added:
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/CategoryOptionComboResourceTable.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DatePeriodResourceTable.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/PeriodResourceTable.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java
dhis-2/dhis-services/dhis-service-administration/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-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java 2015-10-02 16:28:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java 2015-10-02 17:00:44 +0000
@@ -64,16 +64,6 @@
void batchUpdate( int columns, String tableName, List<Object[]> batchArgs );
/**
- * Creates table.
- */
- void createDatePeriodStructure();
-
- /**
- * Creates table.
- */
- void createPeriodStructure();
-
- /**
* Creates and generates table.
*/
void createAndPopulateDataElementCategoryOptionCombo();
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2015-10-02 16:41:20 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2015-10-02 17:00:44 +0000
@@ -28,23 +28,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.resourcetable.ResourceTableStore.TABLE_NAME_DATE_PERIOD_STRUCTURE;
-import static org.hisp.dhis.resourcetable.ResourceTableStore.TABLE_NAME_PERIOD_STRUCTURE;
-
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.common.IdentifiableObjectUtils;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
-import org.hisp.dhis.commons.collection.UniqueArrayList;
import org.hisp.dhis.dataapproval.DataApprovalLevelService;
import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
import org.hisp.dhis.dataelement.DataElement;
@@ -57,19 +49,17 @@
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.Cal;
-import org.hisp.dhis.period.DailyPeriodType;
-import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
-import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.resourcetable.table.CategoryOptionComboNameResourceTable;
import org.hisp.dhis.resourcetable.table.CategoryOptionGroupSetResourceTable;
import org.hisp.dhis.resourcetable.table.CategoryResourceTable;
import org.hisp.dhis.resourcetable.table.DataElementGroupSetResourceTable;
import org.hisp.dhis.resourcetable.table.DataElementResourceTable;
+import org.hisp.dhis.resourcetable.table.DatePeriodResourceTable;
import org.hisp.dhis.resourcetable.table.IndicatorGroupSetResourceTable;
import org.hisp.dhis.resourcetable.table.OrganisationUnitGroupSetResourceTable;
import org.hisp.dhis.resourcetable.table.OrganisationUnitStructureResourceTable;
+import org.hisp.dhis.resourcetable.table.PeriodResourceTable;
import org.hisp.dhis.sqlview.SqlView;
import org.hisp.dhis.sqlview.SqlViewService;
import org.springframework.transaction.annotation.Transactional;
@@ -218,105 +208,19 @@
statementBuilder.getColumnQuote() ) );
}
- // -------------------------------------------------------------------------
- // PeriodTable
- // -------------------------------------------------------------------------
-
@Override
public void generateDatePeriodTable()
{
- // ---------------------------------------------------------------------
- // Create table
- // ---------------------------------------------------------------------
-
- resourceTableStore.createDatePeriodStructure();
-
- // ---------------------------------------------------------------------
- // Populate table, uniqueness check as some calendars produce duplicates
- // ---------------------------------------------------------------------
-
- List<PeriodType> periodTypes = PeriodType.getAvailablePeriodTypes();
-
- List<Object[]> batchArgs = new ArrayList<>();
-
- Date startDate = new Cal( 1975, 1, 1, true ).time(); //TODO
- Date endDate = new Cal( 2025, 1, 1, true ).time();
-
- List<Period> days = new UniqueArrayList<>( new DailyPeriodType().generatePeriods( startDate, endDate ) );
-
- Calendar calendar = PeriodType.getCalendar();
-
- for ( Period day : days )
- {
- List<Object> values = new ArrayList<>();
-
- values.add( day.getStartDate() );
-
- for ( PeriodType periodType : periodTypes )
- {
- values.add( periodType.createPeriod( day.getStartDate(), calendar ).getIsoDate() );
- }
-
- batchArgs.add( values.toArray() );
- }
-
- resourceTableStore.batchUpdate( PeriodType.PERIOD_TYPES.size() + 1, TABLE_NAME_DATE_PERIOD_STRUCTURE, batchArgs );
-
- log.info( "Period table generated" );
+ resourceTableStore.generateResourceTable( new DatePeriodResourceTable(
+ null, statementBuilder.getColumnQuote() ) );
}
@Override
@Transactional
public void generatePeriodTable()
{
- // ---------------------------------------------------------------------
- // Create table
- // ---------------------------------------------------------------------
-
- Collection<Period> periods = periodService.getAllPeriods();
-
- resourceTableStore.createPeriodStructure();
-
- // ---------------------------------------------------------------------
- // Populate table
- // ---------------------------------------------------------------------
-
- Calendar calendar = PeriodType.getCalendar();
-
- List<Object[]> batchArgs = new ArrayList<>();
-
- for ( Period period : periods )
- {
- if ( period != null && period.isValid() )
- {
- final Date startDate = period.getStartDate();
- final PeriodType rowType = period.getPeriodType();
-
- List<Object> values = new ArrayList<>();
-
- values.add( period.getId() );
- values.add( period.getIsoDate() );
- values.add( period.getDaysInPeriod() );
-
- for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
- {
- if ( rowType.getFrequencyOrder() <= periodType.getFrequencyOrder() )
- {
- values.add( IdentifiableObjectUtils.getLocalPeriodIdentifier( startDate, periodType, calendar ) );
- }
- else
- {
- values.add( null );
- }
- }
-
- batchArgs.add( values.toArray() );
- }
- }
-
- resourceTableStore.batchUpdate( PeriodType.PERIOD_TYPES.size() + 3, TABLE_NAME_PERIOD_STRUCTURE, batchArgs );
-
- log.info( "Date period table generated" );
+ resourceTableStore.generateResourceTable( new PeriodResourceTable(
+ periodService.getAllPeriods(), statementBuilder.getColumnQuote() ) );
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java 2015-10-02 16:28:45 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java 2015-10-02 17:00:44 +0000
@@ -36,9 +36,7 @@
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.commons.util.TextUtils;
import org.hisp.dhis.dbms.DbmsManager;
-import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
-import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.resourcetable.ResourceTable;
import org.hisp.dhis.resourcetable.ResourceTableStore;
import org.springframework.jdbc.BadSqlGrammarException;
@@ -63,13 +61,6 @@
this.jdbcTemplate = jdbcTemplate;
}
- private StatementBuilder statementBuilder;
-
- public void setStatementBuilder( StatementBuilder statementBuilder )
- {
- this.statementBuilder = statementBuilder;
- }
-
private DbmsManager dbmsManager;
public void setDbmsManager( DbmsManager dbmsManager )
@@ -166,70 +157,6 @@
}
// -------------------------------------------------------------------------
- // PeriodTable
- // -------------------------------------------------------------------------
-
- @Override
- public void createDatePeriodStructure()
- {
- try
- {
- jdbcTemplate.execute( "DROP TABLE IF EXISTS " + TABLE_NAME_DATE_PERIOD_STRUCTURE );
- }
- catch ( BadSqlGrammarException ex )
- {
- // Do nothing, table does not exist
- }
-
- String quote = statementBuilder.getColumnQuote();
-
- String sql = "CREATE TABLE " + TABLE_NAME_DATE_PERIOD_STRUCTURE + " (dateperiod DATE NOT NULL PRIMARY KEY";
-
- for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
- {
- sql += ", " + quote + periodType.getName().toLowerCase() + quote + " VARCHAR(15)";
- }
-
- sql += ")";
-
- log.info( "Create date period structure SQL: " + sql );
-
- jdbcTemplate.execute( sql );
- }
-
- @Override
- public void createPeriodStructure()
- {
- try
- {
- jdbcTemplate.execute( "DROP TABLE IF EXISTS " + TABLE_NAME_PERIOD_STRUCTURE );
- }
- catch ( BadSqlGrammarException ex )
- {
- // Do nothing, table does not exist
- }
-
- String quote = statementBuilder.getColumnQuote();
-
- String sql = "CREATE TABLE " + TABLE_NAME_PERIOD_STRUCTURE + " (periodid INTEGER NOT NULL PRIMARY KEY, iso VARCHAR(15) NOT NULL, daysno INTEGER NOT NULL";
-
- for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
- {
- sql += ", " + quote + periodType.getName().toLowerCase() + quote + " VARCHAR(15)";
- }
-
- sql += ")";
-
- log.info( "Create period structure SQL: " + sql );
-
- jdbcTemplate.execute( sql );
-
- final String isoInSql = "create unique index in_periodstructure_iso on _periodstructure(iso)";
-
- jdbcTemplate.execute( isoInSql );
- }
-
- // -------------------------------------------------------------------------
// DataElementCategoryOptionComboTable
// -------------------------------------------------------------------------
=== added file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/CategoryOptionComboResourceTable.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/CategoryOptionComboResourceTable.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/CategoryOptionComboResourceTable.java 2015-10-02 17:00:44 +0000
@@ -0,0 +1,61 @@
+package org.hisp.dhis.resourcetable.table;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.resourcetable.ResourceTable;
+
+public class CategoryOptionComboResourceTable
+ extends ResourceTable<DataElementCategoryOptionCombo>
+{
+
+ @Override
+ public String getTableName()
+ {
+ return "_dataelementcategoryoptioncombo";
+ }
+
+ @Override
+ public String getCreateTempTableStatement()
+ {
+ String sql = "CREATE TABLE " + getTempTableName() + " (" +
+ "dataelementid INTEGER NOT NULL, " +
+ "dataelementuid VARCHAR(11) NOT NULL, " +
+ "categoryoptioncomboid INTEGER NOT NULL, " +
+ "categoryoptioncombouid VARCHAR(11) NOT NULL)";
+
+ return sql;
+ }
+
+ @Override
+ public Optional<String> getPopulateTempTableStatement()
+ {
+ String sql =
+ "insert into " + getTempTableName() +
+ " (dataelementid, dataelementuid, categoryoptioncomboid, categoryoptioncombouid) " +
+ "select de.dataelementid as dataelementid, de.uid as dataelementuid, " +
+ "coc.categoryoptioncomboid as categoryoptioncomboid, coc.uid as categoryoptioncombouid " +
+ "from dataelement de " +
+ "join categorycombos_optioncombos cc on de.categorycomboid = cc.categorycomboid " +
+ "join categoryoptioncombo coc on cc.categoryoptioncomboid = coc.categoryoptioncomboid";
+
+ return Optional.of( sql );
+ }
+
+ @Override
+ public Optional<List<Object[]>> getPopulateTempTableContent()
+ {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<String> getCreateIndexStatement()
+ {
+ String name = "in_dataelementcategoryoptioncombo_" + getRandomSuffix();
+
+ String sql = "create index " + name + " on " + getTempTableName() + "(dataelementuid, categoryoptioncombouid)";
+
+ return Optional.of( sql );
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java 2015-10-02 16:41:20 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java 2015-10-02 17:00:44 +0000
@@ -116,10 +116,10 @@
public Optional<String> getCreateIndexStatement()
{
String sql =
- "create unique index in_dataelementstructure_dataelementuid_" + getRandomSuffix() + " on _dataelementstructure(dataelementuid);" +
- "create index in_dataelementstructure_datasetid_" + getRandomSuffix() + " on _dataelementstructure(datasetid);" +
- "create index in_dataelementstructure_datasetuid_" + getRandomSuffix() + " on _dataelementstructure(datasetuid);" +
- "create index in_dataelementstructure_periodtypeid_" + getRandomSuffix() + " on _dataelementstructure(periodtypeid);";
+ "create unique index in_dataelementstructure_dataelementuid_" + getRandomSuffix() + " on " + getTempTableName() + "(dataelementuid);" +
+ "create index in_dataelementstructure_datasetid_" + getRandomSuffix() + " on " + getTempTableName() + "(datasetid);" +
+ "create index in_dataelementstructure_datasetuid_" + getRandomSuffix() + " on " + getTempTableName() + "(datasetuid);" +
+ "create index in_dataelementstructure_periodtypeid_" + getRandomSuffix() + " on " + getTempTableName() + "(periodtypeid);";
return Optional.of( sql );
}
=== added file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DatePeriodResourceTable.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DatePeriodResourceTable.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DatePeriodResourceTable.java 2015-10-02 17:00:44 +0000
@@ -0,0 +1,118 @@
+package org.hisp.dhis.resourcetable.table;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+
+import org.hisp.dhis.calendar.Calendar;
+import org.hisp.dhis.commons.collection.UniqueArrayList;
+import org.hisp.dhis.period.Cal;
+import org.hisp.dhis.period.DailyPeriodType;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.resourcetable.ResourceTable;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class DatePeriodResourceTable
+ extends ResourceTable<Period>
+{
+ public DatePeriodResourceTable( List<Period> objects, String columnQuote )
+ {
+ super( objects, columnQuote );
+ }
+
+ @Override
+ public String getTableName()
+ {
+ return "_dateperiodstructure";
+ }
+
+ @Override
+ public String getCreateTempTableStatement()
+ {
+ String sql = "create table " + getTempTableName() + " (dateperiod date not null primary key";
+
+ for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
+ {
+ sql += ", " + columnQuote + periodType.getName().toLowerCase() + columnQuote + " varchar(15)";
+ }
+
+ sql += ")";
+
+ return sql;
+ }
+
+ @Override
+ public Optional<String> getPopulateTempTableStatement()
+ {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<List<Object[]>> getPopulateTempTableContent()
+ {
+ List<PeriodType> periodTypes = PeriodType.getAvailablePeriodTypes();
+
+ List<Object[]> batchArgs = new ArrayList<>();
+
+ Date startDate = new Cal( 1975, 1, 1, true ).time(); //TODO
+ Date endDate = new Cal( 2025, 1, 1, true ).time();
+
+ List<Period> days = new UniqueArrayList<>( new DailyPeriodType().generatePeriods( startDate, endDate ) );
+
+ Calendar calendar = PeriodType.getCalendar();
+
+ for ( Period day : days )
+ {
+ List<Object> values = new ArrayList<>();
+
+ values.add( day.getStartDate() );
+
+ for ( PeriodType periodType : periodTypes )
+ {
+ values.add( periodType.createPeriod( day.getStartDate(), calendar ).getIsoDate() );
+ }
+
+ batchArgs.add( values.toArray() );
+ }
+
+ return Optional.of( batchArgs );
+ }
+
+ @Override
+ public Optional<String> getCreateIndexStatement()
+ {
+ return Optional.empty();
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/PeriodResourceTable.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/PeriodResourceTable.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/PeriodResourceTable.java 2015-10-02 17:00:44 +0000
@@ -0,0 +1,130 @@
+package org.hisp.dhis.resourcetable.table;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+
+import org.hisp.dhis.calendar.Calendar;
+import org.hisp.dhis.common.IdentifiableObjectUtils;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.resourcetable.ResourceTable;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class PeriodResourceTable
+ extends ResourceTable<Period>
+{
+ public PeriodResourceTable( List<Period> objects, String columnQuote )
+ {
+ super( objects, columnQuote );
+ }
+
+ @Override
+ public String getTableName()
+ {
+ return "_periodstructure";
+ }
+
+ @Override
+ public String getCreateTempTableStatement()
+ {
+ String sql =
+ "CREATE TABLE " + getTempTableName() +
+ " (periodid INTEGER NOT NULL PRIMARY KEY, iso VARCHAR(15) NOT NULL, daysno INTEGER NOT NULL";
+
+ for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
+ {
+ sql += ", " + columnQuote + periodType.getName().toLowerCase() + columnQuote + " VARCHAR(15)";
+ }
+
+ sql += ")";
+
+ return sql;
+ }
+
+ @Override
+ public Optional<String> getPopulateTempTableStatement()
+ {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<List<Object[]>> getPopulateTempTableContent()
+ {
+ Calendar calendar = PeriodType.getCalendar();
+
+ List<Object[]> batchArgs = new ArrayList<>();
+
+ for ( Period period : objects )
+ {
+ if ( period != null && period.isValid() )
+ {
+ final Date startDate = period.getStartDate();
+ final PeriodType rowType = period.getPeriodType();
+
+ List<Object> values = new ArrayList<>();
+
+ values.add( period.getId() );
+ values.add( period.getIsoDate() );
+ values.add( period.getDaysInPeriod() );
+
+ for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
+ {
+ if ( rowType.getFrequencyOrder() <= periodType.getFrequencyOrder() )
+ {
+ values.add( IdentifiableObjectUtils.getLocalPeriodIdentifier( startDate, periodType, calendar ) );
+ }
+ else
+ {
+ values.add( null );
+ }
+ }
+
+ batchArgs.add( values.toArray() );
+ }
+ }
+
+ return Optional.of( batchArgs );
+ }
+
+ @Override
+ public Optional<String> getCreateIndexStatement()
+ {
+ String name = "in_periodstructure_iso_" + getRandomSuffix();
+
+ String sql = "create unique index " + name + " on " + getTempTableName() + "(iso)";
+
+ return Optional.of( sql );
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml 2015-10-02 14:27:58 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml 2015-10-02 17:00:44 +0000
@@ -6,7 +6,6 @@
<bean id="org.hisp.dhis.resourcetable.ResourceTableStore" class="org.hisp.dhis.resourcetable.jdbc.JdbcResourceTableStore">
<property name="jdbcTemplate" ref="jdbcTemplate" />
- <property name="statementBuilder" ref="statementBuilder" />
<property name="dbmsManager" ref="dbmsManager" />
</bean>