com.github.drinkjava2.jsqlbox
Interface ActiveRecordSupport<T>

All Known Implementing Classes:
ActiveRecord

public interface ActiveRecordSupport<T>

If a entity class implements ActiveRecordSupport interface, it will have CRUD Method. This interface is designed for jSqlBox Java8 version because Java8 support default method interface is not useful for Java7 and below.

Since:
1.0.0
Author:
Yong Zhu

Field Summary
static ThreadLocal<String[]> lastTimePutFieldsCache
           
 
Method Summary
 SqlItem bind(Object... parameters)
          For tXxxx style templateEngine use, return a SqlItemType.PUT type SqlItem instance, Usage: put("key1",value1,"key2",value2...);
 int countAll(Object... optionItems)
          Return how many records for current entity class
 SqlBoxContext ctx(Object... optionItems)
           
 void delete(Object... optionItems)
          Delete entity in database, if not 1 row deleted, throw SqlBoxException
 void deleteById(Object id, Object... optionItems)
          Delete entity by given id, if not 1 row deleted, throw SqlBoxException
 int deleteByIdTry(Object id, Object... optionItems)
          Delete entity by given id, return how many rows deleted
 int deleteTry(Object... optionItems)
          Delete entity in database, return how many rows affected
 boolean exist(Object... optionItems)
          Check if entity exist by its id
 boolean existById(Object id, Object... optionItems)
          Check if entity exist by given id
 List<T> findAll(Object... optionItems)
          Find all entity of same entity class, if not found, return empty list
 List<T> findByIds(Iterable<?> ids, Object... optionItems)
          Find all entity according its id, if not found, return empty list
 List<T> findBySample(Object sampleBean, Object... optionItems)
          Find entity according a sample bean, ignore null fields, if not found, return empty list
 List<T> findBySQL(Object... optionItems)
          Find entity according SQL, if not found, return empty list
<E> E
findOneRelated(Object... sqlItems)
          Find one related entity
<E> List<E>
findRelatedList(Object... sqlItems)
          Find related entity List
<E> Map<Object,E>
findRelatedMap(Object... sqlItems)
          Find related entity Map
<E> Set<E>
findRelatedSet(Object... sqlItems)
          Find related entity Set
<U> U
guess(Object... params)
          In SqlMapper style, based on current method @Sql annotated String or Text(see user manual) in comments(need put Java file in resources folder, see user manual) and parameters, guess a best fit query/update/delete/execute method and run it
 PreparedSQL guessPreparedSQL(Object... params)
          In SqlMapper style, return current method's prepared SQL
 String guessSQL()
          In SqlMapper style, return current method's SQL String based on current method @Sql annotated String or Text(see user manual) in comments(need put Java file in resources folder, see user manual)
 T insert(Object... optionItems)
          Insert entity to database, if not 1 row updated, throw SqlBoxException
 T load(Object... optionItems)
          Load entity according its id, if not 1 row round, throw SqlBoxException
 T loadById(Object id, Object... optionItems)
          Load entity by given id, if not 1 row found, throw SqlBoxException
 T loadByIdTry(Object id, Object... optionItems)
          Load entity by given id, if not found, return null
 int loadTry(Object... optionItems)
          Load entity according its id, return how many rows found
 T put(Object... fieldAndValues)
          Link style set values for entity field, format like: user.put("id","id1").put("name","Sam").put("address","Beijing","phone","12345", "email","abc@123.com")
 T putFields(String... fieldNames)
          Cache a field array in ThreadLocal for putValues method use
 T putValues(Object... values)
          Put values for entity fields, field names should be cached by call putFields method first
 SqlBoxContext shardDB(Object... optionItems)
          Return current entity's shardDatabase according its sharding key values
 String shardTB(Object... optionItems)
          Return current entity's shardTable according its sharding key values
 T update(Object... optionItems)
          Update entity in database, if not 1 row updated, throw SqlBoxException
 int updateTry(Object... optionItems)
          Update entity in database, return how many rows affected
 

