com.scooterframework.orm.activerecord
Class Calculator

java.lang.Object
  extended by com.scooterframework.orm.activerecord.Calculator

public class Calculator
extends java.lang.Object

Calculator class contains basic calculation methods for an entity.


Field Summary
protected  ActiveRecord recHome
          record home instance.
 
Method Summary
 java.lang.Object average(java.lang.String field)
          Calculates average of a field.
 java.lang.Object average(java.lang.String field, java.lang.String options)
          Calculates average of a field.
static java.lang.Object calculate(ActiveRecord recordHome, java.lang.String function, java.lang.String field, java.util.Map<java.lang.String,java.lang.String> options)
          Calculates by a function on a field.
static java.lang.Object calculate(ActiveRecord recordHome, java.lang.String function, java.lang.String field, java.lang.String options)
          Calculates by a function on a field.
 java.lang.Object calculate(java.lang.String function, java.lang.String field, java.lang.String options)
          Calculates by a function on a field.
 long count()
          Counts number of records.
 long count(java.lang.String field)
          Counts number of records for a field.
 long count(java.lang.String field, java.lang.String options)
          Counts number of records for a field.
static Calculator getCalculator(java.lang.Class<? extends ActiveRecord> modelClass)
          Gets a calculator for a model.
static java.lang.String getCountSelectPart(ActiveRecord recordHome, java.util.Map<java.lang.String,java.lang.String> properties)
          Returns a SQL fragment for count.
 java.lang.Object maximum(java.lang.String field)
          Calculates maximum of a field.
 java.lang.Object maximum(java.lang.String field, java.lang.String options)
          Calculates maximum of a field.
 java.lang.Object minium(java.lang.String field)
          Calculates minimum of a field.
 java.lang.Object minium(java.lang.String field, java.lang.String options)
          Calculates minmum of a field.
 java.lang.Object sum(java.lang.String field)
          Calculates sum of a field.
 java.lang.Object sum(java.lang.String field, java.lang.String options)
          Calculates sum of a field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

recHome

protected ActiveRecord recHome

record home instance.

Method Detail

getCalculator

public static Calculator getCalculator(java.lang.Class<? extends ActiveRecord> modelClass)

Gets a calculator for a model.

Parameters:
modelClass - the model class

count

public long count()
Counts number of records.

Returns:
number of records.

count

public long count(java.lang.String field)
Counts number of records for a field.

Parameters:
field - name of the field
Returns:
number of records.

count

public long count(java.lang.String field,
                  java.lang.String options)
Counts number of records for a field.

Parameters:
field - name of the field
options - options for calculation
Returns:
number of records.

sum

public java.lang.Object sum(java.lang.String field)
Calculates sum of a field.

Parameters:
field - the column name
Returns:
result of calculation

sum

public java.lang.Object sum(java.lang.String field,
                            java.lang.String options)
Calculates sum of a field.

Parameters:
field - the column name
options - options of calculation
Returns:
result of calculation

average

public java.lang.Object average(java.lang.String field)
Calculates average of a field.

Parameters:
field - the column name
Returns:
result of calculation

average

public java.lang.Object average(java.lang.String field,
                                java.lang.String options)
Calculates average of a field.

Parameters:
field - the column name
options - options of calculation
Returns:
result of calculation

maximum

public java.lang.Object maximum(java.lang.String field)
Calculates maximum of a field.

Parameters:
field - the column name
Returns:
result of calculation

maximum

public java.lang.Object maximum(java.lang.String field,
                                java.lang.String options)
Calculates maximum of a field.

Parameters:
field - the column name
options - options of calculation
Returns:
result of calculation

minium

public java.lang.Object minium(java.lang.String field)
Calculates minimum of a field.

Parameters:
field - the column name
Returns:
result of calculation

minium

public java.lang.Object minium(java.lang.String field,
                               java.lang.String options)
Calculates minmum of a field.

Parameters:
field - the column name
options - options of calculation
Returns:
result of calculation

calculate

public java.lang.Object calculate(java.lang.String function,
                                  java.lang.String field,
                                  java.lang.String options)
Calculates by a function on a field.

Parameters:
function - the SQL function name
field - the column name
options - options of calculation
Returns:
result of calculation

calculate

public static java.lang.Object calculate(ActiveRecord recordHome,
                                         java.lang.String function,
                                         java.lang.String field,
                                         java.lang.String options)
Calculates by a function on a field.

Parameters:
recordHome - home instance of an entity
function - the SQL function name
field - the column name
options - options of calculation
Returns:
result of calculation

calculate

public static java.lang.Object calculate(ActiveRecord recordHome,
                                         java.lang.String function,
                                         java.lang.String field,
                                         java.util.Map<java.lang.String,java.lang.String> options)
Calculates by a function on a field.

Parameters:
recordHome - home instance of an entity
function - the SQL function name
field - the column name
options - options of calculation
Returns:
result of calculation

getCountSelectPart

public static java.lang.String getCountSelectPart(ActiveRecord recordHome,
                                                  java.util.Map<java.lang.String,java.lang.String> properties)
Returns a SQL fragment for count.

Parameters:
recordHome - home instance of an entity
properties - properties of SQL query
Returns:
a SQL fragment for count