Package net.sf.jkniv.whinstone
Interface Repository
-
public interface RepositoryA repository holds the connections to data base server, allowing it to be queried through Queryable objects. Repository instances must be thread-safe and usually a single instance is enough per application.- Since:
- 0.6.0
- Author:
- Alisson Gomes
-
-
Field Summary
Fields Modifier and Type Field Description static StringTRANSACTION_NONEstatic StringTRANSACTION_READ_COMMITTEDstatic StringTRANSACTION_READ_UNCOMMITTEDstatic StringTRANSACTION_REPEATABLE_READstatic StringTRANSACTION_SERIALIZABLE
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intadd(Queryable queryable)Add a new object to repository.<T> intadd(T entity)Add a new object to repository.voidclose()Close the connection with the database.booleancontainsQuery(String name)<T> Tdsl()A domain-specific languages (DSL) from native API: JPA, Couchbase, Cassandra etc.booleanenrich(Queryable queryable)Use theQueryableto retrieve data and appends the result toQueryable.getParams()parameters, where for eachgetmethod must have a correspondentset.voidflush()Push the queries from buffer to repository.<T> Tget(Class<T> returnType, Object object)Get one object instance of typereturnTypefrom repository using aobjectas parameter.<T> Tget(Queryable queryable)Get one object instance from repository using a query.<T> Tget(Queryable queryable, Class<T> returnType)Get one object instance of typereturnTypefrom repository using a query.<T,R>
Tget(Queryable queryable, ResultRow<T,R> customResultRow)Get one object instance from repository using a query.<T> Tget(T object)Get one object instance from repository using aobjectas parameter.TransactionalgetTransaction()<T> List<T>list(Queryable queryable)Retrieve a set of objectsTfrom repository using a query.<T> List<T>list(Queryable queryable, Class<T> returnType)Retrieve a set of objectsreturnTypefrom repository using a query.<T,R>
List<T>list(Queryable queryable, ResultRow<T,R> customResultRow)Retrieve a set of objectsTfrom repository using a query.intremove(Queryable queryable)Execute a query to remove one or many objects from repository.<T> intremove(T entity)Remove theentityfrom repository.<T> Tscalar(Queryable queryable)Retrieve a number, numerical quantity, string, date, boolean, some primitive value (wrapped), the type is checked against jdbc data type.intupdate(Queryable queryable)Update many objects in repository.<T> Tupdate(T entity)Update object(s) in repository.
-
-
-
Field Detail
-
TRANSACTION_NONE
static final String TRANSACTION_NONE
- See Also:
- Constant Field Values
-
TRANSACTION_READ_UNCOMMITTED
static final String TRANSACTION_READ_UNCOMMITTED
- See Also:
- Constant Field Values
-
TRANSACTION_READ_COMMITTED
static final String TRANSACTION_READ_COMMITTED
- See Also:
- Constant Field Values
-
TRANSACTION_REPEATABLE_READ
static final String TRANSACTION_REPEATABLE_READ
- See Also:
- Constant Field Values
-
TRANSACTION_SERIALIZABLE
static final String TRANSACTION_SERIALIZABLE
- See Also:
- Constant Field Values
-
-
Method Detail
-
get
<T> T get(Queryable queryable)
Get one object instance from repository using a query.- Type Parameters:
T- generic type to be returned- Parameters:
queryable- The Query name with yours parameters- Returns:
- Return the object that matches with query. A null reference is returned if the query no match anyone object.
- Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query namenet.sf.jkniv.sqlegance.NonUniqueResultException- when select or select with group by recovery more one objects
-
get
<T> T get(Queryable queryable, Class<T> returnType)
Get one object instance of typereturnTypefrom repository using a query.- Type Parameters:
T- type of object returned- Parameters:
queryable- The Query name with yours parametersreturnType- overload the returned type from XML file- Returns:
- Return the object
returnTypethat matches with query. A null reference is returned if the query no match anyone object. - Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query namenet.sf.jkniv.sqlegance.NonUniqueResultException- when select or select with group by recovery more one objects
-
get
<T,R> T get(Queryable queryable, ResultRow<T,R> customResultRow)
Get one object instance from repository using a query.- Type Parameters:
T- type of object returnedR- raw type from repository API (LikeResultSetfrom JDBC)- Parameters:
queryable- The Query name with yours parameterscustomResultRow- Customized extractor to process each row from query- Returns:
- Return the object
returnTypethat matches with query. A null reference is returned if the query no match anyone object. - Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query namenet.sf.jkniv.sqlegance.NonUniqueResultException- when select or select with group by recovery more one objects
-
get
<T> T get(T object)
Get one object instance from repository using aobjectas parameter.- Type Parameters:
T- type of object returned- Parameters:
object- object that contains the parameters to retrieve the entity.- Returns:
- Return the object
returnTypethat matches with query. A null reference is returned if the query no match anyone object. - Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query namenet.sf.jkniv.sqlegance.NonUniqueResultException- when select or select with group by recovery more one objects
-
get
<T> T get(Class<T> returnType, Object object)
Get one object instance of typereturnTypefrom repository using aobjectas parameter.- Type Parameters:
T- type of object returned- Parameters:
returnType- overload the returned type from XML fileobject- parameters from query to retrieve the object- Returns:
- Return the object
returnTypethat matches with query. A null reference is returned if the query no match anyone object. - Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query namenet.sf.jkniv.sqlegance.NonUniqueResultException- when select or select with group by recovery more one objects
-
scalar
<T> T scalar(Queryable queryable)
Retrieve a number, numerical quantity, string, date, boolean, some primitive value (wrapped), the type is checked against jdbc data type.- java.math.BigDecimal
- java.lang.Boolean
- java.lang.Byte
- java.lang.Double
- java.lang.Float
- java.lang.Integer
- java.lang.Long
- java.lang.Short
- java.lang.String
- java.lang.Character
- java.util.Date
- Type Parameters:
T- the single type to be returned- Parameters:
queryable- The Query name with yours parameters- Returns:
- Scalar value
- Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query namenet.sf.jkniv.sqlegance.NonUniqueResultException- when select or select with group by recovery more one objects
-
enrich
boolean enrich(Queryable queryable)
Use theQueryableto retrieve data and appends the result toQueryable.getParams()parameters, where for eachgetmethod must have a correspondentset.- Parameters:
queryable- Query with yours parameters- Returns:
- return
trueif the objects was enriched,falseotherwise. - Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query namenet.sf.jkniv.sqlegance.NonUniqueResultException- if yourQueryabledoesn't return one unique value
-
list
<T> List<T> list(Queryable queryable)
Retrieve a set of objectsTfrom repository using a query.- Type Parameters:
T- generic type to be returned- Parameters:
queryable- The Query name with yours parameters- Returns:
- Return a set of object that matches with query. A empty list is returned if the query no match anyone object.
- Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query name
-
list
<T> List<T> list(Queryable queryable, Class<T> returnType)
Retrieve a set of objectsreturnTypefrom repository using a query.- Type Parameters:
T- type of object returned- Parameters:
queryable- The Query name with yours parametersreturnType- overload the returned type from XML file- Returns:
- Return a set of object that matches with query. A empty list is returned if the query no match anyone object.
- Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query name
-
list
<T,R> List<T> list(Queryable queryable, ResultRow<T,R> customResultRow)
Retrieve a set of objectsTfrom repository using a query.- Type Parameters:
T- type of object returnedR- raw type from repository API (LikeResultSetfrom JDBC)- Parameters:
queryable- The Query name with yours parameterscustomResultRow- Customized extractor to process each row from query- Returns:
- Return a set of object that matches with query. A empty list is returned if the query no match anyone object.
- Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query name
-
add
int add(Queryable queryable)
Add a new object to repository.- Parameters:
queryable- name of query must be executed to add object to repository- Returns:
- Return the number of objects inserted.
- Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query name
-
add
<T> int add(T entity)
Add a new object to repository.- Type Parameters:
T- type of object returned- Parameters:
entity- object to be added to repository- Returns:
- Return the number of objects inserted.
- Throws:
IllegalArgumentException- when entity is null
-
update
int update(Queryable queryable)
Update many objects in repository.- Parameters:
queryable- The Query name with yours parameters- Returns:
- Return the number of objects updated.
- Throws:
net.sf.jkniv.sqlegance.QueryNotFoundException- when not found the query nameIllegalArgumentException- when the query is different from update sentence
-
update
<T> T update(T entity)
Update object(s) in repository.- Type Parameters:
T- type of object returned- Parameters:
entity- update the repository with aentityvalues mapped at query.- Returns:
- the instance that was updated to
- Throws:
IllegalArgumentException- when entity is null
-
remove
int remove(Queryable queryable)
Execute a query to remove one or many objects from repository.- Parameters:
queryable- The Query name with yours parameters- Returns:
- the number of rows removed.
- Throws:
IllegalArgumentException- when the query is different from delete
-
remove
<T> int remove(T entity)
Remove theentityfrom repository.- Type Parameters:
T- type of object returned- Parameters:
entity- object with the parameters- Returns:
- the number of objects removed.
- Throws:
IllegalArgumentException- when entity is null
-
flush
void flush()
Push the queries from buffer to repository.
-
getTransaction
Transactional getTransaction()
-
close
void close()
Close the connection with the database. After close the repository any query cannot be executed against the database then all subsequent access to the repository throw aRepositoryException
-
containsQuery
boolean containsQuery(String name)
-
dsl
<T> T dsl()
A domain-specific languages (DSL) from native API: JPA, Couchbase, Cassandra etc.- Type Parameters:
T- a generic type from DSL API- Returns:
- the DSL API to build dynamic queries
- Throws:
UnsupportedDslOperationException- when the repository does not supports DSL
-
-