org.lambico.test.spring.hibernate
Class FixtureHelper

java.lang.Object
  extended by org.lambico.test.spring.hibernate.FixtureHelper

public class FixtureHelper
extends java.lang.Object

Author:
Paolo Dona paolo.dona@seesaw.it, Michele Franzin michele.franzin@seesaw.it

Constructor Summary
protected FixtureHelper()
          A default protected constructor.
 
Method Summary
static void eraseDbForModel(java.lang.Class model, GenericDaoBase dao)
          Erase the DB for a model.
static java.lang.String getFixtureBusinessDaoId(java.lang.Class model)
          Gets id of dao related to a model.
static java.lang.String getFixtureDaoId(java.lang.Class model)
          Gets id of dao related to a model.
static java.lang.String getFixtureFileName(java.lang.Class model)
          Gets file name of a fixture fragment related to a model.
static java.lang.String getModelName(java.lang.Class model)
          Gets human readable name of a model.
static java.util.Map<java.lang.Class,java.lang.Object[]> loadFixturesFromResource(org.springframework.core.io.ClassPathResource fixtureDir, java.util.Set<java.lang.Class> models)
          Load the fixtures.
static java.util.Map<java.lang.Class,java.lang.Object[]> loadFixturesFromResource(java.lang.String classpathResource, java.util.Set<java.lang.Class> models)
          Load the fixtures.
static void populateDbForModel(java.lang.Class model, java.lang.Object[] fixtures, GenericDaoBase dao)
          Populate the DB with the fixtures data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixtureHelper

protected FixtureHelper()
A default protected constructor.

Method Detail

getFixtureFileName

public static java.lang.String getFixtureFileName(java.lang.Class model)
Gets file name of a fixture fragment related to a model.

Parameters:
model - The class of a model.
Returns:
The fixture file name.

getFixtureDaoId

public static java.lang.String getFixtureDaoId(java.lang.Class model)
Gets id of dao related to a model.

*WARNING*: strong condition on the DAO id (entity_name+Dao) For retriving a dao for an entity it's better something like: DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID); GenericDao dao = (GenericDao)daos.getDao(clazz);

The DAO_PROVIDER_ID usually is "daos".

Parameters:
model - The class of a model.
Returns:
The DAO id.

getFixtureBusinessDaoId

public static java.lang.String getFixtureBusinessDaoId(java.lang.Class model)
Gets id of dao related to a model.

*WARNING*: strong condition on the DAO id (entity_name+Dao) For retriving a dao for an entity it's better something like: DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID); GenericDao dao = (GenericDao)daos.getDao(clazz);

The DAO_PROVIDER_ID usually is "daos".

Parameters:
model - The class of a model.
Returns:
The business DAO id.

getModelName

public static java.lang.String getModelName(java.lang.Class model)
Gets human readable name of a model.

Parameters:
model - The class of a model.
Returns:
The model name.

loadFixturesFromResource

public static java.util.Map<java.lang.Class,java.lang.Object[]> loadFixturesFromResource(java.lang.String classpathResource,
                                                                                         java.util.Set<java.lang.Class> models)
Load the fixtures.

Parameters:
classpathResource - dir relative path
models - The set of models.
Returns:
The model->values map of fixtures.

loadFixturesFromResource

public static java.util.Map<java.lang.Class,java.lang.Object[]> loadFixturesFromResource(org.springframework.core.io.ClassPathResource fixtureDir,
                                                                                         java.util.Set<java.lang.Class> models)
Load the fixtures.

Parameters:
fixtureDir - The directory where to search the fixtures.
models - The set of models.
Returns:
The model->values map of fixtures.

populateDbForModel

public static void populateDbForModel(java.lang.Class model,
                                      java.lang.Object[] fixtures,
                                      GenericDaoBase dao)
Populate the DB with the fixtures data.

Parameters:
model - The model to populate.
fixtures - The fixtures.
dao - The DAO to use.

eraseDbForModel

public static void eraseDbForModel(java.lang.Class model,
                                   GenericDaoBase dao)
Erase the DB for a model.

Parameters:
model - The model to erase.
dao - The DAO tp use.


Copyright © 2009-2010 Lambico Team. All Rights Reserved.