From: <and...@us...> - 2016-12-25 18:28:14
|
Revision: 1440 http://sourceforge.net/p/ggc/code/1440 Author: andyrozman Date: 2016-12-25 18:28:11 +0000 (Sun, 25 Dec 2016) Log Message: ----------- ggc-nutri 1.4.2 - GGCTreeRootStatic changed - datalayer - GGCDbCache, CGCDbNutri - backup object - print food menu Modified Paths: -------------- trunk/ggc-nutri/build/build.xml trunk/ggc-nutri/docs/Changelog trunk/ggc-nutri/pom.xml trunk/ggc-nutri/src/ggc/nutri/data/GGCTreeRootStatic.java trunk/ggc-nutri/src/ggc/nutri/db/GGCDbCache.java trunk/ggc-nutri/src/ggc/nutri/db/GGCDbNutri.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DailyFoodEntries.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DailyFoodEntry.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/FoodDescription.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/FoodGroup.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/GlycemicNutrients.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/HomeWeightSpecial.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/Meal.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/MealGroup.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/MealNutrition.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/MealPart.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/MealParts.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/NutritionDefinition.java trunk/ggc-nutri/src/ggc/nutri/db/datalayer/NutritionHomeWeightType.java trunk/ggc-nutri/src/ggc/nutri/plugin/BackupRestoreNutriHandler.java trunk/ggc-nutri/src/ggc/nutri/print/PrintFoodMenuAbstract.java trunk/ggc-nutri/src/ggc/nutri/print/PrintFoodMenuBase.java trunk/ggc-nutri/src/ggc/nutri/print/PrintFoodMenuExt1.java trunk/ggc-nutri/src/ggc/nutri/print/PrintFoodMenuExt2.java Added Paths: ----------- trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DAOObject.java Modified: trunk/ggc-nutri/build/build.xml =================================================================== --- trunk/ggc-nutri/build/build.xml 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/build/build.xml 2016-12-25 18:28:11 UTC (rev 1440) @@ -6,11 +6,11 @@ <!-- Environment properties read from a file ...--> <property file="../../build/AtechTools.properties"/> - <property file="../../ggc-core/build/GGCBuild.properties"/> + <property file="../../ggc-core-app/ggc-core/build/GGCBuild.properties"/> <!-- <property file="./GGCPlugInBaseBuild.properties"/> <property file="../../ggc-plugin_base/build/GGCPlugInBaseBuild.properties"/> --> - <property file="../../ggc-plugin_base/build/GGCPlugInBaseVersion.properties"/> - <property file="../../ggc-core/build/GGC_Core_Version.properties"/> + <property file="../../ggc-plugins/ggc-plugins-base/build/GGCPlugInBaseVersion.properties"/> + <property file="../../ggc-core-app/ggc-core/build/GGC_Core_Version.properties"/> <property file="./GGCNutriToolVersion.properties"/> <!-- These should *not* be modified on the command line! --> Modified: trunk/ggc-nutri/docs/Changelog =================================================================== --- trunk/ggc-nutri/docs/Changelog 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/docs/Changelog 2016-12-25 18:28:11 UTC (rev 1440) @@ -6,6 +6,14 @@ -------------------------------------------------------------------------------------------------- +1.4.2 [25.12.2016] [Andy] +- GGCTreeRootStatic changed +- datalayer +- GGCDbCache, CGCDbNutri +- backup object +- print food menu + + 1.4.1 [18.5.2016] - db objects refactoring - refactorings Modified: trunk/ggc-nutri/pom.xml =================================================================== --- trunk/ggc-nutri/pom.xml 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/pom.xml 2016-12-25 18:28:11 UTC (rev 1440) @@ -5,7 +5,7 @@ <groupId>net.sf.ggc</groupId> <artifactId>ggc-parent</artifactId> <version>1.0-SNAPSHOT</version> - <relativePath>../ggc-master-pom/pom.xml</relativePath> + <relativePath>../ggc-removed/ggc-master-pom/pom.xml</relativePath> </parent> <name>GGC Nutrition Tool Project</name> Modified: trunk/ggc-nutri/src/ggc/nutri/data/GGCTreeRootStatic.java =================================================================== --- trunk/ggc-nutri/src/ggc/nutri/data/GGCTreeRootStatic.java 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/src/ggc/nutri/data/GGCTreeRootStatic.java 2016-12-25 18:28:11 UTC (rev 1440) @@ -27,9 +27,7 @@ package ggc.nutri.data; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; +import java.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -71,49 +69,49 @@ private static final Logger LOG = LoggerFactory.getLogger(GGCTreeRootStatic.class); - private ArrayList<FoodGroup> import1_grp = null; - private ArrayList<FoodDescription> import1_foods = null; + private List<FoodGroup> import1_grp = null; + private List<FoodDescription> import1_foods = null; - private ArrayList<MealGroup> import2_grp = null; - private ArrayList<Meal> import2_foods = null; + private List<MealGroup> import2_grp = null; + private List<Meal> import2_foods = null; /** * Food Groups */ - public ArrayList<FoodGroup> m_groups = null; + public List<FoodGroup> m_groups = null; /** * Food Groups as Hashtable */ - public Hashtable<String, FoodGroup> m_groups_ht = null; + public Map<String, FoodGroup> m_groups_ht = null; /** * Food Groups Tree */ - public ArrayList<FoodGroup> m_groups_tree = null; + public List<FoodGroup> m_groups_tree = null; /** * Foods Hashtable */ - public Hashtable<String, FoodDescription> m_foods_ht = null; + public Map<String, FoodDescription> m_foods_ht = null; /** * Meal Groups */ - public ArrayList<MealGroup> m_meal_groups = null; + public List<MealGroup> m_meal_groups = null; /** * Meal Groups Hashtable */ - public Hashtable<String, MealGroup> m_meal_groups_ht = null; + public Map<String, MealGroup> m_meal_groups_ht = null; /** * Meal Groups Tree */ - public ArrayList<MealGroup> m_meal_groups_tree = null; + public List<MealGroup> m_meal_groups_tree = null; /** * Meals Hashtable */ - public Hashtable<String, Meal> m_meals_ht = null; + public Map<String, Meal> m_meals_ht = null; // private boolean debug = true; private boolean dev = false; Modified: trunk/ggc-nutri/src/ggc/nutri/db/GGCDbCache.java =================================================================== --- trunk/ggc-nutri/src/ggc/nutri/db/GGCDbCache.java 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/src/ggc/nutri/db/GGCDbCache.java 2016-12-25 18:28:11 UTC (rev 1440) @@ -27,8 +27,10 @@ package ggc.nutri.db; -import java.util.ArrayList; +import java.util.HashMap; import java.util.Hashtable; +import java.util.List; +import java.util.Map; import com.atech.graphics.dialogs.selector.SelectableInterface; @@ -83,47 +85,47 @@ /** * Tree Roots */ - public Hashtable<String, GGCTreeRoot> tree_roots = null; + public Map<String, GGCTreeRoot> tree_roots = null; /** * Data: Nutrition Definitions (Hashtable) */ - public Hashtable<String, NutritionDefinition> nutrition_defs = null; + public Map<String, NutritionDefinition> nutrition_defs = null; /** * Data: Home Weight Definitions (Hashtable) */ - public Hashtable<String, NutritionHomeWeightType> homeweight_defs = null; + public Map<String, NutritionHomeWeightType> homeweight_defs = null; /** * Data: Nutrition Definitions (ArrayList) */ - public ArrayList<SelectableInterface> nutrition_defs_list = null; + public List<SelectableInterface> nutrition_defs_list = null; /** * Data: Home Weight Definitions (ArrayList) */ - public ArrayList<SelectableInterface> homeweight_defs_list = null; + public List<SelectableInterface> homeweight_defs_list = null; /** * Food Groups as Hashtable */ - public Hashtable<String, Hashtable<String, FoodGroup>> food_groups = null; + public Map<String, Map<String, FoodGroup>> food_groups = null; /** * Foods as Hashtable */ - public Hashtable<String, Hashtable<String, FoodDescription>> foods = null; + public Map<String, Map<String, FoodDescription>> foods = null; /** * Food Groups as Hashtable */ - public Hashtable<String, Hashtable<String, MealGroup>> meal_groups = null; + public Map<String, Map<String, MealGroup>> meal_groups = null; /** * Foods as Hashtable */ - public Hashtable<String, Hashtable<String, Meal>> meals = null; + public Map<String, Map<String, Meal>> meals = null; /** @@ -135,18 +137,18 @@ { this.m_db = db; - food_groups = new Hashtable<String, Hashtable<String, FoodGroup>>(); + food_groups = new HashMap<String, Map<String, FoodGroup>>(); food_groups.put("1", new Hashtable<String, FoodGroup>()); food_groups.put("2", new Hashtable<String, FoodGroup>()); - foods = new Hashtable<String, Hashtable<String, FoodDescription>>(); + foods = new Hashtable<String, Map<String, FoodDescription>>(); foods.put("1", new Hashtable<String, FoodDescription>()); foods.put("2", new Hashtable<String, FoodDescription>()); - meal_groups = new Hashtable<String, Hashtable<String, MealGroup>>(); + meal_groups = new Hashtable<String, Map<String, MealGroup>>(); meal_groups.put("3", new Hashtable<String, MealGroup>()); - meals = new Hashtable<String, Hashtable<String, Meal>>(); + meals = new Hashtable<String, Map<String, Meal>>(); meals.put("3", new Hashtable<String, Meal>()); this.tree_roots = new Hashtable<String, GGCTreeRoot>(); @@ -459,7 +461,7 @@ * @param parent_id id of parent * @return */ - public ArrayList<FoodGroup> getChildrenFoodGroup(int type, long parent_id) + public List<FoodGroup> getChildrenFoodGroup(int type, long parent_id) { boolean not_loaded = false; @@ -483,7 +485,7 @@ if (not_loaded) { - ArrayList<FoodGroup> lst = m_db.getFoodGroups(type, parent_id); + List<FoodGroup> lst = m_db.getFoodGroups(type, parent_id); for (int i = 0; i < lst.size(); i++) { @@ -509,7 +511,7 @@ * @param parent_id * @return */ - public ArrayList<FoodDescription> getChildrenFoods(int type, long parent_id) + public List<FoodDescription> getChildrenFoods(int type, long parent_id) { boolean not_loaded = false; @@ -533,7 +535,7 @@ if (not_loaded) { - ArrayList<FoodDescription> lst = m_db.getFoodsByParent(type, parent_id); + List<FoodDescription> lst = m_db.getFoodsByParent(type, parent_id); for (int i = 0; i < lst.size(); i++) { @@ -560,7 +562,7 @@ * @param parent_id * @return */ - public ArrayList<MealGroup> getChildrenMealGroup(int type, long parent_id) + public List<MealGroup> getChildrenMealGroup(int type, long parent_id) { boolean not_loaded = false; @@ -583,7 +585,7 @@ if (not_loaded) { - ArrayList<MealGroup> lst = m_db.getMealGroups(parent_id); + List<MealGroup> lst = m_db.getMealGroups(parent_id); for (int i = 0; i < lst.size(); i++) { @@ -608,7 +610,7 @@ * @param parent_id * @return */ - public ArrayList<Meal> getChildrenMeals(int type, long parent_id) + public List<Meal> getChildrenMeals(int type, long parent_id) { boolean not_loaded = false; @@ -631,7 +633,7 @@ if (not_loaded) { - ArrayList<Meal> lst = m_db.getMealsByParent(parent_id); + List<Meal> lst = m_db.getMealsByParent(parent_id); for (int i = 0; i < lst.size(); i++) { Modified: trunk/ggc-nutri/src/ggc/nutri/db/GGCDbNutri.java =================================================================== --- trunk/ggc-nutri/src/ggc/nutri/db/GGCDbNutri.java 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/src/ggc/nutri/db/GGCDbNutri.java 2016-12-25 18:28:11 UTC (rev 1440) @@ -3,22 +3,22 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.Iterator; +import java.util.List; +import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.Session; -import org.hibernate.Transaction; +import org.hibernate.criterion.Order; +import org.hibernate.criterion.Restrictions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.atech.db.hibernate.HibernateConfiguration; import com.atech.db.hibernate.HibernateDb; +import com.atech.db.hibernate.HibernateObject; import com.atech.graphics.dialogs.selector.SelectableInterface; -import ggc.core.data.DailyValues; -import ggc.core.data.DailyValuesRow; -import ggc.core.data.DayValuesData; import ggc.core.db.GGCDb; -import ggc.core.db.hibernate.DayValueH; import ggc.core.db.hibernate.food.*; import ggc.nutri.data.GGCTreeRoot; import ggc.nutri.data.GGCTreeRootDyn; @@ -43,53 +43,20 @@ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA * - * Filename: GGCDb - * Description: Class for working with database (Hibernate) + * Filename: GGCDbNutri + * Description: Class for working with database (Hibernate) in Nutrition Plugin * * Author: andyrozman {an...@at...} */ -public class GGCDbNutri extends HibernateDb // extends GGCDb +public class GGCDbNutri extends HibernateDb { - // public static final int DB_CONFIG_LOADED = 1; - // public static final int DB_INITIALIZED = 2; - // public static final int DB_STARTED = 3; - - private boolean debug = true; - // x private boolean db_debug = false; - private static final Logger LOG = LoggerFactory.getLogger(GGCDbNutri.class); - // private Session m_session = null; - // private Session m_session_2 = null; - // private SessionFactory sessions = null; - // private int m_errorCode = 0; - // private String m_errorDesc = ""; - // private String m_addId = ""; - // private DataAccessNutri dataAccess; - - private int m_loadStatus = 0; - - // GLOBAL DATA - - /* - * public ArrayList<MeterCompanyH> meter_companies = null; public - * Hashtable<String,ArrayList<MeterH>> meters_by_cmp = null; public - * Hashtable<String,MeterH> meters_full = null; - */ - - // --- - // --- DB Settings - // --- - /* - * protected int db_num = 0; protected String db_hib_dialect = null; - * protected String db_driver_class = null; protected String db_conn_name = - * null; protected String db_conn_url = null; protected String - * db_conn_username = null; protected String db_conn_password = null; - */ - HibernateConfiguration hib_config; + private boolean debug = true; + GGCDbCache cache_db = null; /** @@ -108,17 +75,7 @@ } - // ************************************************************* - // **** SETTINGS **** - // ************************************************************* - // ************************************************************* - // **** SETTINGS **** - // ************************************************************* - - GGCDbCache cache_db = null; - - /** * Get Db Cache * @@ -129,26 +86,11 @@ return cache_db; } - // ************************************************************* // **** DATABASE INIT METHODS **** // ************************************************************* - /** - * Load Nutrition Database - */ - public void loadNutritionDatabase() - { - /* - * this.loadNutritionDbBase(); - * this.loadNutritionDb1(); - * this.loadNutritionDb2(); - * this.loadMealsDb(); - */ - } - - /** * Load Nutrition Db Base */ @@ -205,7 +147,7 @@ * @param parent_id * @return */ - public ArrayList<FoodGroup> getFoodGroups(int type, long parent_id) + public List<FoodGroup> getFoodGroups(int type, long parent_id) { if (type == GGCTreeRoot.TREE_USER_NUTRITION) return this.getUserFoodGroups(parent_id); @@ -240,111 +182,111 @@ * * @return */ - public ArrayList<FoodGroup> getUSDAFoodGroups() + public List<FoodGroup> getUSDAFoodGroups() { + List<FoodGroupH> fgList = getHibernateObjectListByParameter(null, null, Order.asc("name"), FoodGroupH.class, 2); - logInfo("getUSDAFoodGroups()"); + return getDAOGroupList(fgList, FoodGroup.class); + } - ArrayList<FoodGroup> list = new ArrayList<FoodGroup>(); + public <T extends HibernateObject> T getHibernateObjectByParameter(String parameterName, Long parameterValue, + Order orderBy, Class<T> clazz, Integer sessionId) + { + LOG.info("get " + clazz.getSimpleName() + " (id=" + parameterValue + ")"); + try { + Criteria criteria = this.getSession(sessionId).createCriteria(clazz); + criteria.add(Restrictions.eq(parameterName, parameterValue)); - Query q = getSession(2) - .createQuery("select pst from ggc.core.db.hibernate.food.FoodGroupH as pst order by pst.name"); + List list = criteria.list(); - Iterator<?> it = q.iterate(); - - while (it.hasNext()) + if (list.size() > 0) { - FoodGroupH eh = (FoodGroupH) it.next(); - list.add(new FoodGroup(eh)); + return (T) list.get(0); } } catch (Exception ex) { - logException("getUSDAFoodGroups()", ex); + LOG.info( + "get " + clazz.getSimpleName() + " (id=" + parameterValue + ") problem. Exception: " + ex.getMessage(), + ex); } - return list; - + return (T) null; } - /** - * Get USDA Food Group - * - * @param id - * @return - */ - public FoodGroup getUSDAFoodGroup(long id) + public <T extends HibernateObject> List<T> getHibernateObjectListByParameter(String parameterName, + Long parameterValue, Order orderBy, Class<T> clazz, Integer sessionId) { + LOG.info("get %s %s", clazz.getSimpleName(), getParameterDebugString(parameterName, parameterValue)); - logInfo("getUSDAFoodGroup(id=)" + id + ")"); + List<T> outList = new ArrayList<T>(); - // ArrayList<FoodGroup> list = new ArrayList<FoodGroup>(); - try { + Criteria criteria = this.getSession(sessionId).createCriteria(clazz); - Query q = getSession(2) - .createQuery("select pst from ggc.core.db.hibernate.food.FoodGroupH as pst where pst.id=" + id); + if (parameterName != null) + criteria.add(Restrictions.eq(parameterName, parameterValue)); - Iterator<?> it = q.iterate(); + if (orderBy != null) + { + criteria.addOrder(orderBy); + } - while (it.hasNext()) + List list = criteria.list(); + + for (Object obj : list.toArray()) { - FoodGroupH eh = (FoodGroupH) it.next(); - return new FoodGroup(eh); + outList.add((T) obj); } } catch (Exception ex) { - logException("getUSDAFoodGroups()", ex); + LOG.error("get %s (%s=%s) problem. Exception: ", clazz.getSimpleName(), + getParameterDebugString(parameterName, parameterValue), ex.getMessage(), ex); } - return null; + return outList; + } + + private String getParameterDebugString(String parameterName, Long parameterValue) + { + return parameterName != null ? String.format(" (%s=%s)", parameterName, parameterValue) : ""; } /** - * Get Food Groups - User + * Get USDA Food Group * * @param id * @return */ - public FoodGroup getUserFoodGroup(long id) + public FoodGroup getUSDAFoodGroup(long id) { - logInfo("getUserFoodGroup(id=" + id + ")"); + FoodGroupH fg = getHibernateObjectByParameter("id", id, Order.asc("name"), FoodGroupH.class, 2); - // ArrayList<FoodGroup> list = new ArrayList<FoodGroup>(); + return fg != null ? new FoodGroup(fg) : null; + } - try - { - Query q = getSession(2) - .createQuery("select pst from ggc.core.db.hibernate.food.FoodUserGroupH as pst order by pst.name"); + /** + * Get Food Groups - User + * + * @param id + * @return + */ + public FoodGroup getUserFoodGroup(long id) + { + FoodUserGroupH fg = getHibernateObjectByParameter("id", id, Order.asc("name"), FoodUserGroupH.class, 2); - Iterator<?> it = q.iterate(); - - while (it.hasNext()) - { - FoodUserGroupH eh = (FoodUserGroupH) it.next(); - return new FoodGroup(eh); - } - } - catch (Exception ex) - { - logException("getUserFoodGroup()", ex); - - // LOG.error("Exception on getloadConfigData: " + ex.getMessage(), - // ex); - } - - return null; + return fg != null ? new FoodGroup(fg) : null; } @@ -353,79 +295,57 @@ * * @return */ - public ArrayList<FoodGroup> getUserFoodGroups() + public List<FoodGroup> getUserFoodGroups() { - logInfo("getUserFoodGroups()"); + List<FoodUserGroupH> fgList = getHibernateObjectListByParameter(null, null, Order.asc("name"), + FoodUserGroupH.class, 2); - ArrayList<FoodGroup> list = new ArrayList<FoodGroup>(); + return getDAOGroupList(fgList, FoodGroup.class); + } - try - { - Query q = getSession(2) - .createQuery("select pst from ggc.core.db.hibernate.food.FoodUserGroupH as pst order by pst.name"); + private <T extends DAOObject> List<T> getDAOGroupList(List<? extends HibernateObject> fgList, Class<T> clazz) + { + List<T> outList = new ArrayList<T>(); - Iterator<?> it = q.iterate(); - - while (it.hasNext()) + for (HibernateObject hibernateObject : fgList) + { + if (hibernateObject instanceof FoodGroupH) { - FoodUserGroupH eh = (FoodUserGroupH) it.next(); - list.add(new FoodGroup(eh)); + outList.add((T) new FoodGroup((FoodGroupH) hibernateObject)); } + else if (hibernateObject instanceof FoodUserGroupH) + { + outList.add((T) new FoodGroup((FoodUserGroupH) hibernateObject)); + } + else if (hibernateObject instanceof MealGroupH) + { + outList.add((T) new MealGroup((MealGroupH) hibernateObject)); + } + else if (hibernateObject instanceof FoodDescriptionH) + { + outList.add((T) new FoodDescription((FoodDescriptionH) hibernateObject)); + } - return list; } - catch (Exception ex) - { - logException("getUserFoodGroups()", ex); - // LOG.error("Exception on getloadConfigData: " + ex.getMessage(), - // ex); - } - - return list; + return outList; } /** * Get Food Groups - User * - * @param parent_id + * @param parentId parent Group * * @return */ - public ArrayList<FoodGroup> getUserFoodGroups(long parent_id) + public List<FoodGroup> getUserFoodGroups(long parentId) { - logInfo("getUserFoodGroups()"); + List<FoodUserGroupH> fgList = getHibernateObjectListByParameter("parent_id", parentId, Order.asc("name"), + FoodUserGroupH.class, 2); - ArrayList<FoodGroup> list = new ArrayList<FoodGroup>(); - - try - { - - Query q = getSession(2) - .createQuery("select pst from ggc.core.db.hibernate.food.FoodUserGroupH as pst where pst.parent_id=" - + parent_id + " order by pst.name"); - - Iterator<?> it = q.iterate(); - - while (it.hasNext()) - { - FoodUserGroupH eh = (FoodUserGroupH) it.next(); - list.add(new FoodGroup(eh)); - } - - return list; - } - catch (Exception ex) - { - logException("getUserFoodGroups()", ex); - - // LOG.error("Exception on getloadConfigData: " + ex.getMessage(), - // ex); - } - - return list; + return getDAOGroupList(fgList, FoodGroup.class); } @@ -434,73 +354,27 @@ * * @return */ - public ArrayList<MealGroup> getMealGroups() + public List<MealGroup> getMealGroups() { + List<MealGroupH> fgList = getHibernateObjectListByParameter(null, null, Order.asc("name"), MealGroupH.class, 2); - logInfo("getMealGroups()"); - - ArrayList<MealGroup> list = new ArrayList<MealGroup>(); - - try - { - - Query q = getSession(2) - .createQuery("select pst from ggc.core.db.hibernate.food.MealGroupH as pst order by pst.name"); - - Iterator<?> it = q.iterate(); - - while (it.hasNext()) - { - MealGroupH eh = (MealGroupH) it.next(); - list.add(new MealGroup(eh)); - } - - } - catch (Exception ex) - { - logException("getMealGroups()", ex); - } - - return list; + return getDAOGroupList(fgList, MealGroup.class); } /** * Get Meal Groups * - * @param parent_id + * @param parentId parentId of groups * - * @return + * @return List of meal groups */ - public ArrayList<MealGroup> getMealGroups(long parent_id) + public List<MealGroup> getMealGroups(long parentId) { + List<MealGroupH> fgList = getHibernateObjectListByParameter("parent_id", parentId, Order.asc("name"), + MealGroupH.class, 2); - logInfo("getMealGroups()"); - - ArrayList<MealGroup> list = new ArrayList<MealGroup>(); - - try - { - - Query q = getSession(2) - .createQuery("select pst from ggc.core.db.hibernate.food.MealGroupH as pst where pst.parent_id=" - + parent_id + " order by pst.name"); - - Iterator<?> it = q.iterate(); - - while (it.hasNext()) - { - MealGroupH eh = (MealGroupH) it.next(); - list.add(new MealGroup(eh)); - } - - } - catch (Exception ex) - { - logException("getMealGroups()", ex); - } - - return list; + return getDAOGroupList(fgList, MealGroup.class); } @@ -512,7 +386,7 @@ * * @return */ - public ArrayList<FoodDescription> getFoodsByParent(int type, long parent_id) + public List<FoodDescription> getFoodsByParent(int type, long parent_id) { logInfo("getFoodsByParent(type=" + type + ",parent_id=" + parent_id + ")"); @@ -529,73 +403,28 @@ * * @return */ - public ArrayList<FoodDescription> getUSDAFoodDescriptions() + public List<FoodDescription> getUSDAFoodDescriptions() { - logInfo("getUSDAFoodDescriptions()"); + List<FoodDescriptionH> fgList = getHibernateObjectListByParameter(null, null, Order.asc("name"), + FoodDescriptionH.class, 2); - ArrayList<FoodDescription> list = new ArrayList<FoodDescription>(); - - try - { - - Query q = getSession(2).createQuery( - "select pst from ggc.core.db.hibernate.food.FoodDescriptionH as pst order by pst.name"); - - Iterator<?> it = q.iterate(); - - while (it.hasNext()) - { - FoodDescriptionH eh = (FoodDescriptionH) it.next(); - list.add(new FoodDescription(eh)); - } - - return list; - } - catch (Exception ex) - { - logException("getUSDAFoodDescriptions()", ex); - } - - return list; + return getDAOGroupList(fgList, FoodDescription.class); } /** - * Get Food Descriptions - USDA + * Get Food Descriptions By Parent - USDA * - * @param parent_id + * @param parentId * * @return */ - public ArrayList<FoodDescription> getUSDAFoodDescriptionsByParent(long parent_id) + public List<FoodDescription> getUSDAFoodDescriptionsByParent(long parentId) { - logInfo("getUSDAFoodDescriptionsByParent(parent_id=" + parent_id + ")"); + List<FoodDescriptionH> fgList = getHibernateObjectListByParameter("parent_id", parentId, Order.asc("name"), + FoodDescriptionH.class, 2); - ArrayList<FoodDescription> list = new ArrayList<FoodDescription>(); - - try - { - - Query q = getSession(2).createQuery( - "select pst from ggc.core.db.hibernate.food.FoodDescriptionH as pst where pst.group_id=" + parent_id - + " order by pst.name"); - - Iterator<?> it = q.iterate(); - - while (it.hasNext()) - { - FoodDescriptionH eh = (FoodDescriptionH) it.next(); - list.add(new FoodDescription(eh)); - } - - return list; - } - catch (Exception ex) - { - logException("getUSDAFoodDescriptions()", ex); - } - - return list; + return getDAOGroupList(fgList, FoodDescription.class); } @@ -733,11 +562,11 @@ * * @return */ - public ArrayList<FoodDescription> getUserFoodDescriptions() + public List<FoodDescription> getUserFoodDescriptions() { logInfo("getUserFoodDescriptions()"); - ArrayList<FoodDescription> list = new ArrayList<FoodDescription>(); + List<FoodDescription> list = new ArrayList<FoodDescription>(); try { @@ -771,11 +600,11 @@ * * @return */ - public ArrayList<Meal> getMeals() + public List<Meal> getMeals() { logInfo("getMeals()"); - ArrayList<Meal> list = new ArrayList<Meal>(); + List<Meal> list = new ArrayList<Meal>(); try { @@ -813,31 +642,9 @@ */ public Meal getMealById(int type, long meal_id) { - logInfo("getMealById()"); + MealH fg = getHibernateObjectByParameter("id", meal_id, null, MealH.class, 2); - try - { - - Query q = getSession(2) - .createQuery("select pst from ggc.core.db.hibernate.food.MealH as pst where pst.id=" + meal_id); - - Iterator<?> it = q.iterate(); - - while (it.hasNext()) - { - MealH eh = (MealH) it.next(); - // list.put("" + eh.getId(), new Meal(eh)); - return new Meal(eh); - } - - } - catch (Exception ex) - { - logException("getMealById()", ex); - } - - return null; - + return fg != null ? new Meal(fg) : null; } @@ -848,11 +655,11 @@ * * @return */ - public ArrayList<Meal> getMealsByParent(long parent_id) + public List<Meal> getMealsByParent(long parent_id) { logInfo("getMealsByParent()"); - ArrayList<Meal> list = new ArrayList<Meal>(); + List<Meal> list = new ArrayList<Meal>(); try { @@ -890,29 +697,9 @@ */ public Meal getMealById(long id) { - logInfo("getMealById(id=" + id + ")"); + MealH fg = getHibernateObjectByParameter("id", id, null, MealH.class, 2); - try - { - - Query q = getSession(2) - .createQuery("select pst from ggc.core.db.hibernate.food.MealH as pst where pst.id=" + id); - - Iterator<?> it = q.iterate(); - - while (it.hasNext()) - { - MealH eh = (MealH) it.next(); - return new Meal(eh); - } - } - catch (Exception ex) - { - logException("getMealById()", ex); - } - - return null; - + return fg != null ? new Meal(fg) : null; } @@ -924,29 +711,9 @@ */ public MealGroup getMealGroupById(long id) { - logInfo("getMealGroupById(id=" + id + ")"); + MealGroupH fg = getHibernateObjectByParameter("id", id, null, MealGroupH.class, 2); - try - { - - Query q = getSession(2) - .createQuery("select pst from ggc.core.db.hibernate.food.MealGroupH as pst where pst.id=" + id); - - Iterator<?> it = q.iterate(); - - while (it.hasNext()) - { - MealGroupH eh = (MealGroupH) it.next(); - return new MealGroup(eh); - } - } - catch (Exception ex) - { - logException("getMealGroupById()", ex); - } - - return null; - + return fg != null ? new MealGroup(fg) : null; } @@ -1077,169 +844,7 @@ } - // ************************************************************* - // **** GGC Main Data **** - // **** Comment: Were implemnted in DataBaseHandler **** - // ************************************************************* - - /** - * Get DayValuesData - * - * @param from - * @param till - * @return - */ - public DayValuesData getDayValuesData(long from, long till) - { - - if (m_loadStatus == DB_CONFIG_LOADED) - return null; - - logInfo("getDayValuesData()"); - - DayValuesData dvd = new DayValuesData(from, till); - - try - { - Query q = getSession().createQuery("SELECT dv from " + "ggc.core.db.hibernate.DayValueH as dv " - + "WHERE dv.dt_info >= " + from + "0000 AND dv.dt_info <= " + till + "2359 ORDER BY dv.dt_info"); - - Iterator<?> it = q.list().iterator(); - - while (it.hasNext()) - { - DayValueH dv = (DayValueH) it.next(); - - DailyValuesRow dVR = new DailyValuesRow(dv); - dvd.addDayValueRow(dVR); - } - - } - catch (Exception ex) - { - logException("getDayValuesData()", ex); - } - - return dvd; - - } - - - /** - * Save Day Stats - * - * @param dV - */ - public void saveDayStats(DailyValues dV) - { - - if (dV.hasChanged()) - { - logInfo("saveDayStats()"); - - logDebug("saveDayStats()", "Data has changed"); - - Session sess = getSession(); - - try - { - - // deleted entries - - if (dV.hasDeletedItems()) - { - logDebug("saveDayStats()", "Removing deleted entry"); - - Transaction tx = sess.beginTransaction(); - - ArrayList<DayValueH> list = dV.getDeletedItems(); - for (int i = 0; i < list.size(); i++) - { - DayValueH d = list.get(i); - sess.delete(d); - tx.commit(); - } - - } - - // see if any of elements were changed or added - - for (int i = 0; i < dV.getRowCount(); i++) - { - DailyValuesRow dwr = dV.getRow(i); - - if (dwr.isNew()) - { - logDebug("saveDayStats()", "Adding new entry"); - - Transaction tx = sess.beginTransaction(); - - DayValueH dvh = dwr.getHibernateObject(); - Long l = (Long) sess.save(dvh); - - dvh.setId(l.longValue()); - tx.commit(); - } - else if (dwr.hasChanged()) - { - Transaction tx = sess.beginTransaction(); - - logDebug("saveDayStats()", "Changing entry"); - - DayValueH dvh = dwr.getHibernateObject(); - sess.update(dvh); - - tx.commit(); - } - - } // for - - } - catch (Exception ex) - { - logException("saveDayStats()", ex); - } - - } // hasChanged - else - { - logDebug("saveDayStats()", "No entries changed"); - } - - } - - - /** - * DateTime Exists - * - * @param datetime - * @return - */ - public boolean dateTimeExists(long datetime) - { - if (m_loadStatus == DB_CONFIG_LOADED) - return false; - - // if (db_debug) - // System.out.println("Hibernate: dateTimeExists()"); - - try - { - Query q = getSession().createQuery( - "SELECT dv from " + "ggc.nutri.db.hibernate.DayValueH as dv " + "WHERE dv.dt_info = " + datetime); - - return q.list().size() == 1; - } - catch (Exception ex) - { - logException("dateTimeExists()", ex); - return false; - } - - } - - // ************************************************************* // **** NUTRITION DATA **** // ************************************************************* @@ -1249,7 +854,7 @@ * * @return */ - public ArrayList<SelectableInterface> getNutritionHomeWeights() + public List<SelectableInterface> getNutritionHomeWeights() { return this.cache_db.homeweight_defs_list; } @@ -1272,62 +877,12 @@ * * @return */ - public ArrayList<SelectableInterface> getNutritionDefinitions() + public List<SelectableInterface> getNutritionDefinitions() { return this.cache_db.nutrition_defs_list; } - // ************************************************************* - // **** TOOLS Db METHODS **** - // ************************************************************* - /* - * <class name="ggc.nutri.db.hibernate.GlucoValueH" table="data_dayvalues" > - * <id name="id" type="long" unsaved-value="0"> - * <generator class="org.hibernate.id.AssignedIncrementGenerator"/> - * </id> - * <property name="dt_info" type="long" not-null="true"/> - * <property name="bg" type="int" /> - * <property name="person_id" type="int" not-null="true" /> - * <property name="changed" type="long" not-null="false" /> - * </class> - */ - - - // ************************************************************* - // **** U T I L S **** - // ************************************************************* - /* - * public String changeCase(String in) - * { - * StringTokenizer stok = new StringTokenizer(in, " "); - * boolean first = true; - * String out = ""; - * while (stok.hasMoreTokens()) - * { - * if (!first) - * out += " "; - * out += changeCaseWord(stok.nextToken()); - * first = false; - * } - * return out; - * } - * public String changeCaseWord(String in) - * { - * String t = ""; - * t = in.substring(0, 1).toUpperCase(); - * t += in.substring(1).toLowerCase(); - * return t; - * } - * public void showByte(byte[] in) - * { - * for (int i = 0; i < in.length; i++) - * { - * System.out.println((char) in[i] + " " + in[i]); - * } - * } - */ - /** * Debug Out */ @@ -1415,18 +970,8 @@ public Session getSession(int session_nr) { return this.hib_config.getSession(session_nr); - /* - * if (session_nr == 1) - * { - * m_session.clear(); - * return m_session; - * } - * else - * { - * m_session_2.clear(); - * return m_session_2; - * } - */ } + // 1457 + } Added: trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DAOObject.java =================================================================== --- trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DAOObject.java (rev 0) +++ trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DAOObject.java 2016-12-25 18:28:11 UTC (rev 1440) @@ -0,0 +1,8 @@ +package ggc.nutri.db.datalayer; + +/** + * Created by andy on 26/09/16. + */ +public interface DAOObject +{ +} Modified: trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DailyFoodEntries.java =================================================================== --- trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DailyFoodEntries.java 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DailyFoodEntries.java 2016-12-25 18:28:11 UTC (rev 1440) @@ -1,13 +1,12 @@ package ggc.nutri.db.datalayer; -import ggc.nutri.util.DataAccessNutri; - import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; import java.util.StringTokenizer; import com.atech.i18n.I18nControlAbstract; +import ggc.nutri.util.DataAccessNutri; /** * Application: GGC - GNU Gluco Control @@ -35,8 +34,10 @@ * Author: andyrozman {an...@at...} */ -public class DailyFoodEntries // implements SelectableInterface +public class DailyFoodEntries implements DAOObject // implements + // SelectableInterface { + String text_idx; DataAccessNutri m_da = DataAccessNutri.getInstance(); I18nControlAbstract ic = m_da.getI18nControlInstance(); @@ -47,6 +48,7 @@ ArrayList<DailyFoodEntry> entries = null; + /** * Default constructor */ @@ -55,6 +57,7 @@ entries = new ArrayList<DailyFoodEntry>(); } + /** * Constructor * @@ -71,6 +74,7 @@ } } + /** * Constructor * @@ -93,6 +97,7 @@ } } + /** * Add Daily Food Entry * @@ -117,6 +122,7 @@ } } + /** * Get Calculated Nutrients * @@ -181,6 +187,7 @@ return out_lst; } + /** * Get Elements Count * @@ -191,6 +198,7 @@ return this.entries.size(); } + /** * Get Element * @@ -202,6 +210,7 @@ return this.entries.get(index); } + /** * To String * Modified: trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DailyFoodEntry.java =================================================================== --- trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DailyFoodEntry.java 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/src/ggc/nutri/db/datalayer/DailyFoodEntry.java 2016-12-25 18:28:11 UTC (rev 1440) @@ -1,9 +1,5 @@ package ggc.nutri.db.datalayer; -import ggc.nutri.data.GGCTreeRoot; -import ggc.nutri.util.DataAccessNutri; -import ggc.plugin.util.DataAccessPlugInBase; - import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; @@ -11,6 +7,10 @@ import com.atech.i18n.I18nControlAbstract; +import ggc.nutri.data.GGCTreeRoot; +import ggc.nutri.util.DataAccessNutri; +import ggc.plugin.util.DataAccessPlugInBase; + /** * Application: GGC - GNU Gluco Control * @@ -36,8 +36,10 @@ * Author: andyrozman {an...@at...} */ -public class DailyFoodEntry // implements SelectableInterface +public class DailyFoodEntry implements DAOObject// implements + // SelectableInterface { + private boolean debug = false; String text_idx; DataAccessNutri m_da = DataAccessNutri.getInstance(); @@ -93,6 +95,7 @@ ArrayList<DailyFoodEntry> children = null; + /** * Constructor (food + weight) * @@ -104,6 +107,7 @@ this(fd.getFoodType(), fd, null, DailyFoodEntry.WEIGHT_TYPE_WEIGHT, null, weight); } + /** * Constructor (food + home weight) * @@ -116,6 +120,7 @@ this(fd.getFoodType(), fd, null, DailyFoodEntry.WEIGHT_TYPE_HOME_WEIGHT, hw, amount); } + /** * Constructor (meal + amount) * @@ -127,6 +132,7 @@ this(3, null, ml, DailyFoodEntry.WEIGHT_TYPE_AMOUNT, null, amount); } + /** * Constructor (many parameters) - Main * @@ -175,6 +181,7 @@ } + /** * Daily Food Entry (String) * @param val @@ -208,6 +215,7 @@ } + /** * Constructor (String, boolean) * @@ -235,6 +243,7 @@ loadNutrients(); } + /** * Constructor (String, int) * @@ -274,6 +283,7 @@ */ } + /* * public DailyFoodEntry(MealPart mpart) { if mpart.getType()== } */ @@ -284,6 +294,7 @@ loadObjects(); } + private void loadObjects() { // new GGCTreeRoot(1); @@ -299,7 +310,8 @@ { // System.out.println("dataAccess: " + dataAccess); - // System.out.println("dataAccess.getDbCache(): " + dataAccess.getDbCache()); + // System.out.println("dataAccess.getDbCache(): " + + // dataAccess.getDbCache()); // System.out.println("dataAccess.getDbCache().tree_roots: " + // dataAccess.getDbCache().tree_roots); // System.out.println("dataAccess: " + dataAccess); @@ -317,6 +329,7 @@ } + /** * Add Child * @@ -335,6 +348,7 @@ } + /** * Has Children * @@ -348,11 +362,13 @@ return true; } + private void createId() { this.component_id = DataAccessNutri.getInstance().getNewComponentId(); } + /** * Add Multiplier * @@ -372,6 +388,7 @@ } } + /** * Add Multipliers * @@ -395,6 +412,7 @@ } } + /** * Get Name * @@ -410,6 +428,7 @@ return ""; } + /** * Get Nutrition Food Type * @@ -420,6 +439,7 @@ return this.nutrition_food_type; } + /** * Get Food Type * @@ -433,6 +453,7 @@ return 3; // this.m_meal.getName(); } + /** * Get Weight Type * @@ -443,6 +464,7 @@ return this.amount_type; } + /** * Get Weight Type String * @@ -453,6 +475,7 @@ return this.amount_type_str[this.amount_type]; } + /** * Get Home Weight Description * @@ -471,6 +494,7 @@ return ""; } + /** * Get Amount String * @@ -481,6 +505,7 @@ return DataAccessPlugInBase.Decimal2Format.format(this.amount); } + /** * Get Amount Single Decimal String * @@ -491,10 +516,11 @@ return DataAccessPlugInBase.Decimal1Format.format(this.amount); } + private void loadHomeWeight() { // System.out.println("HWs: " + this.m_food.getHome_weights()); - // System.out.println("Looking for: " + this.home_weight_id); + // System.out.println("Looking for: " + this.home_weight_id); if (this.m_food.getHome_weights() == null && this.m_food.getHome_weights().length() == 0) return; @@ -515,6 +541,7 @@ } + /** * Get Meal CHs * @@ -546,6 +573,7 @@ return sum; } + private void calculateMultiplier() { // System.out.println("calculateMultiplier"); @@ -571,6 +599,7 @@ } } + private float getMultiplier() { if (this.calculated_multiplier == 0.0f) @@ -581,11 +610,13 @@ return this.calculated_multiplier; } + private Hashtable<String, String> getMultipliers() { return this.multiplier; } + /** * Get Children * @@ -601,6 +632,7 @@ return this.children; } + /** * Get Short Description * @@ -611,6 +643,7 @@ return this.getName() + " [" + this.getAmountString() + " x " + this.weight + " g]"; } + private int getAmountType(String type) { for (int i = 1; i < this.amount_type_str.length; i++) @@ -622,6 +655,7 @@ return -1; } + /** * Get Amount Type * @@ -632,6 +666,7 @@ return this.amount_type; } + /** * Get Amount * @@ -642,6 +677,7 @@ return this.amount; } + /** * Get Food Object * @return @@ -651,6 +687,7 @@ return this.m_food; } + /** * Get Meal Object * @@ -661,6 +698,7 @@ return this.m_meal; } + /** * Get Home Weight Special Object * @@ -671,6 +709,7 @@ return this.m_home_weight_special; } + // TODO: New code /** @@ -687,6 +726,7 @@ } + /** * Display Nutritions */ @@ -704,6 +744,7 @@ } + /** * To String * @@ -716,6 +757,7 @@ return getShortDescription(); } + /** * Get Value String * @@ -747,6 +789,7 @@ } + private void loadNutrients() { String nutr; @@ -777,6 +820,7 @@ */ } + private void processMeal(Meal meal) { if (meal == null) @@ -840,6 +884,7 @@ * } } } */ + /* * v3.1 * private void mergeGlycemicData(DailyFoodEntry dfe) @@ -892,6 +937,7 @@ } } + /** * Get Nutrients * @@ -936,6 +982,7 @@ return this.nutrients; } + /** * Get Nutrient Value * @@ -957,6 +1004,7 @@ return 0.0f; } + @SuppressWarnings("unused") private ArrayList<MealNutrition> createList(Hashtable<String, MealNutrition> table) { @@ -975,6 +1023,7 @@ return lst; } + /** * Get Home Weight Multiplier * @@ -1041,6 +1090,7 @@ * return this.nutrients; } */ + /* * proc v1 public void calculateNutrition(MealNutrition mn, float mult) { * if ((mn.getId()>=4000) && (mn.getId()<=4005)) { addGlycemicNutrient(mn); @@ -1061,6 +1111,7 @@ } } + /** * Contains Glycemic Nutrients * @@ -1071,6 +1122,7 @@ return this.glyc_nutr != null; } + /** * Get Glycemic Nutrients * @@ -1081,6 +1133,7 @@ return this.glyc_nutr; } + /** * getObjectName - returns name of DatabaseObject * @@ -1091,6 +1144,7 @@ return "Daily Food Entry"; } + /** * isDebugMode - returns debug mode of object * @@ -1101,6 +1155,7 @@ return debug; } + /** * getAction - returns action that should be done on object * 0 = no action 1 = add action 2 = edit action 3 = delete action @@ -1116,6 +1171,7 @@ return 0; } + /** * getItemId * Modified: trunk/ggc-nutri/src/ggc/nutri/db/datalayer/FoodDescription.java =================================================================== --- trunk/ggc-nutri/src/ggc/nutri/db/datalayer/FoodDescription.java 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/src/ggc/nutri/db/datalayer/FoodDescription.java 2016-12-25 18:28:11 UTC (rev 1440) @@ -42,7 +42,7 @@ * Author: andyrozman {an...@at...} */ -public class FoodDescription implements DatabaseObjectHibernate, BackupRestoreObject +public class FoodDescription implements DatabaseObjectHibernate, BackupRestoreObject, DAOObject { private boolean debug = false; Modified: trunk/ggc-nutri/src/ggc/nutri/db/datalayer/FoodGroup.java =================================================================== --- trunk/ggc-nutri/src/ggc/nutri/db/datalayer/FoodGroup.java 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/src/ggc/nutri/db/datalayer/FoodGroup.java 2016-12-25 18:28:11 UTC (rev 1440) @@ -1,6 +1,7 @@ package ggc.nutri.db.datalayer; import java.util.ArrayList; +import java.util.List; import java.util.Map; import org.hibernate.Session; @@ -43,7 +44,7 @@ * Author: andyrozman {an...@at...} */ -public class FoodGroup implements DatabaseObjectHibernate, BackupRestoreObject +public class FoodGroup implements DatabaseObjectHibernate, BackupRestoreObject, DAOObject { private boolean debug = false; @@ -59,19 +60,19 @@ /** * Children - Groups */ - public ArrayList<FoodGroup> children_group = null; // new - // ArrayList<FoodGroup>(); + public List<FoodGroup> children_group = null; // new + // ArrayList<FoodGroup>(); /** * Children - All */ - public ArrayList<Object> children = null; // new ArrayList<Object>(); + public List<Object> children = null; // new ArrayList<Object>(); /** * Children - Foods */ - public ArrayList<FoodDescription> children_food = null; // new - // ArrayList<Meal>(); + public List<FoodDescription> children_food = null; // new + // ArrayList<Meal>(); // public ArrayList<MealGroup> children_group = null; //new // ArrayList<MealGroup>(); Modified: trunk/ggc-nutri/src/ggc/nutri/db/datalayer/GlycemicNutrients.java =================================================================== --- trunk/ggc-nutri/src/ggc/nutri/db/datalayer/GlycemicNutrients.java 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/src/ggc/nutri/db/datalayer/GlycemicNutrients.java 2016-12-25 18:28:11 UTC (rev 1440) @@ -1,11 +1,10 @@ package ggc.nutri.db.datalayer; -import ggc.nutri.util.DataAccessNutri; - import java.util.ArrayList; import java.util.Hashtable; import com.atech.i18n.I18nControlAbstract; +import ggc.nutri.util.DataAccessNutri; /** * Application: GGC - GNU Gluco Control @@ -32,8 +31,9 @@ * Author: andyrozman {an...@at...} */ -public class GlycemicNutrients +public class GlycemicNutrients implements DAOObject { + DataAccessNutri m_da = DataAccessNutri.getInstance(); I18nControlAbstract ic = m_da.getI18nControlInstance(); Hashtable<String, ArrayList<MealNutrition>> gly_nutrients; @@ -46,6 +46,7 @@ String weight; Hashtable<String, MealNutrition> nutrients = null; + /** * Constructor * @@ -58,6 +59,7 @@ processEntry(mn); } + /** * */ @@ -67,6 +69,7 @@ System.out.println("mergeGlycemicData not implemented"); } + private void loadGI_GL() { // GI = 4000, GL = 4001, GI_MIN = 4002, GI_MAX = 4003, GL_MIN = 4004, @@ -77,6 +80,7 @@ this.nutrients.put("4005", new MealNutrition(4005, 0.0f, "GL Max")); } + /** * Add Nutrient * @@ -87,6 +91,7 @@ this.processEntry(mn); } + private void processEntry(MealNutrition mn) { // GI = 4000, GL = 4001, GI_MIN = 4002, GI_MAX = 4003, GL_MIN = 4004, @@ -120,6 +125,7 @@ } + private void checkGI_GL(Hashtable<String, MealNutrition> nutres, MealNutrition mn, boolean GI) { // GI = 4000, GL = 4001, GI_MIN = 4002, GI_MAX = 4003, GL_MIN = 4004, @@ -165,6 +171,7 @@ } + private void checkGI_GL_Max(Hashtable<String, MealNutrition> nutres, MealNutrition mn, boolean GI) { // GI = 4000, GL = 4001, GI_MIN = 4002, GI_MAX = 4003, GL_MIN = 4004, @@ -195,6 +202,7 @@ } + private void checkGI_GL_Min(Hashtable<String, MealNutrition> nutres, MealNutrition mn, boolean GI) { // GI = 4000, GL = 4001, GI_MIN = 4002, GI_MAX = 4003, GL_MIN = 4004, Modified: trunk/ggc-nutri/src/ggc/nutri/db/datalayer/HomeWeightSpecial.java =================================================================== --- trunk/ggc-nutri/src/ggc/nutri/db/datalayer/HomeWeightSpecial.java 2016-12-25 18:18:32 UTC (rev 1439) +++ trunk/ggc-nutri/src/ggc/nutri/db/datalayer/HomeWeightSpecial.java 2016-12-25 18:28:11 UTC (rev 1440) @@ -1,10 +1,9 @@ package ggc.nutri.db.datalayer; -import ggc.nutri.util.DataAccessNutri; - import com.atech.graphics.dialogs.selector.ColumnSorter; import com.atech.graphics.dialogs.selector.SelectableInterface; import com.atech.i18n.I18nControlAbstract; +import ggc.nutri.util.DataAccessNutri; /** * Application: GGC - GNU Gluco Control @@ -31,8 +30,9 @@ * Author: andyrozman {an...@at...} */ -public class HomeWeightSpecial implements SelectableInterface +public class HomeWeightSpecial implements SelectableInterface, DAOObject { + DataAccessNutri m_da = DataAccessNutri.getInstance(); I18nControlAbstract ic = m_da.getI18nControlInstance(); @@ -45,6 +45,7 @@ String weight; float calculated_weight = 0.0f; + /** * Constructor */ @@ -53,6 +54,7 @@ } + /** * Constructor * @@ -65,6 +67,7 @@ this(id, name, "1", weight); } + /** * Constructor * @@ -95,6 +98,7 @@ } + /** * Constructor * @@ -113,6 +117,7 @@ setSearchContext(); } + /* * public NutritionHomeWeightType(NutritionHomeWeightTypeH ch) { * this.setId(ch.getId()); this.setName(ch.getName()); setSearchContext(); } @@ -133,6 +138,7 @@ } + /** * Get Calculated Weight * @@ -148,6 +154,7 @@ return this.calculated_weight; } + /** * Get Short Description * @@ -159,6 +166,7 @@ return this.name + " [" + this.amount + " x " + this.weight + " g]"; } + /** * To String * @@ -170,6 +178,7 @@ return getShortDescription(); } + /** * Get Name * @@ -180,6 +189,7 @@ return this.name; } + /** * getObjectName - returns name of DatabaseObject * @@ -190,6 +200,7 @@ return "Home Weight Type"; } + /** * isDebugMode - returns debug mode of object * @@ -200,6 +211,7 @@ return debug; } + /** * getAction - returns action that should be done on object 0 = no action 1 * = add action 2 = edit action 3 = delete action This is used mainly for @@ -213,6 +225,7 @@ return 0; } + // --- // --- SelectorInterface // --- @@ -225,6 +238,7 @@ return 4; } + /** * Get Column Name */ @@ -247,6 +261,7 @@ } } + /** * Get Column Value */ @@ -270,6 +285,7 @@ } + /** * Get Column Value Object */ @@ -292,6 +308,7 @@ } } + /** * Get Column Width */ @@ -318,6 +335,7 @@ } + /** * Get Item Id */ @@ -326,6 +344,7 @@ return this.id; } + /** * Is Found */ @@ -334,6 +353,7 @@ return true; } + /** * Is Found */ @@ -342,6 +362,7 @@ return true; } + /** * Is Found */ @@ -353,6 +374,7 @@ return false; } + /** * Set Search Context */ @@ -367,6 +389,7 @@ private ColumnSorter columnSorter = null; + /** * setColumnSorter - sets class that will help with column sorting * @@ -377,6 +400,7 @@ this.columnSorter = cs; } + /** * Compares this object with the specified object for order. Returns a * negative integer, zero, or a positive integer as this object is less Modified: trunk/ggc-nutri/src/ggc/nutri/db/datalayer/Meal.java =================================================================== --- trunk/ggc-nutri/src/ggc/nutri/db/datalayer/Meal.java 2016-12-25 18:18:32 UTC (rev 1439... [truncated message content] |