Class DataSource

java.lang.Object
cronapi.database.DataSource
All Implemented Interfaces:
com.fasterxml.jackson.databind.JsonSerializable

public class DataSource extends Object implements 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
  • Constructor Details

    • DataSource

      public DataSource(String entity)
      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

      public DataSource(String entity, jakarta.persistence.EntityManager entityManager)
      Init a datasource with a page size equals 100, and custom entity manager
      Parameters:
      entity - - full name of entitiy class like String
      entityManager - - custom entity manager
    • DataSource

      public DataSource(String entity, int pageSize)
      Init a datasource setting a page size
      Parameters:
      entity - - full name of entitiy class like String
      pageSize - - page size of a Pageable object retrieved from repository
  • Method Details

    • getEntityManager

      public jakarta.persistence.EntityManager getEntityManager(Class domainClass)
    • getDomainClass

      public Class getDomainClass()
    • getSimpleEntity

      public String getSimpleEntity()
    • getEntity

      public String getEntity()
    • count

      public long count()
    • fetch

      public Object[] 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

      public Object[] fetch(boolean isCount)
    • getMetadata

      public EntityMetadata getMetadata()
    • insert

      public void insert()
      Create a new instance of entity and add a results and set current (index) for his position
    • toObject

      public Object toObject(Map<?,?> values)
    • insert

      public void insert(Object value)
    • save

      public Object save()
    • save

      public Object save(boolean returnCursorAfterInsert)
    • save

      public Object save(boolean returnCursorAfterInsert, boolean returnRefreshed)
      Saves the object in the current index or a new object when has insertedElement
      Parameters:
      returnCursorAfterInsert - boolean
      returnRefreshed - boolean
      Returns:
      Object
    • saveAfterCommit

      public Object saveAfterCommit(org.eclipse.persistence.internal.sessions.AbstractSession session)
    • delete

      public void delete(Var[] primaryKeys)
    • delete

      public void delete()
      Removes the object in the current index
    • updateField

      public void updateField(String fieldName, Object fieldValue)
      Update a field from object in the current index
      Parameters:
      fieldName - - attributte name in entity
      fieldValue - - value that replaced or inserted in field name passed
    • updateFields

      public void updateFields(Var... fields)
      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

      public void filterByPk(Var[] params)
    • filter

      public void filter(Var data, Var[] extraParams)
    • update

      public void update(Var data)
    • getObject

      public Object getObject()
      Return object in current index
      Returns:
      Object from database in current position
    • getObject

      public Object getObject(String fieldName)
      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

      public void filter(String filter, Var... params)
      Fetch objects from database by a filter
      Parameters:
      filter - jpql instruction like a namedQuery
      params - parameters used in jpql instruction
    • setDataSourceFilter

      public void setDataSourceFilter(DataSourceFilter dsFilter)
    • filter

      public void filter(String filter, org.springframework.data.domain.PageRequest pageRequest, Var... params)
    • alowFetchNext

      public void alowFetchNext(boolean alowFetchNext)
    • deleteRelation

      public void deleteRelation(String refId, Var[] primaryKeys, Var[] relationKeys)
    • insertRelation

      public Object insertRelation(String refId, Map<?,?> data, Var... primaryKeys)
    • resolveRelation

      public void resolveRelation(String refId)
    • filterByRelation

      public void filterByRelation(String refId, org.springframework.data.domain.PageRequest pageRequest, Var... primaryKeys)
    • clear

      public void clear()
      Clean Datasource and to free up allocated memory
    • execute

      public Var execute(String query, Var... params)
      Execute Query
      Parameters:
      query - - JPQL instruction for filter objects to remove
      params - - Bidimentional array with params name and params value
      Returns:
      Var
    • getTotalElements

      public Var getTotalElements()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • serialize

      public void serialize(com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers) throws IOException
      Specified by:
      serialize in interface com.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:
      serializeWithType in interface com.fasterxml.jackson.databind.JsonSerializable
      Throws:
      IOException
    • checkRESTSecurity

      public void checkRESTSecurity(String method) throws Exception
      Throws:
      Exception
    • checkRESTSecurity

      public void checkRESTSecurity(String relationId, String method) throws Exception
      Throws:
      Exception
    • getRelationEntity

      public String getRelationEntity(String relationId) throws Exception
      Throws:
      Exception
    • disableMultiTenant

      public void disableMultiTenant()
    • enableMultiTenant

      public void enableMultiTenant()
    • getFilter

      public String getFilter()
    • getIds

      public Var getIds()
    • getId

      public Var getId()
    • getObjectWithId

      public Object getObjectWithId(Var[] ids)
    • validate

      public void validate(String jpql)
    • 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()