# Class SQLMap

java.lang.Object
com.codename1.properties.SQLMap

public final class SQLMap extends Object
A simple ORM wrapper for property objects. This is a very poor mans ORM that doesn't handle relations properly at this time.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `class`
  `SQLMap.SelectBuilder`
  Used to build the where statement as a builder pattern
  `static enum`
  `SQLMap.SqlType`

- ## Method Summary

  Modifier and Type
  Method
  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

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `final Class`
  `getClass()`
  Returns the runtime class of an object.
  `int`
  `hashCode()`
  Returns a hash code value for the object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `String`
  `toString()`
  Returns a string representation of the object.
  `final void`
  `wait()`
  Causes current thread to wait until another thread invokes the method or the method for this object.
  `final void`
  `wait(long timeout)`
  Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
  `final void`
  `wait(long timeout, int nanos)`
  Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

- ## Method Details

  - ### create

    public static SQLMap create(Database db)

    Creates an SQL Map instance to the given database instance

    ###### Parameters

    - `db`: 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`: the business object

    - `pk`: 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`: the business object

    - `pk`: the primary key field

  - ### setSqlType

    public void setSqlType(PropertyBase p, SQLMap.SqlType type)

    Sets the sql type for the column

    ###### Parameters

    - `p`: the property

    - `type`: 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`: 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`: the properties business object

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

    - `name`: 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`: 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`: the business object

    ###### Returns

    true if the table was created false if it already existed

    Throws:
      `IOException`

  - ### dropTable

    public void dropTable(PropertyBusinessObject cmp) throws IOException

    Drop a table matching the given property component

    ###### Parameters

    - `cmp`: the business object
    Throws:
      `IOException`

  - ### insert

    public void insert(PropertyBusinessObject cmp) throws IOException

    Adds a new business object into the database

    ###### Parameters

    - `cmp`: the business component
    Throws:
      `IOException`

  - ### 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`: the component

    ###### Throws

    - `IOException`
    Throws:
      `IOException`

  - ### delete

    public void delete(PropertyBusinessObject cmp) throws IOException

    Deletes a table row matching the component

    ###### Parameters

    - `cmp`: the component
    Throws:
      `IOException`

  - ### 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`: the component to match

    - `orderBy`: the column to order by, can be null to ignore order

    - `ascending`: true to indicate ascending order

    - `maxElements`: the maximum number of elements returned can be 0 or lower to ignore

    - `page`: the page within the query to match the max elements value

    ###### Returns

    the result of the query

    Throws:
      `IOException`
      `InstantiationException`

  - ### 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`: the component to match

    - `orderBy`: the column to order by, can be null to ignore order

    - `ascending`: true to indicate ascending order

    - `maxElements`: the maximum number of elements returned can be 0 or lower to ignore

    - `page`: the page within the query to match the max elements value

    ###### Returns

    the result of the query

    Throws:
      `IOException`
      `InstantiationException`

  - ### 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

    ###### Parameters

    - `verbose`