public final class SQLMap

  1. Object
  2. 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.SelectBuilderUsed to build the where statement as a builder pattern

Methods

public static SQLMap create(Database db)Creates an SQL Map instance to the given database instance
public void setPrimaryKey(PropertyBusinessObject cmp, Property pk)Sets the primary key for the component
public void setPrimaryKeyAutoIncrement(PropertyBusinessObject cmp, Property pk)Sets the primary key for the component and makes it auto-increment
public void setSqlType(PropertyBase p, SQLMap.SqlType type)Sets the sql type for the column
public SQLMap.SqlType getSqlType(PropertyBase p)Returns the SQL type for the given column
public void setTableName(PropertyBusinessObject cmp, String name)By default the table name matches the property index name unless explicitly modified with this method
public String getTableName(PropertyBusinessObject cmp)By default the table name matches the property index name unless explicitly modified with this method
public void setColumnName(PropertyBase prop, String name)By default the column name matches the property name unless explicitly modified with this method
public String getColumnName(PropertyBase prop)By default the column name matches the property name unless explicitly modified with this method
public boolean createTable(PropertyBusinessObject cmp) throws IOExceptionCreates a table matching the given property component if one doesn’t exist yet
public void dropTable(PropertyBusinessObject cmp) throws IOExceptionDrop a table matching the given property component
public void insert(PropertyBusinessObject cmp) throws IOExceptionAdds a new business object into the database
public void update(PropertyBusinessObject cmp) throws IOExceptionThe equivalent of an SQL update assumes that the object is already in the database
public void delete(PropertyBusinessObject cmp) throws IOExceptionDeletes a table row matching the component
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
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
public SQLMap.SelectBuilder selectBuild()Fetches the components from the database matching the given select builder query
public void setVerbose(boolean verbose)Toggle verbose mode

Inherited methods

Method details

create

public static SQLMap create(Database db)
Creates an SQL Map instance to the given database instance

Parameters

db Database
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

cmp PropertyBusinessObject
the business object
pk Property
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

cmp PropertyBusinessObject
the business object
pk Property
the primary key field

setSqlType

public void setSqlType(PropertyBase p, SQLMap.SqlType type)
Sets the sql type for the column

Parameters

p PropertyBase
the property
type SQLMap.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

p PropertyBase
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

cmp PropertyBusinessObject
the properties business object
name String
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

cmp PropertyBusinessObject
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

prop PropertyBase
a property instance, this will apply to all the property instances for the type
name String
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

prop PropertyBase
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 IOException
Creates a table matching the given property component if one doesn’t exist yet

Parameters

cmp PropertyBusinessObject
the business object

Returns

true if the table was created false if it already existed

dropTable

public void dropTable(PropertyBusinessObject cmp) throws IOException
Drop a table matching the given property component

Parameters

cmp PropertyBusinessObject
the business object

insert

public void insert(PropertyBusinessObject cmp) throws IOException
Adds a new business object into the database

Parameters

cmp PropertyBusinessObject
the business component

update

public void update(PropertyBusinessObject cmp) throws IOException
The equivalent of an SQL update assumes that the object is already in the database

Parameters

cmp PropertyBusinessObject
the component

delete

public void delete(PropertyBusinessObject cmp) throws IOException
Deletes a table row matching the component

Parameters

cmp PropertyBusinessObject
the component

select

public List<PropertyBusinessObject> select(PropertyBusinessObject cmp, Property orderBy, boolean ascending, int maxElements, int page) throws IOException, InstantiationException
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

Parameters

cmp PropertyBusinessObject
the component to match
orderBy Property
the column to order by, can be null to ignore order
ascending boolean
true to indicate ascending order
maxElements int
the maximum number of elements returned can be 0 or lower to ignore
page int
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, InstantiationException
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

Parameters

cmp PropertyBusinessObject
the component to match
orderBy Property
the column to order by, can be null to ignore order
ascending boolean
true to indicate ascending order
maxElements int
the maximum number of elements returned can be 0 or lower to ignore
page int
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