org.tentackle.pdo.PdoFactory Maven / Gradle / Ivy
/*
* Tentackle - https://tentackle.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.tentackle.pdo;
import org.tentackle.common.ServiceFactory;
import org.tentackle.reflect.ClassMapper;
import org.tentackle.session.Session;
interface PdoFactoryHolder {
PdoFactory INSTANCE = ServiceFactory.createService(PdoFactory.class, DefaultPdoFactory.class);
}
/**
* A factory for persistent domain objects.
*
* @author harald
*/
public interface PdoFactory {
/**
* The singleton.
*
* @return the singleton
*/
static PdoFactory getInstance() {
return PdoFactoryHolder.INSTANCE;
}
/**
* Gets the persistence class mapper associated to this factory.
* The classmapper maps PDO interfaces to their persistence implementation.
*
* @return the mapper for the persistence implementations
*/
ClassMapper getPersistenceMapper();
/**
* Gets the domain class mapper associated to this factory.
* The classmapper maps PDO interfaces to their domain implementation.
*
* @return the mapper for the domain implementations
*/
ClassMapper getDomainMapper();
/**
* Creates a PDO.
*
* @param the PDO type
* @param clazz the class of the PDO, usually an interface
* @param context the domain context
* @return the created PDO
*/
> T create(Class clazz, DomainContext context);
/**
* Creates a PDO.
*
* @param the PDO type
* @param clazz the class of the PDO, usually an interface
* @param session the session
* @return the created PDO
*/
> T create(Class clazz, Session session);
/**
* Creates a PDO.
*
* @param the PDO type
* @param className the name of PDO-class, usually an interface
* @param context the domain context
* @return the created PDO
*/
> T create(String className, DomainContext context);
/**
* Creates a PDO for a session only.
*
* Note: the application must set the context.
*
* @param the PDO type
* @param className the name of PDO-class, usually an interface
* @param session the session
* @return the created PDO
*/
> T create(String className, Session session);
/**
* Creates a PDO without any domain context or session.
*
* Note: the application must set the context.
*
* @param the PDO type
* @param clazz the class of the PDO, usually an interface
* @return the created PDO
*/
> T create(Class clazz);
/**
* Creates a PDO without any domain context or session.
*
* Note: the application must set the context.
*
* @param the PDO type
* @param className the name of PDO-class, usually an interface
* @return the created PDO
*/
> T create(String className);
/**
* Creates a PDO.
*
* @param the PDO type
* @param pdo the PDO
* @return the created PDO belonging to the same class as the given {@code pdo} and in same context.
*/
> T create(T pdo);
/**
* Creates a PDO within a sub context.
* If the current context is already within the given context name, the result is equivalent
* to {@link #create(PersistentDomainObject)}.
*
* @param the PDO type
* @param pdo the PDO
* @param contextName the context name
* @return the created PDO belonging to the same class as the given {@code pdo} in a sub context of given name
*/
> T create(T pdo, String contextName);
/**
* Creates a PDO for a given persistence delegate.
*
* @param the PDO type
* @param clazz the class of the PDO, usually an interface
* @param persistenceDelegate the persistence delegate
* @return the created PDO
*/
> T create(Class clazz, PersistentObject persistenceDelegate);
/**
* Creates a PDO for a given persistence delegate.
*
* @param the PDO type
* @param className the name of PDO-class, usually an interface
* @param persistenceDelegate the persistence delegate
* @return the created PDO
*/
> T create(String className, PersistentObject persistenceDelegate);
/**
* Creates a PDO for a given domain delegate.
*
* @param the PDO type
* @param clazz the class of the PDO, usually an interface
* @param context the domain context
* @param domainDelegate the domain delegate
* @return the created PDO
*/
> T create(Class clazz, DomainContext context, DomainObject domainDelegate);
/**
* Creates a PDO for a given domain delegate.
*
* @param the PDO type
* @param className the name of PDO-class, usually an interface
* @param context the domain context
* @param domainDelegate the domain delegate
* @return the created PDO
*/
> T create(String className, DomainContext context, DomainObject domainDelegate);
/**
* Creates a PDO for a given domain delegate.
*
* @param the PDO type
* @param clazz the class of the PDO, usually an interface
* @param session the session
* @param domainDelegate the domain delegate
* @return the created PDO
*/
> T create(Class clazz, Session session, DomainObject domainDelegate);
/**
* Creates a PDO for a given domain delegate.
*
* @param the PDO type
* @param className the name of PDO-class, usually an interface
* @param session the session
* @param domainDelegate the domain delegate
* @return the created PDO
*/
> T create(String className, Session session, DomainObject domainDelegate);
/**
* Creates a PDO for given delegates.
*
* @param the PDO type
* @param clazz the class of the PDO, usually an interface
* @param persistenceDelegate the persistence delegate
* @param domainDelegate the domain delegate
* @return the created PDO
*/
> T create(Class clazz, PersistentObject persistenceDelegate,
DomainObject domainDelegate);
/**
* Creates a PDO for given delegates.
*
* @param the PDO type
* @param className the name of PDO-class, usually an interface
* @param persistenceDelegate the persistence delegate
* @param domainDelegate the domain delegate
* @return the created PDO
*/
> T create(String className, PersistentObject persistenceDelegate,
DomainObject domainDelegate);
/**
* Gets the class implementing the persistence layer.
*
* @param the PDO type
* @param className the name of PDO-class, usually an interface
* @return the persistence class
*/
> Class> getPersistenceClass(String className);
/**
* Gets the class implementing the domain layer.
*
* @param the PDO type
* @param className the name of PDO-class, usually an interface
* @return the domain class
*/
> Class> getDomainClass(String className);
/**
* Creates the delegate implementing the persistence layer.
*
* @param the PDO type
* @param className the name of PDO-class, usually an interface
* @return the persistent delegate
*/
> PersistentObject createPersistenceDelegate(String className);
/**
* Creates the delegate implementing the domain layer.
*
* @param the PDO type
* @param className the name of PDO-class, usually an interface
* @return the domain delegate
*/
> DomainObject createDomainDelegate(String className);
}