hydroScalingAPI.util.database
Class DataBaseEngine

java.lang.Object
  extended by hydroScalingAPI.util.database.DataBaseEngine

public class DataBaseEngine
extends java.lang.Object

A Memory based implementation of a database engine. This was created to simplify the comunication between GUIs and Analysis Modules with the Gauges and Locations data in CUENCAS. However it is generic enough to handle other types of registers.

Author:
Ricardo Mantilla

Field Summary
static int EQUAL_TO
          The value used to indicate a EQUAL_TO type of comparison
static int GREATER_THAN
          The value used to indicate a GREATER_THAN type of comparison
static int SMALLER_THAN
          The value used to indicate a SMALLER_THAN type of comparison
 
Constructor Summary
DataBaseEngine()
          Creates a new instance of DataBaseEngine
 
Method Summary
 void addData(java.lang.String tableName, java.lang.String RegisterIndex, DB_Register Field)
          Adds an entry to one of the tables
 void addData(java.lang.String tableName, java.lang.String RegisterIndex, java.lang.Object[] Values)
          Adds an entry to one of the tables
 void addTable(java.lang.String tableName, java.lang.String[] Fields, java.lang.String[] Type)
          Adds a DB_Table into the database engine
 DB_Register[] compareFieldsTo(java.lang.String tableName, java.lang.String[] FieldName, java.lang.Object[] ValueToCompare, int[] ConditionToCheckFor)
          A more general search for registers in a table.
 DB_Register[] findRegister(java.lang.String tableName, java.lang.String[] FieldName, java.lang.Object[] ValueToMatch)
          Finds registers in a table that match a set of values criteria in several of its properties (e.g.
 java.lang.Double getMaxValue(java.lang.String tableName, java.lang.String FieldName)
          Returns the maximum value for a given "Numeric" Property in a given table
 java.lang.Double getMinValue(java.lang.String tableName, java.lang.String FieldName)
          Returns the minimum value for a given "Numeric" Property in a given table
 DB_Register getRegisterByMainIndex(java.lang.String tableName, java.lang.Object ValueToMatch)
          Returns a DB_Register whose main index matches a predetermined keyword in a specific table
 java.util.Vector getUniqueValues(java.lang.String tableName, java.lang.String FieldName)
          Returns a vector of Objects with unique values for a given property
static void main(java.lang.String[] args)
          An extensive test for the Database engine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SMALLER_THAN

public static final int SMALLER_THAN
The value used to indicate a SMALLER_THAN type of comparison

See Also:
Constant Field Values

EQUAL_TO

public static final int EQUAL_TO
The value used to indicate a EQUAL_TO type of comparison

See Also:
Constant Field Values

GREATER_THAN

public static final int GREATER_THAN
The value used to indicate a GREATER_THAN type of comparison

See Also:
Constant Field Values
Constructor Detail

DataBaseEngine

public DataBaseEngine()
Creates a new instance of DataBaseEngine

Method Detail

addTable

public void addTable(java.lang.String tableName,
                     java.lang.String[] Fields,
                     java.lang.String[] Type)
Adds a DB_Table into the database engine

Parameters:
tableName - The name associated to this table
Fields - The properties of the registers in the table
Type - The type of register see DB_Table for details

addData

public void addData(java.lang.String tableName,
                    java.lang.String RegisterIndex,
                    java.lang.Object[] Values)
Adds an entry to one of the tables

Parameters:
tableName - The name associated to this table
RegisterIndex - A unique identifier for the register
Values - The Values to be assigned. Note: Values need to be in the same order than the Fields variable when the table was created

addData

public void addData(java.lang.String tableName,
                    java.lang.String RegisterIndex,
                    DB_Register Field)
Adds an entry to one of the tables

Parameters:
tableName - The name associated to this table
Field - The DB_Register to add
RegisterIndex - A unique identifier for the register

getRegisterByMainIndex

public DB_Register getRegisterByMainIndex(java.lang.String tableName,
                                          java.lang.Object ValueToMatch)
Returns a DB_Register whose main index matches a predetermined keyword in a specific table

Parameters:
tableName - The name associated to this table
ValueToMatch - The keyword to be matched
Returns:
The DB_Register found or null value

findRegister

public DB_Register[] findRegister(java.lang.String tableName,
                                  java.lang.String[] FieldName,
                                  java.lang.Object[] ValueToMatch)
Finds registers in a table that match a set of values criteria in several of its properties (e.g. in a gazetteer find all the "cities" that are in "colorado")

Parameters:
tableName - The name associated to this table
FieldName - The properties to match
ValueToMatch - The values to match
Returns:
The gruop of registers that match the imposed criteria

compareFieldsTo

public DB_Register[] compareFieldsTo(java.lang.String tableName,
                                     java.lang.String[] FieldName,
                                     java.lang.Object[] ValueToCompare,
                                     int[] ConditionToCheckFor)
A more general search for registers in a table. It compares registers with a a set of criteria in several of its properties. The criteria are:

0: equal to

-1: smaller than

1: greater than

Parameters:
tableName - The name associated to this table
FieldName - The properties to match
ValueToCompare - The values used as reference
ConditionToCheckFor - The conditions to apply to the reference value
Returns:
The gruop of registers that match the imposed criteria

getUniqueValues

public java.util.Vector getUniqueValues(java.lang.String tableName,
                                        java.lang.String FieldName)
Returns a vector of Objects with unique values for a given property

Parameters:
tableName - The name associated to this table
FieldName - The property to query
Returns:
The vector of unique values. For "Numeric" type properties a int[] is returned where int[0] is the minimum value and int[1] is the maximum value

getMaxValue

public java.lang.Double getMaxValue(java.lang.String tableName,
                                    java.lang.String FieldName)
Returns the maximum value for a given "Numeric" Property in a given table

Parameters:
tableName - The name associated to this table
FieldName - The property to query
Returns:
The maximum value

getMinValue

public java.lang.Double getMinValue(java.lang.String tableName,
                                    java.lang.String FieldName)
Returns the minimum value for a given "Numeric" Property in a given table

Parameters:
tableName - The name associated to this table
FieldName - The property to query
Returns:
The minimum value

main

public static void main(java.lang.String[] args)
An extensive test for the Database engine

Parameters:
args - the command line arguments


CUENCAS was initially developed by Ricardo Mantilla at the University of Colorado under the supervision of Dr. Vijay K. Gupta. We wish to recognize the support from the National Science Fundation.