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.
  • 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