← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4034: Implemented new object class named "Constant". Working in process...

 

------------------------------------------------------------
revno: 4034
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-06-29 15:51:25 +0700
message:
  Implemented new object class named "Constant". Working in process...
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/ConstantService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/constant/
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/constant/hibernate/
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/constant/hibernate/Constant.hbm.xml
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.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
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant'
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java	2011-06-29 08:51:25 +0000
@@ -0,0 +1,125 @@
+package org.hisp.dhis.constant;
+
+/*
+ * Copyright (c) 2004-2011, 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 org.hisp.dhis.common.AbstractIdentifiableObject;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id Constant.java June 29, 2011$
+ */
+public class Constant
+    extends AbstractIdentifiableObject
+{
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
+    
+    /**
+     * Determines if a de-serialized file is compatible with this class.
+     */
+    
+    // -------------------------------------------------------------------------
+    // Variables
+    // -------------------------------------------------------------------------
+
+    private Double value;
+
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
+    public Constant()
+    {
+    }
+
+    public Constant( String name )
+    {
+        this.name = name;
+    }
+
+    public Constant( String name, Double value )
+    {
+        this.name = name;
+        this.value = value;
+    }
+
+    // -------------------------------------------------------------------------
+    // hashCode, equals and toString
+    // -------------------------------------------------------------------------
+
+    @Override
+    public int hashCode()
+    {
+        return name.hashCode();
+    }
+
+    @Override
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+
+        if ( o == null )
+        {
+            return false;
+        }
+
+        if ( !(o instanceof Constant) )
+        {
+            return false;
+        }
+
+        final Constant other = (Constant) o;
+
+        return name.equals( other.getName() );
+    }
+
+    @Override
+    public String toString()
+    {
+        return "[" + name + "]";
+    }
+
+    // -------------------------------------------------------------------------
+    // Getter & Setter
+    // -------------------------------------------------------------------------
+
+    public Double getValue()
+    {
+        return value;
+    }
+
+    public void setValue( Double value )
+    {
+        this.value = value;
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/ConstantService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/ConstantService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/ConstantService.java	2011-06-29 08:51:25 +0000
@@ -0,0 +1,67 @@
+package org.hisp.dhis.constant;
+
+/*
+ * Copyright (c) 2004-2011, 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.Collection;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id ConstantService.java June 29, 2011$
+ */
+public interface ConstantService
+{
+    String ID = ConstantService.class.getName();
+
+    // -------------------------------------------------------------------------
+    // Concept
+    // -------------------------------------------------------------------------
+
+    int saveConstant( Constant constant );
+
+    void deleteConstant( Constant constant );
+
+    void updateConstant( Constant constant );
+
+    Constant getConstant( int constantId );
+
+    Constant getConstantByName( String constantName );
+
+    Collection<Constant> getAllConstants();
+    
+    // -------------------------------------------------------------------------
+    // Constant expanding
+    // -------------------------------------------------------------------------
+    
+    Collection<Constant> getConstantsBetween( int first, int max );
+    
+    Collection<Constant> getConstantsBetweenByName( String name, int first, int max );
+    
+    int getConstantCount();
+    
+    int getConstantCountByName( String name );    
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2011-01-06 17:07:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2011-06-29 08:51:25 +0000
@@ -1,7 +1,7 @@
 package org.hisp.dhis.sqlview;
 
 /*
- * Copyright (c) 2004-2009, University of Oslo
+ * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java	2011-06-29 08:51:25 +0000
@@ -0,0 +1,110 @@
+package org.hisp.dhis.constant;
+
+/*
+ * Copyright (c) 2004-2011, 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.Collection;
+
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id DefaultConstantService.java July 29, 2011$
+ */
+@Transactional
+public class DefaultConstantService
+    implements ConstantService
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private GenericIdentifiableObjectStore<Constant> constantStore;
+
+    public void setConstantStore( GenericIdentifiableObjectStore<Constant> constantStore )
+    {
+        this.constantStore = constantStore;
+    }
+
+    // -------------------------------------------------------------------------
+    // Constant
+    // -------------------------------------------------------------------------
+
+    public int saveConstant( Constant constant )
+    {
+        return constantStore.save( constant );
+    }
+
+    public void updateConstant( Constant constant )
+    {
+        constantStore.update( constant );
+    }
+
+    public void deleteConstant( Constant constant )
+    {
+        constantStore.delete( constant );
+    }
+
+    public Constant getConstant( int constantId )
+    {
+        return constantStore.get( constantId );
+    }
+
+    public Constant getConstantByName( String constantName )
+    {
+        return constantStore.getByName( constantName );
+    }
+
+    public Collection<Constant> getAllConstants()
+    {
+        return constantStore.getAll();
+    }
+
+    // -------------------------------------------------------------------------
+    // Constant expanding
+    // -------------------------------------------------------------------------
+    
+    public int getConstantCount()
+    {
+        return constantStore.getCount();
+    }
+
+    public int getConstantCountByName( String name )
+    {
+        return constantStore.getCountByName( name );
+    }
+
+    public Collection<Constant> getConstantsBetween( int first, int max )
+    {
+        return constantStore.getBetween( first, max );
+    }
+
+    public Collection<Constant> getConstantsBetweenByName( String name, int first, int max )
+    {
+        return constantStore.getBetweenByName( name, first, max );
+    }
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2011-06-23 14:44:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2011-06-29 08:51:25 +0000
@@ -227,7 +227,12 @@
     <property name="sessionFactory" ref="sessionFactory" />
     <property name="clazz" value="org.hisp.dhis.configuration.Configuration" />
   </bean>
-	
+  
+  <bean id="org.hisp.dhis.constant.ConstantStore" class="org.hisp.dhis.hibernate.HibernateGenericStore">
+    <property name="sessionFactory" ref="sessionFactory" />
+	<property name="clazz" value="org.hisp.dhis.constant.Constant" />
+  </bean>
+  
 	<!-- Service definitions -->
 
   <bean id="org.hisp.dhis.dataelement.DataElementOperandService" class="org.hisp.dhis.dataelement.DefaultDataElementOperandService">
@@ -431,7 +436,11 @@
   <bean id="org.hisp.dhis.configuration.ConfigurationService" class="org.hisp.dhis.configuration.DefaultConfigurationService">
     <property name="configurationStore" ref="org.hisp.dhis.configuration.ConfigurationStore" />
   </bean>
-	
+
+  <bean id="org.hisp.dhis.constant.ConstantService" class="org.hisp.dhis.constant.DefaultConstantService">
+    <property name="constantStore" ref="org.hisp.dhis.constant.ConstantStore" />
+  </bean>
+
 	<!-- I18nService -->
 
   <bean id="org.hisp.dhis.i18n.I18nService" class="org.hisp.dhis.i18n.DefaultI18nService">

=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/constant'
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/constant/hibernate'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/constant/hibernate/Constant.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/constant/hibernate/Constant.hbm.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/constant/hibernate/Constant.hbm.xml	2011-06-29 08:51:25 +0000
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";>
+
+<hibernate-mapping>
+  <class name="org.hisp.dhis.constant.Constant" table="constant">
+
+    <cache usage="read-write" />
+  
+    <id name="id" column="constantid">
+      <generator class="native" />
+    </id>
+
+    <property name="name">
+      <column name="name" not-null="true" unique="true" length="230" />
+    </property>
+	
+	<property name="value" />
+
+  </class>
+</hibernate-mapping>

=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml	2011-06-09 20:24:19 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml	2011-06-29 08:51:25 +0000
@@ -122,6 +122,9 @@
   
   <cache name="org.hisp.dhis.dashboard.DashboardContent"
     maxElementsInMemory="1000"/>
+	
+  <cache name="org.hisp.dhis.constant.Constant"
+    maxElementsInMemory="1000"/>
   
   <!-- Hibernate Associations -->