Package cronapi.database
Class DataSource
java.lang.Object
cronapi.database.DataSource
- All Implemented Interfaces:
com.fasterxml.jackson.databind.JsonSerializable
Class database manipulation, responsible for querying, inserting,
updating and deleting database data procedurally, allowing paged
navigation and setting page size.
- Since:
- 2017-04-26
- Version:
- 1.0
- Author:
- robson.ataide
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.fasterxml.jackson.databind.JsonSerializable
com.fasterxml.jackson.databind.JsonSerializable.Base -
Constructor Summary
ConstructorsConstructorDescriptionDataSource(com.google.gson.JsonObject query) DataSource(String entity) Init a datasource with a page size equals 100DataSource(String entity, int pageSize) Init a datasource setting a page sizeDataSource(String entity, jakarta.persistence.EntityManager entityManager) Init a datasource with a page size equals 100, and custom entity manager -
Method Summary
Modifier and TypeMethodDescriptionvoidalowFetchNext(boolean alowFetchNext) voidcheckRESTSecurity(String method) voidcheckRESTSecurity(String relationId, String method) voidclear()Clean Datasource and to free up allocated memorylongcount()voiddelete()Removes the object in the current indexvoidvoiddeleteRelation(String refId, Var[] primaryKeys, Var[] relationKeys) voidvoidExecute QueryObject[]fetch()Retrieve objects from database using repository when filter is null or empty, if filter not null or is not empty, this method uses entityManager and create a jpql instruction.Object[]fetch(boolean isCount) voidvoidFetch objects from database by a filtervoidvoidfilterByPk(Var[] params) voidfilterByRelation(String refId, org.springframework.data.domain.PageRequest pageRequest, Var... primaryKeys) voidflush()intjakarta.persistence.EntityManagergetEntityManager(Class domainClass) getId()getIds()Return object in current indexReturn field passed from object in current indexgetObjectWithId(Var[] ids) org.springframework.data.domain.PagegetPage()Gets a Pageable object retrieved from repositoryorg.eclipse.persistence.queries.DatabaseQuerygetRelationEntity(String relationId) booleanhasData()booleanhasNext()Verify if can moves the index for next position, in pageable case, looking for next page and so onvoidinsert()Create a new instance of entity and add a results and set current (index) for his positionvoidinsertRelation(String refId, Map<?, ?> data, Var... primaryKeys) booleanvoidnext()Moves the index for next position, in pageable case, looking for next page and so onvoidMoves the index for next position, in pageable case, looking for next page and so onbooleanprevious()Moves the index for previous position, in pageable case, looking for next page and so onvoidresolveRelation(String refId) save()save(boolean returnCursorAfterInsert) save(boolean returnCursorAfterInsert, boolean returnRefreshed) Saves the object in the current index or a new object when has insertedElementsaveAfterCommit(org.eclipse.persistence.internal.sessions.AbstractSession session) voidserialize(com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers) voidserializeWithType(com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers, com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSer) voidsetCurrent(int current) voidsetDataSourceFilter(DataSourceFilter dsFilter) voidsetPageSize(int pageSize) Create a new page request with size passedvoidsetPlainData(boolean plainData) voidsetUseOdataRequest(boolean useOdataRequest) voidsetUseOffset(boolean useOffset) voidsetUseUrlParams(boolean useUrlParams) toString()voidvoidupdateField(String fieldName, Object fieldValue) Update a field from object in the current indexvoidupdateFields(Var... fields) Update fields from object in the current indexbooleanvoid
-
Constructor Details
-
DataSource
Init a datasource with a page size equals 100- Parameters:
entity- - full name of entitiy class like String
-
DataSource
public DataSource(com.google.gson.JsonObject query) -
DataSource
Init a datasource with a page size equals 100, and custom entity manager- Parameters:
entity- - full name of entitiy class like StringentityManager- - custom entity manager
-
DataSource
Init a datasource setting a page size- Parameters:
entity- - full name of entitiy class like StringpageSize- - page size of a Pageable object retrieved from repository
-
-
Method Details
-
getEntityManager
-
getDomainClass
-
getSimpleEntity
-
getEntity
-
count
public long count() -
fetch
Retrieve objects from database using repository when filter is null or empty, if filter not null or is not empty, this method uses entityManager and create a jpql instruction.- Returns:
- a array of Object
-
fetch
-
getMetadata
-
insert
public void insert()Create a new instance of entity and add a results and set current (index) for his position -
toObject
-
insert
-
save
-
save
-
save
Saves the object in the current index or a new object when has insertedElement- Parameters:
returnCursorAfterInsert- booleanreturnRefreshed- boolean- Returns:
- Object
-
saveAfterCommit
-
delete
-
delete
public void delete()Removes the object in the current index -
updateField
Update a field from object in the current index- Parameters:
fieldName- - attributte name in entityfieldValue- - value that replaced or inserted in field name passed
-
updateFields
Update fields from object in the current index- Parameters:
fields- - bidimensional array like fields sample: { {"name", "Paul"}, {"age", "21"} }- Throws:
RuntimeException- if a field is not accessible through a set method
-
filterByPk
-
filter
-
update
-
getObject
Return object in current index- Returns:
- Object from database in current position
-
getObject
Return field passed from object in current index- Parameters:
fieldName- Nome campo- Returns:
- Object value of field passed
- Throws:
RuntimeException- if a field is not accessible through a set method
-
next
public void next()Moves the index for next position, in pageable case, looking for next page and so on -
nextOnPage
public void nextOnPage()Moves the index for next position, in pageable case, looking for next page and so on -
hasNext
public boolean hasNext()Verify if can moves the index for next position, in pageable case, looking for next page and so on- Returns:
- boolean true if has next, false else
-
hasData
public boolean hasData() -
previous
public boolean previous()Moves the index for previous position, in pageable case, looking for next page and so on- Returns:
- boolean true if has previous, false else
-
setCurrent
public void setCurrent(int current) -
getCurrent
public int getCurrent() -
getPage
public org.springframework.data.domain.Page getPage()Gets a Pageable object retrieved from repository- Returns:
- pageable from repository, returns null when fetched by filter
-
setPageSize
public void setPageSize(int pageSize) Create a new page request with size passed- Parameters:
pageSize- size of page request
-
filter
Fetch objects from database by a filter- Parameters:
filter- jpql instruction like a namedQueryparams- parameters used in jpql instruction
-
setDataSourceFilter
-
filter
-
alowFetchNext
public void alowFetchNext(boolean alowFetchNext) -
deleteRelation
-
insertRelation
-
resolveRelation
-
filterByRelation
-
clear
public void clear()Clean Datasource and to free up allocated memory -
execute
Execute Query- Parameters:
query- - JPQL instruction for filter objects to removeparams- - Bidimentional array with params name and params value- Returns:
- Var
-
getTotalElements
-
toString
-
serialize
public void serialize(com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers) throws IOException - Specified by:
serializein interfacecom.fasterxml.jackson.databind.JsonSerializable- Throws:
IOException
-
serializeWithType
public void serializeWithType(com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers, com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSer) throws IOException - Specified by:
serializeWithTypein interfacecom.fasterxml.jackson.databind.JsonSerializable- Throws:
IOException
-
checkRESTSecurity
- Throws:
Exception
-
checkRESTSecurity
- Throws:
Exception
-
getRelationEntity
- Throws:
Exception
-
disableMultiTenant
public void disableMultiTenant() -
enableMultiTenant
public void enableMultiTenant() -
getFilter
-
getIds
-
getId
-
getObjectWithId
-
validate
-
isPlainData
public boolean isPlainData() -
setPlainData
public void setPlainData(boolean plainData) -
useUrlParams
public boolean useUrlParams() -
setUseUrlParams
public void setUseUrlParams(boolean useUrlParams) -
flush
public void flush() -
setUseOdataRequest
public void setUseOdataRequest(boolean useOdataRequest) -
setUseOffset
public void setUseOffset(boolean useOffset) -
getQueryParsed
public org.eclipse.persistence.queries.DatabaseQuery getQueryParsed()
-