|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.toften.jlips.persist.EntityFactory
public final class EntityFactory
Java Lightweight Interface Persistence System (jlips) Factory. This factory is the main interface towards the application. It is responsible for creating and finding objects specified by the interfaces. To use the factory an interface needs to be created, specifing the accessor methods for the fields in the database table. All methods in this factory returns an object of the type Object. However this object can (and must) be typecasted to the type of the interface specifying the accessor methods.
Field Summary | |
---|---|
static String |
EF_DB_CON_HAND
String used to specify the name of the database connection handler in the properties passed to jlips when it is initialised |
static String |
EF_DB_PROP_HAND
String used to specify the name of the database connection properties in the properties passed to jlips when it is initialised |
static String |
EF_DB_STM_HAND
String used to specify the name of the SQL statement creater class. |
Method Summary | |
---|---|
static Object |
create(Class theEntity)
Creates a new row in the database. |
static Object |
find(Class theEntity,
Object key)
Finds a row in the database given a primary key. |
static Collection |
findAll(Class theEntity)
This method will return all the records in the table mapped to the persist entity provided |
static String |
getEntityName(Class theEntity)
Returns the name of the interface class given. |
static void |
init(DBProperties dbProps,
Map tableMap)
|
static void |
init(Properties dbProps,
Map tableMap)
Initializes the persistence system. |
static Collection |
search(Class theEntity,
String query,
Object[] args)
Runs a predefined query. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String EF_DB_CON_HAND
DBConnectionHandler
,
Constant Field Valuespublic static final String EF_DB_PROP_HAND
DBProperties
,
Constant Field Valuespublic static final String EF_DB_STM_HAND
DBDefaultStatement
class will be used.
DBStatement
,
Constant Field ValuesMethod Detail |
---|
public static void init(Properties dbProps, Map tableMap)
init
method takes.
dbProps
takes two
properties. These properties are the full class path to the classes
that implements the connection information retrieval and the database connection
handler.
The dbProps
parameter is a Properties
Object
containing two elements. Example:
connection.handler=net.toften.jlips.persist.db.DBPooledConnection properties.handler=net.toften.jlips.persist.db.DBHardPropertiesThe properties describe which classes jLips should use to manage database connections and to retreive connection information. When jLips initialise the database connection factory, it will instantiate one object of each of these classes. The
connection.handler
must implement the interface
DBConnectionHandler
and the
properties.handler
must implement the interface
DBProperties
interface.
dbProps
- Properties that describe the database connection detailstableMap
- Map describing the mapping between the persist entities
and the database tablespublic static void init(DBProperties dbProps, Map tableMap)
public static Object create(Class theEntity)
Person p = (Person)EntityFactory.create(Person.class); p.setName("Thomas"); p.commit();The code above will create a new record using the Person persist entity and set the field
name
to "Thomas".
The last line commits the changes to the database.
theEntity
- The class of the interface specifying the accessor
methods
public static Object find(Class theEntity, Object key)
theEntity
- The class of the interface specifying the accessor
methodskey
- The primary key of the record to be found
public static String getEntityName(Class theEntity)
theEntity
- The class of the interface specifying the accessor
methods
public static Collection search(Class theEntity, String query, Object[] args)
queries
. This array is a two dimentional array
in the following format:
public static final String queries[][] = { { "findByFirstName", "firstname = ?" }, { "findByLastName", "lastname = ?" } };Where the first element is the name of the query passed to this method in the query parameter. The second element is the WHERE part of the SQL query. In this part every
?
will be replaces with the
corosponding element in the args
array, i.e. the first
?
will be replaced with args[0]
and so forth.
The query will return a Collection that contains all the records that matches
the search. If no matches were found an empty Collection is returned.
theEntity
- The persist entity containing the searchquery
- args
- Array of arguments to be passed into the query
SearchCollectionEntityHandler
public static Collection findAll(Class theEntity)
theEntity
- The entity for which all records is requested
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |