Class IoC
- java.lang.Object
-
- com.github.collinalpert.java2db.utilities.IoC
-
public class IoC extends java.lang.Object- Author:
- Collin Alpert
A
Inversion of Control
class. It is responsible for registering services, resolving services and administrating default query constraints.
-
-
Constructor Summary
Constructors Constructor Description IoC()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <E extends BaseEntity>
voidaddConstraint(java.lang.Class<E> clazz, SqlPredicate<E> predicate)Adds a query constraint to a query made with a certain entity.<E extends BaseEntity,S extends BaseService<E>>
booleanisRegistered(java.lang.Class<S> clazz)Checks if a service has already been registered.static <E extends BaseEntity,S extends BaseService<E>>
voidregisterService(java.lang.Class<E> clazz, S service)Registers an instance of a service class.static <E> Eresolve(java.lang.Class<E> clazz)Resolves any class.static <E extends BaseEntity,S extends BaseService<E>>
SresolveService(java.lang.Class<S> clazz)Resolves a service class.static <E extends BaseEntity,S extends BaseService<E>>
SresolveServiceByEntity(java.lang.Class<E> clazz)Resolves a service class by the entity it was registered with.
-
-
-
Method Detail
-
resolve
public static <E> E resolve(java.lang.Class<E> clazz)
Resolves any class.- Type Parameters:
E- The type of the entity.- Parameters:
clazz- The class to be constructed.- Returns:
- An instance of this class.
- Throws:
java.lang.IllegalArgumentException- if the class cannot be constructed for any reason. This can occur if there is no public parameterless constructor available.
-
resolveService
public static <E extends BaseEntity,S extends BaseService<E>> S resolveService(java.lang.Class<S> clazz)
Resolves a service class. This is to prevent multiple instances of a service. Only one is needed in the lifecycle of an application.- Type Parameters:
E- The type of the service class's entity.S- The type of the service class.- Parameters:
clazz- The service class to retrieve.- Returns:
- The previously registered instance of a service class.
-
resolveServiceByEntity
public static <E extends BaseEntity,S extends BaseService<E>> S resolveServiceByEntity(java.lang.Class<E> clazz)
Resolves a service class by the entity it was registered with.- Type Parameters:
E- The type of the entity.S- The type of the service.- Parameters:
clazz- The entity class corresponding to a service class.- Returns:
- An instance of a previously registered service class.
-
registerService
public static <E extends BaseEntity,S extends BaseService<E>> void registerService(java.lang.Class<E> clazz, S service)
Registers an instance of a service class.- Type Parameters:
E- The type of the entity.S- The type of the service class.- Parameters:
clazz- An entity class.service- The service class this entity corresponds to.
-
addConstraint
public static <E extends BaseEntity> void addConstraint(java.lang.Class<E> clazz, SqlPredicate<E> predicate)
Adds a query constraint to a query made with a certain entity. This means that any query made with this entity will include thispredicate.- Type Parameters:
E- The type of the entity.- Parameters:
clazz- The entity to add the constraint to.predicate- The constraint.
-
isRegistered
public <E extends BaseEntity,S extends BaseService<E>> boolean isRegistered(java.lang.Class<S> clazz)
Checks if a service has already been registered.- Type Parameters:
E- The type of the entity.S- The type of the service.- Parameters:
clazz- The class os the service.- Returns:
Trueif an instance of the service is registered,falseif not.
-
-