|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectca.spaz.cron.datasource.AbstractFoodDataSource
ca.spaz.cron.datasource.AbstractMutableFoodDatasource
ca.spaz.cron.datasource.sql.SQLDatasource
public class SQLDatasource
A Food datasource that is based on a SQL database.
| Field Summary | |
|---|---|
protected java.sql.Connection |
conn
|
static java.lang.String |
FOOD_DB_ID
|
| Constructor Summary | |
|---|---|
protected |
SQLDatasource(java.lang.String name,
java.lang.String id,
java.sql.Connection conn,
boolean allowLocal)
|
| Method Summary | |
|---|---|
void |
close()
Close this connection. |
boolean |
containsFood(Food food)
Determine if this datasource contains the specified food. |
static ILocalFoodDatasource |
createPersonalFoodSource()
|
static ILocalFoodDatasource |
createPersonalFoodSource(java.lang.String connectionId)
|
static IFoodDatasource |
createReadonlyFoodSource(java.lang.String connectionID)
|
protected Food |
doAddFood(Food food)
Add a Food to this datasource. |
protected void |
doAddFoodGroup(FoodGroup foodGroup)
Add a new FoodGroup to the data source. |
protected boolean |
doAddMeasure(Food food,
Measure measure)
Each food in the Datasource has available a list of Measures that
describe portions or servings. |
protected boolean |
doChangeMeasure(Food food,
java.util.List measures)
Update all changes made to a set of measures for the food. |
protected boolean |
doChangeServingAmount(Serving serving)
Changes the amount of a food consumed to the amount in the serving provided. |
protected Food |
doConsumeFood(Serving serving)
This method consumes the food in a serving. |
protected Food |
doCreateNewFood()
Create a new Food object associated with this datasource. |
protected java.util.List |
doFindAllFoods()
Retrieve a list of all foods in this datasource. |
protected java.util.List |
doFindFoods(java.lang.String[] parts)
Retrieve a List of all foods in this particular Datasource. |
protected java.util.List |
doFindFoods(java.lang.String[] keys,
java.lang.String foodGroup,
java.lang.String source)
Retrieve a List of all foods in this particular Datasource having
the given food group and source. |
protected java.util.List |
doGetMeasuresFor(Food food)
Return a List of Measure objects for the provided food. |
protected void |
doGetNutrientsFor(Food food,
NutrientTable nutrients)
Fill the provided NutrientTable with the nutrients associated with the
Food. |
protected int |
doGetTimesConsumed(Food food)
Retrieve the total number of times that this food has been consumed. |
protected int |
doGetTimesConsumed(Food food,
java.util.Date startDate,
java.util.Date endDate)
Retrieve the number of times the specified Food was consumed
between the provided dates. |
protected boolean |
doRemoveFood(Food food)
Remove a Food from the datasource. |
protected boolean |
doRemoveMeasure(Food food,
Measure m)
Remove a measure from the database. |
protected boolean |
doSaveFood(Food food)
Alter the information of some Food object in the backing representation of the datasource. |
protected boolean |
doSaveMeasure(Measure measure)
|
protected boolean |
doUnConsumeFood(Serving serving)
Remove the Food in a particular serving from the user's consumed
list. |
protected Food |
findFoodBySourceUID(java.lang.String sourceUID)
Find a local food by its sourceUID field value. |
java.util.List |
getConsumedOn(java.util.Date date)
Retrieve a list of all Servings consumed on a particular date. |
java.util.List |
getFoodGroups()
Get a list of all food groups in this datasource. |
java.lang.String |
getId()
Retrieve the id from the SQLDatasource. |
java.util.List |
getSources()
Get a list of all sources in this datasource. |
void |
initialize()
Initialize the datasource to a working state. |
boolean |
isAvailable()
Determines if the datasource is operable and available. |
boolean |
isListable()
Implementors that can provide listing services should return true here, false otherwise. |
boolean |
isSearchable()
Implementors that can provide search services should return true here, false otherwise. |
void |
setId(java.lang.String id)
Set the id in the SQLDatasource. |
| Methods inherited from class ca.spaz.cron.datasource.AbstractMutableFoodDatasource |
|---|
addFood, addFoodDatasourceListener, addFoodGroup, addMeasure, addServing, changeMeasure, changeServingAmount, createNewFood, getNotify, getTimesConsumed, getTimesConsumed, notifyObservers, notifyObservers, removeFood, removeFoodDatasourceListener, removeMeasure, removeServing, saveFood, setNotify |
| Methods inherited from class ca.spaz.cron.datasource.AbstractFoodDataSource |
|---|
diffSource, findAllFoods, findFoods, findFoods, getLastError, getMeasuresFor, getName, getNutrientsFor, notNull, registerError, sameSource, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface ca.spaz.cron.datasource.IFoodDatasource |
|---|
findAllFoods, findFoods, findFoods, getLastError, getMeasuresFor, getName, getNutrientsFor |
| Field Detail |
|---|
protected java.sql.Connection conn
public static final java.lang.String FOOD_DB_ID
| Constructor Detail |
|---|
protected SQLDatasource(java.lang.String name,
java.lang.String id,
java.sql.Connection conn,
boolean allowLocal)
| Method Detail |
|---|
public static IFoodDatasource createReadonlyFoodSource(java.lang.String connectionID)
public static ILocalFoodDatasource createPersonalFoodSource()
public static ILocalFoodDatasource createPersonalFoodSource(java.lang.String connectionId)
protected Food doConsumeFood(Serving serving)
AbstractMutableFoodDatasourceFood object have
this as its datasource, since in this case if the Food
object has a different datasource, it will either A) be added to this
one, and then consumed, or B) if it is already present in this datasource
it will simply be added from this datasource.
doConsumeFood in class AbstractMutableFoodDatasourceserving - a Serving to add to the user's consumed list.
Food object that represents the Food
that is associated with this datasource. If the food was already associated
with this datasource, the same object will be returned. null
will be returned if some error occurred.protected boolean doChangeServingAmount(Serving serving)
AbstractMutableFoodDatasourceFood retrieved by calling
getFood() on newServing. If the food is not already
in the database as being consumed, it will be added. The food must already
be in the user datasource, however.
doChangeServingAmount in class AbstractMutableFoodDatasourceserving - a Serving object whose Food's serving
quantity on the proper date will be altered.
true if the serving was altered, false if some
error occurred.protected boolean doUnConsumeFood(Serving serving)
AbstractMutableFoodDatasourceFood in a particular serving from the user's consumed
list. Operates regardless of quantity.
doUnConsumeFood in class AbstractMutableFoodDatasourceserving - the serving to un-consume.
true if the action succeeded, false if there
was some error.
protected boolean doChangeMeasure(Food food,
java.util.List measures)
doChangeMeasure in class AbstractMutableFoodDatasourcetrue if successful, false if some error occurred.
protected boolean doRemoveMeasure(Food food,
Measure m)
doRemoveMeasure in class AbstractMutableFoodDatasourcem - the Measure to delete
protected boolean doAddMeasure(Food food,
Measure measure)
AbstractMutableFoodDatasourceMeasures that
describe portions or servings. This method will add a valid Measure
to a Food object stored in this datasource.
doAddMeasure in class AbstractMutableFoodDatasourcefood - The Food object to which the new measure applies.measure - The new Measure.
true if successful, false if some error occurred.protected boolean doSaveMeasure(Measure measure)
protected int doGetTimesConsumed(Food food)
AbstractMutableFoodDatasource
doGetTimesConsumed in class AbstractMutableFoodDatasourcefood - the Food to check.
-1 on error.
protected int doGetTimesConsumed(Food food,
java.util.Date startDate,
java.util.Date endDate)
AbstractMutableFoodDatasourceFood was consumed
between the provided dates.
doGetTimesConsumed in class AbstractMutableFoodDatasourcefood - the Food to check.startDate - the starting date.endDate - the ending date.
-1
on error.public java.util.List getConsumedOn(java.util.Date date)
ILocalFoodDatasourceServings consumed on a particular date.
date - the Date to retrieve the foods for.
List consisting only of Serving objects,
or null if some error occurred. If no servings were consumed
on the specified date, an empty list will be returned.protected Food doAddFood(Food food)
AbstractMutableFoodDatasourceFood to this datasource.
This method is an exception to the local datasource rule -- the Food
provided to this method must not be attached to this datasource.
doAddFood in class AbstractMutableFoodDatasourcefood - A Food object that comes from another datasource.
Food object whose information is the same as the parameter,
but that exists only in this datasource, with all nutrient information still
represtented. null will be returned if some error occurred.protected boolean doSaveFood(Food food)
AbstractMutableFoodDatasourceFood implementation specific to the datasource has a concept of
unique identifiers, a true alteration will occur. However, if the Food
object does not have this feature, for example in a flat-file database or something
like it, the implementor should check for name similarity, and if that does not
match, simply add the new food to the database.
doSaveFood in class AbstractMutableFoodDatasourcefood - a Food object to be changed.
true if successful, false if some error occurred.protected boolean doRemoveFood(Food food)
AbstractMutableFoodDatasourceFood from the datasource.
doRemoveFood in class AbstractMutableFoodDatasourcefood - the Food to remove.
true if successful, false if some error occurred.protected java.util.List doFindFoods(java.lang.String[] parts)
AbstractFoodDataSourceList of all foods in this particular Datasource.
doFindFoods in class AbstractFoodDataSourceparts - the keys to search on. This searches with an AND relation.
Food objects matching the criteria.
protected java.util.List doFindFoods(java.lang.String[] keys,
java.lang.String foodGroup,
java.lang.String source)
AbstractFoodDataSourceList of all foods in this particular Datasource having
the given food group and source.
doFindFoods in class AbstractFoodDataSourcekeys - the keys to search on. This searches with an AND relation.foodGroup - the food group to search for. null to ignore.source - the source of this food item. null to ignore.
Food objects matching the criteria.protected java.util.List doFindAllFoods()
AbstractFoodDataSource
doFindAllFoods in class AbstractFoodDataSourceFood objects consisting of every food in the datasource.protected java.util.List doGetMeasuresFor(Food food)
AbstractFoodDataSourceList of Measure objects for the provided food.
doGetMeasuresFor in class AbstractFoodDataSourcefood - a Food object to find the measures for
List that is guaranteed to contain only Measure
objects.
protected void doGetNutrientsFor(Food food,
NutrientTable nutrients)
AbstractFoodDataSourceNutrientTable with the nutrients associated with the
Food.
doGetNutrientsFor in class AbstractFoodDataSourcefood - The food item to load fromnutrients - the NutrientTable to fill.public java.util.List getSources()
IFoodDatasource
List of String objects naming the sources
for this Datasource.public java.util.List getFoodGroups()
IFoodDatasource
List of FoodGroup objects naming the food
groups for this Datasource.public boolean isSearchable()
IFoodDatasource
true if this Datasource supports search, false
otherwise.public boolean isAvailable()
IFoodDatasource
true if this datasource is functioning, false
otherwisepublic boolean isListable()
IFoodDatasource
true if this Datasource supports listing, false
otherwise.protected Food doCreateNewFood()
AbstractMutableFoodDatasourceFood object associated with this datasource.
doCreateNewFood in class AbstractMutableFoodDatasourceFood instance.public void close()
IFoodDatasource
public void initialize()
IFoodDatasourceisAvailable must return
true for this data source. If this source is already available, this
method will do nothing.
protected void doAddFoodGroup(FoodGroup foodGroup)
AbstractMutableFoodDatasource
doAddFoodGroup in class AbstractMutableFoodDatasourcefoodGroup - the new food group to add to the data source.public void setId(java.lang.String id)
id in the SQLDatasource.
id - The id to set.public java.lang.String getId()
id from the SQLDatasource. This will be
unique between all SQL data source instances.
protected Food findFoodBySourceUID(java.lang.String sourceUID)
AbstractMutableFoodDatasource
findFoodBySourceUID in class AbstractMutableFoodDatasourcesourceUID - The key to search on
Food found, or null if no food matched.public boolean containsFood(Food food)
IFoodDatasourceFood in this datasource, the Food's SourceUID is equal
to that of the food on the command line.
food - The food to test for
true if there is a Food in this datasource matching the
provided one.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||