Field Detail

lastTimePutFieldsCache

static final ThreadLocal<String[]> lastTimePutFieldsCache
Method Detail

ctx

SqlBoxContext ctx(Object... optionItems)
Returns:
current SqlBoxContext instance

insert

T insert(Object... optionItems)
Insert entity to database, if not 1 row updated, throw SqlBoxException


update

T update(Object... optionItems)
Update entity in database, if not 1 row updated, throw SqlBoxException


updateTry

int updateTry(Object... optionItems)
Update entity in database, return how many rows affected


delete

void delete(Object... optionItems)
Delete entity in database, if not 1 row deleted, throw SqlBoxException


deleteTry

int deleteTry(Object... optionItems)
Delete entity in database, return how many rows affected


deleteById

void deleteById(Object id,
                Object... optionItems)
Delete entity by given id, if not 1 row deleted, throw SqlBoxException


deleteByIdTry

int deleteByIdTry(Object id,
                  Object... optionItems)
Delete entity by given id, return how many rows deleted


exist

boolean exist(Object... optionItems)
Check if entity exist by its id


existById

boolean existById(Object id,
                  Object... optionItems)
Check if entity exist by given id


countAll

int countAll(Object... optionItems)
Return how many records for current entity class


load

T load(Object... optionItems)
Load entity according its id, if not 1 row round, throw SqlBoxException


loadTry

int loadTry(Object... optionItems)
Load entity according its id, return how many rows found


loadById

T loadById(Object id,
           Object... optionItems)
Load entity by given id, if not 1 row found, throw SqlBoxException


loadByIdTry

T loadByIdTry(Object id,
              Object... optionItems)
Load entity by given id, if not found, return null


findAll

List<T> findAll(Object... optionItems)
Find all entity of same entity class, if not found, return empty list


findByIds

List<T> findByIds(Iterable<?> ids,
                  Object... optionItems)
Find all entity according its id, if not found, return empty list


findBySQL

List<T> findBySQL(Object... optionItems)
Find entity according SQL, if not found, return empty list


findBySample

List<T> findBySample(Object sampleBean,
                     Object... optionItems)
Find entity according a sample bean, ignore null fields, if not found, return empty list


findOneRelated

<E> E findOneRelated(Object... sqlItems)
Find one related entity


findRelatedList

<E> List<E> findRelatedList(Object... sqlItems)
Find related entity List


findRelatedSet

<E> Set<E> findRelatedSet(Object... sqlItems)
Find related entity Set


findRelatedMap

<E> Map<Object,E> findRelatedMap(Object... sqlItems)
Find related entity Map


put

T put(Object... fieldAndValues)
Link style set values for entity field, format like: user.put("id","id1").put("name","Sam").put("address","Beijing","phone","12345", "email","abc@123.com")


putFields

T putFields(String... fieldNames)
Cache a field array in ThreadLocal for putValues method use


putValues

T putValues(Object... values)
Put values for entity fields, field names should be cached by call putFields method first


guess

<U> U guess(Object... params)
In SqlMapper style, based on current method @Sql annotated String or Text(see user manual) in comments(need put Java file in resources folder, see user manual) and parameters, guess a best fit query/update/delete/execute method and run it


guessSQL

String guessSQL()
In SqlMapper style, return current method's SQL String based on current method @Sql annotated String or Text(see user manual) in comments(need put Java file in resources folder, see user manual)


guessPreparedSQL

PreparedSQL guessPreparedSQL(Object... params)
In SqlMapper style, return current method's prepared SQL


bind

SqlItem bind(Object... parameters)
For tXxxx style templateEngine use, return a SqlItemType.PUT type SqlItem instance, Usage: put("key1",value1,"key2",value2...);


shardTB

String shardTB(Object... optionItems)
Return current entity's shardTable according its sharding key values


shardDB

SqlBoxContext shardDB(Object... optionItems)
Return current entity's shardDatabase according its sharding key values



Copyright © 2018. All rights reserved.