|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jzeno.tests.Populator
public class Populator
Populator is a helper class for facilitating the creation of test enitities.
Constructor Summary | |
---|---|
Populator()
|
Method Summary | |
---|---|
void |
clear()
Removes all objects ever created, or enlisted on this populator. |
java.lang.Object |
create(java.lang.Class clazz)
Creates a new entity in the database, and fills in all primitive properties. |
java.lang.Object |
create(java.lang.Class clazz,
java.lang.String prefix)
Creates a new entity in the database, and fills in all primitive properties. |
void |
delete(java.lang.Object o)
Removes the indicated object from the database. |
void |
end()
Ends the started transaction. |
java.lang.Object[] |
executeQuery(java.lang.String query)
Executes a given HQL query |
java.lang.Object[] |
executeQuery(java.lang.String query,
java.lang.String paramName,
java.lang.Object paramValue)
Executes a given HQL query |
java.lang.Object |
find(java.lang.Class clazz)
|
java.lang.Object[] |
find(java.lang.Class clazz,
int howMany)
|
java.lang.Object |
find(java.lang.String className)
|
java.lang.Object[] |
find(java.lang.String className,
int howMany)
Retrieves a number of objects of the specified type. |
java.util.List |
findAll(java.lang.Class clazz)
|
java.util.List |
findAll(java.lang.String className)
Retrieves ALL available objects of the given type. |
java.lang.String |
getRandomNumericString(int length)
This operation generates random strings of given length. |
Session |
getSession()
Convenience function to retrieve the current session. |
boolean |
isAutoCreate()
|
Entity |
load(Entity outOfSessionObject)
Loads a fresh copy of the given object from the DB. |
void |
rollback()
Rolls back the started transaction. |
void |
save(java.lang.Object o)
|
void |
setAutoCreate(boolean autoCreate)
|
Session |
start()
Starts a new transaction. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Populator()
Method Detail |
---|
public java.lang.Object create(java.lang.Class clazz)
Creates a new entity in the database, and fills in all primitive properties. Strings are filled in with "Anonymous", a sequence number (unique to the instance of the populator), a dot and the name of the property itself. Numbers are filled in with a random value between 0 and 10000. Booleans are set to false, and the object returned is associated with the Active status object. This method assumes such a Active status object exists beforehand. Date attributes are set to the Date/Time of creation.
public java.lang.Object create(java.lang.Class clazz, java.lang.String prefix)
Creates a new entity in the database, and fills in all primitive properties. Strings are filled in with the prefix specified, a dot and the name of the property itself. Numbers are filled in with a random value between 0 and 10000. Booleans are set to false. Date attributes are set to the Date/Time of creation.
many-to-one relations are by default filled in with a random selected object of the right type. Similar to doing p.find(TypeOfRelation.class) and object.setXYZ(..) yourself.
public Session start()
Starts a new transaction.
public void end()
Ends the started transaction.
public void rollback()
Rolls back the started transaction.
public void clear()
Removes all objects ever created, or enlisted on this populator. This operation can work in an existing transaction, or will create a transaction of its own when no transaction is available. If a transaction is created, it will also close that temporary transaction.
public java.lang.Object[] find(java.lang.String className, int howMany)
Retrieves a number of objects of the specified type. Useful for when you need some marginal entity for you test entities, but it's not relay important which specific instance gets used.
public java.util.List findAll(java.lang.String className)
Retrieves ALL available objects of the given type.
public java.util.List findAll(java.lang.Class clazz)
public java.lang.Object find(java.lang.Class clazz)
public java.lang.Object[] find(java.lang.Class clazz, int howMany)
public java.lang.Object find(java.lang.String className)
public java.lang.Object[] executeQuery(java.lang.String query)
Executes a given HQL query
public java.lang.Object[] executeQuery(java.lang.String query, java.lang.String paramName, java.lang.Object paramValue)
Executes a given HQL query
public Session getSession()
Convenience function to retrieve the current session. Handy for doing on the fly queries, etc...
public void save(java.lang.Object o)
public void delete(java.lang.Object o)
Removes the indicated object from the database.
public java.lang.String getRandomNumericString(int length)
This operation generates random strings of given length. It's usefull to mark certain objects in your unit test with a unique indicator.
public Entity load(Entity outOfSessionObject)
Loads a fresh copy of the given object from the DB.
public boolean isAutoCreate()
public void setAutoCreate(boolean autoCreate)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |