public final class SQLMap
- Object
- SQLMap
A simple ORM wrapper for property objects. This is a very poor mans ORM that doesn’t handle relations
properly at this time.
Nested types
enum SQLMap.SqlType | |
class SQLMap.SelectBuilder | Used to build the where statement as a builder pattern |
Methods
Inherited methods
Method details
create
public static SQLMap create(Database db)Creates an SQL Map instance to the given database instance
Parameters
dbDatabase- the database connection instance
Returns
an instance of the SQL mapping
setPrimaryKey
public void setPrimaryKey(PropertyBusinessObject cmp, Property pk)Sets the primary key for the component
Parameters
cmpPropertyBusinessObject- the business object
pkProperty- the primary key field
setPrimaryKeyAutoIncrement
public void setPrimaryKeyAutoIncrement(PropertyBusinessObject cmp, Property pk)Sets the primary key for the component and makes it auto-increment
Parameters
cmpPropertyBusinessObject- the business object
pkProperty- the primary key field
setSqlType
public void setSqlType(PropertyBase p, SQLMap.SqlType type)Sets the sql type for the column
Parameters
pPropertyBase- the property
typeSQLMap.SqlType- one of the enum values representing supported SQL data types
getSqlType
public SQLMap.SqlType getSqlType(PropertyBase p)Returns the SQL type for the given column
Parameters
pPropertyBase- the property
Returns
the sql data type
setTableName
public void setTableName(PropertyBusinessObject cmp, String name)By default the table name matches the property index name unless explicitly modified with this method
Parameters
cmpPropertyBusinessObject- the properties business object
nameString- the name of the table
getTableName
public String getTableName(PropertyBusinessObject cmp)By default the table name matches the property index name unless explicitly modified with this method
Parameters
cmpPropertyBusinessObject- the properties business object
Returns
the name of the table
setColumnName
public void setColumnName(PropertyBase prop, String name)By default the column name matches the property name unless explicitly modified with this method
Parameters
propPropertyBase- a property instance, this will apply to all the property instances for the type
nameString- the name of the column
getColumnName
public String getColumnName(PropertyBase prop)By default the column name matches the property name unless explicitly modified with this method
Parameters
propPropertyBase- a property instance, this will apply to all the property instances for the type
Returns
the name of the property
createTable
public boolean createTable(PropertyBusinessObject cmp)
throws IOExceptionCreates a table matching the given property component if one doesn’t exist yet
Parameters
cmpPropertyBusinessObject- the business object
Returns
true if the table was created false if it already existed
Throws
dropTable
public void dropTable(PropertyBusinessObject cmp)
throws IOExceptionDrop a table matching the given property component
Parameters
cmpPropertyBusinessObject- the business object
Throws
insert
public void insert(PropertyBusinessObject cmp)
throws IOExceptionAdds a new business object into the database
Parameters
cmpPropertyBusinessObject- the business component
Throws
update
public void update(PropertyBusinessObject cmp)
throws IOExceptionThe equivalent of an SQL update assumes that the object is already in the database
Parameters
cmpPropertyBusinessObject- the component
Throws
delete
public void delete(PropertyBusinessObject cmp)
throws IOExceptionDeletes a table row matching the component
Parameters
cmpPropertyBusinessObject- the component
Throws
select
public List<PropertyBusinessObject> select(PropertyBusinessObject cmp, Property orderBy, boolean ascending, int maxElements, int page)
throws IOException, InstantiationExceptionFetches the components from the database matching the given cmp description, the fields that aren’t
null within the cmp will match the where clause
Parameters
cmpPropertyBusinessObject- the component to match
orderByProperty- the column to order by, can be null to ignore order
ascendingboolean- true to indicate ascending order
maxElementsint- the maximum number of elements returned can be 0 or lower to ignore
pageint- the page within the query to match the max elements value
Returns
the result of the query
selectNot
public List<PropertyBusinessObject> selectNot(PropertyBusinessObject cmp, Property orderBy, boolean ascending, int maxElements, int page)
throws IOException, InstantiationExceptionFetches the components from the database matching the given cmp description, the fields that aren’t
null within the cmp will NOT match the where clause
Parameters
cmpPropertyBusinessObject- the component to match
orderByProperty- the column to order by, can be null to ignore order
ascendingboolean- true to indicate ascending order
maxElementsint- the maximum number of elements returned can be 0 or lower to ignore
pageint- the page within the query to match the max elements value
Returns
the result of the query
selectBuild
public SQLMap.SelectBuilder selectBuild()Fetches the components from the database matching the given select builder query
Returns
the result of the query
setVerbose
public void setVerbose(boolean verbose)Toggle verbose mode