public class SQLMap extends Object
Modifier and Type | Class and Description |
---|---|
class |
SQLMap.SelectBuilder
Used to build the where statement as a builder pattern
|
static class |
SQLMap.SqlType |
Modifier and Type | Method and Description |
---|---|
static SQLMap |
create(Database db)
Creates an SQL Map instance to the given database instance
|
boolean |
createTable(PropertyBusinessObject cmp)
Creates a table matching the given property component if one doesn't exist yet
|
void |
delete(PropertyBusinessObject cmp)
Deletes a table row matching the component
|
void |
dropTable(PropertyBusinessObject cmp)
Drop a table matching the given property component
|
String |
getColumnName(PropertyBase prop)
By default the column name matches the property name unless explicitly modified with this method
|
SQLMap.SqlType |
getSqlType(PropertyBase p)
Returns the SQL type for the given column
|
String |
getTableName(PropertyBusinessObject cmp)
By default the table name matches the property index name unless explicitly modified with this method
|
void |
insert(PropertyBusinessObject cmp)
Adds a new business object into the database
|
List<PropertyBusinessObject> |
select(PropertyBusinessObject cmp,
Property orderBy,
boolean ascending,
int maxElements,
int page)
Fetches the components from the database matching the given cmp description, the fields that aren't
null within the cmp will match the where clause
|
SQLMap.SelectBuilder |
selectBuild()
Fetches the components from the database matching the given select builder query
|
List<PropertyBusinessObject> |
selectNot(PropertyBusinessObject cmp,
Property orderBy,
boolean ascending,
int maxElements,
int page)
Fetches 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
|
void |
setColumnName(PropertyBase prop,
String name)
By default the column name matches the property name unless explicitly modified with this method
|
void |
setPrimaryKey(PropertyBusinessObject cmp,
Property pk)
Sets the primary key for the component
|
void |
setPrimaryKeyAutoIncrement(PropertyBusinessObject cmp,
Property pk)
Sets the primary key for the component and makes it auto-increment
|
void |
setSqlType(PropertyBase p,
SQLMap.SqlType type)
Sets the sql type for the column
|
void |
setTableName(PropertyBusinessObject cmp,
String name)
By default the table name matches the property index name unless explicitly modified with this method
|
void |
setVerbose(boolean verbose)
Toggle verbose mode
|
void |
update(PropertyBusinessObject cmp)
The equivalent of an SQL update assumes that the object is already in the database
|
public static SQLMap create(Database db)
db
- the database connection instancepublic void setPrimaryKey(PropertyBusinessObject cmp, Property pk)
cmp
- the business objectpk
- the primary key fieldpublic void setPrimaryKeyAutoIncrement(PropertyBusinessObject cmp, Property pk)
cmp
- the business objectpk
- the primary key fieldpublic void setSqlType(PropertyBase p, SQLMap.SqlType type)
p
- the propertytype
- one of the enum values representing supported SQL data typespublic SQLMap.SqlType getSqlType(PropertyBase p)
p
- the propertypublic void setTableName(PropertyBusinessObject cmp, String name)
cmp
- the properties business objectname
- the name of the tablepublic String getTableName(PropertyBusinessObject cmp)
cmp
- the properties business objectpublic void setColumnName(PropertyBase prop, String name)
prop
- a property instance, this will apply to all the property instances for the typename
- the name of the columnpublic String getColumnName(PropertyBase prop)
prop
- a property instance, this will apply to all the property instances for the typepublic boolean createTable(PropertyBusinessObject cmp) throws IOException
cmp
- the business objectIOException
public void dropTable(PropertyBusinessObject cmp) throws IOException
cmp
- the business objectIOException
public void insert(PropertyBusinessObject cmp) throws IOException
cmp
- the business componentIOException
public void update(PropertyBusinessObject cmp) throws IOException
cmp
- the componentIOException
public void delete(PropertyBusinessObject cmp) throws IOException
cmp
- the componentIOException
public List<PropertyBusinessObject> select(PropertyBusinessObject cmp, Property orderBy, boolean ascending, int maxElements, int page) throws IOException, InstantiationException
cmp
- the component to matchorderBy
- the column to order by, can be null to ignore orderascending
- true to indicate ascending ordermaxElements
- the maximum number of elements returned can be 0 or lower to ignorepage
- the page within the query to match the max elements valueIOException
InstantiationException
public List<PropertyBusinessObject> selectNot(PropertyBusinessObject cmp, Property orderBy, boolean ascending, int maxElements, int page) throws IOException, InstantiationException
cmp
- the component to matchorderBy
- the column to order by, can be null to ignore orderascending
- true to indicate ascending ordermaxElements
- the maximum number of elements returned can be 0 or lower to ignorepage
- the page within the query to match the max elements valueIOException
InstantiationException
public SQLMap.SelectBuilder selectBuild()
public void setVerbose(boolean verbose)
verbose
-