|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.github.drinkjava2.jsqlbox.ActiveRecord<T>
public class ActiveRecord<T>
Entity class extended from ActiveRecord or implements ActiveRecordSupport interface will get CRUD methods, see below difference in jSqlBox to save ActiveRecord entity and normal entity(POJO) into database:
ActiveRecord style:
SqlBoxContext ctx=new SqlBoxContext(dataSource);
SqlBoxContext.setDefaultContext(ctx);
entity.insert();
or
SqlBoxContext ctx=new SqlBoxContext(dataSource);
entity.useContext(ctx);
entity.insert();
or
SqlBoxContext ctx=new SqlBoxContext(dataSource);
entity.insert(ctx);
Data Mapper style (for POJO entity):
SqlBoxContext ctx=new SqlBoxContext(dataSource);
ctx.insert(entity);
or
SqlBoxContext ctx=new SqlBoxContext(dataSource);
someOtherCtx.insert(entity, ctx);
| Field Summary |
|---|
| Fields inherited from interface com.github.drinkjava2.jsqlbox.ActiveRecordSupport |
|---|
lastTimePutFieldsCache |
| Constructor Summary | |
|---|---|
ActiveRecord()
|
|
| 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 |
|
protected void |
crudMethods__________________()
|
|
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 |
|
|
findOneRelated(Object... optionItems)
Find one related entity |
|
|
findRelatedList(Object... optionItems)
Find related entity List |
|
|
findRelatedMap(Object... optionItems)
Find related entity Map |
|
|
findRelatedSet(Object... optionItems)
Find related entity Set |
|
|
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 |
|
protected void |
miscMethods__________________()
|
|
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 |
|
T |
useContext(SqlBoxContext ctx)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ActiveRecord()
| Method Detail |
|---|
public SqlBoxContext ctx(Object... optionItems)
ctx in interface ActiveRecordSupport<T>public T useContext(SqlBoxContext ctx)
protected void crudMethods__________________()
public T insert(Object... optionItems)
ActiveRecordSupport
insert in interface ActiveRecordSupport<T>public T update(Object... optionItems)
ActiveRecordSupport
update in interface ActiveRecordSupport<T>public int updateTry(Object... optionItems)
ActiveRecordSupport
updateTry in interface ActiveRecordSupport<T>public void delete(Object... optionItems)
ActiveRecordSupport
delete in interface ActiveRecordSupport<T>public int deleteTry(Object... optionItems)
ActiveRecordSupport
deleteTry in interface ActiveRecordSupport<T>
public void deleteById(Object id,
Object... optionItems)
ActiveRecordSupport
deleteById in interface ActiveRecordSupport<T>
public int deleteByIdTry(Object id,
Object... optionItems)
ActiveRecordSupport
deleteByIdTry in interface ActiveRecordSupport<T>public boolean exist(Object... optionItems)
ActiveRecordSupport
exist in interface ActiveRecordSupport<T>
public boolean existById(Object id,
Object... optionItems)
ActiveRecordSupport
existById in interface ActiveRecordSupport<T>public T load(Object... optionItems)
ActiveRecordSupport
load in interface ActiveRecordSupport<T>public int loadTry(Object... optionItems)
ActiveRecordSupport
loadTry in interface ActiveRecordSupport<T>
public T loadById(Object id,
Object... optionItems)
ActiveRecordSupport
loadById in interface ActiveRecordSupport<T>
public T loadByIdTry(Object id,
Object... optionItems)
ActiveRecordSupport
loadByIdTry in interface ActiveRecordSupport<T>public List<T> findAll(Object... optionItems)
ActiveRecordSupport
findAll in interface ActiveRecordSupport<T>
public List<T> findByIds(Iterable<?> ids,
Object... optionItems)
ActiveRecordSupport
findByIds in interface ActiveRecordSupport<T>public List<T> findBySQL(Object... optionItems)
ActiveRecordSupport
findBySQL in interface ActiveRecordSupport<T>
public List<T> findBySample(Object sampleBean,
Object... optionItems)
ActiveRecordSupport
findBySample in interface ActiveRecordSupport<T>public <E> E findOneRelated(Object... optionItems)
ActiveRecordSupport
findOneRelated in interface ActiveRecordSupport<T>public <E> List<E> findRelatedList(Object... optionItems)
ActiveRecordSupport
findRelatedList in interface ActiveRecordSupport<T>public <E> Set<E> findRelatedSet(Object... optionItems)
ActiveRecordSupport
findRelatedSet in interface ActiveRecordSupport<T>public <E> Map<Object,E> findRelatedMap(Object... optionItems)
ActiveRecordSupport
findRelatedMap in interface ActiveRecordSupport<T>public int countAll(Object... optionItems)
ActiveRecordSupport
countAll in interface ActiveRecordSupport<T>protected void miscMethods__________________()
public T put(Object... fieldAndValues)
ActiveRecordSupport
put in interface ActiveRecordSupport<T>public T putFields(String... fieldNames)
ActiveRecordSupport
putFields in interface ActiveRecordSupport<T>public T putValues(Object... values)
ActiveRecordSupport
putValues in interface ActiveRecordSupport<T>public <U> U guess(Object... params)
ActiveRecordSupport
guess in interface ActiveRecordSupport<T>public String guessSQL()
ActiveRecordSupport
guessSQL in interface ActiveRecordSupport<T>public PreparedSQL guessPreparedSQL(Object... params)
ActiveRecordSupport
guessPreparedSQL in interface ActiveRecordSupport<T>public SqlItem bind(Object... parameters)
ActiveRecordSupport
bind in interface ActiveRecordSupport<T>public String shardTB(Object... optionItems)
ActiveRecordSupport
shardTB in interface ActiveRecordSupport<T>public SqlBoxContext shardDB(Object... optionItems)
ActiveRecordSupport
shardDB in interface ActiveRecordSupport<T>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||