|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.github.drinkjava2.jsqlbox.SqlBoxContextUtils
public abstract class SqlBoxContextUtils
| Constructor Summary | |
|---|---|
SqlBoxContextUtils()
|
|
| Method Summary | ||
|---|---|---|
protected static void |
appendLeftJoinSQL(PreparedSQL ps)
Based on PreparedSQL's models and alias, automatically build and append a SQL like below: |
|
static void |
createLastAutoAliasName(PreparedSQL ps)
Create auto Alias name based on capital letters of class name in models of PreparedSQL, if alias already exists, put a number at end, for example: User ->u User, UserRole, UserOther, Order, Order_a -> u, u1, u2, o, o1 if no EntityClass, alais will be created by table name, for example: user ->u user_role -> UR |
|
static EntityNet |
entityAutoNet(SqlBoxContext ctx,
Class<?>... entityClasses)
|
|
static int |
entityCountAll(SqlBoxContext ctx,
Class<?> entityClass,
Object... optionItems)
Count quantity of all entity, this method does not support sharding |
|
static int |
entityDeleteByIdTry(SqlBoxContext ctx,
Class<?> entityClass,
Object id,
Object... optionItems)
Try delete entity by Id, return row affected, return row affected |
|
static int |
entityDeleteTry(SqlBoxContext ctx,
Object entityBean,
Object... optionItems)
Delete entityBean in database according primary key value, return row affected |
|
static boolean |
entityExist(SqlBoxContext ctx,
Object entityBean,
Object... optionItems)
Check if entityBean exist in database by its id |
|
static boolean |
entityExistById(SqlBoxContext ctx,
Class<?> entityClass,
Object id,
Object... optionItems)
Try delete entity by Id, return row affected |
|
static
|
entityFindAll(SqlBoxContext ctx,
Class<T> entityClass,
Object... optionItems)
|
|
static
|
entityFindBySample(SqlBoxContext ctx,
Object sampleBean,
Object... sqlItems)
|
|
static
|
entityFindRelatedList(SqlBoxContext ctx,
Object entity,
Object... sqlItems)
|
|
static
|
entityFindRelatedMap(SqlBoxContext ctx,
Object entity,
Object... sqlItems)
|
|
static
|
entityFindRelatedOne(SqlBoxContext ctx,
Object entity,
Object... sqlItems)
|
|
static
|
entityFindRelatedSet(SqlBoxContext ctx,
Object entity,
Object... sqlItems)
|
|
static int |
entityInsertTry(SqlBoxContext ctx,
Object entityBean,
Object... optionItems)
Insert entityBean into database, and change ID fields to values generated by IdGenerator (identity or sequence or UUID...), return row affected |
|
static
|
entityLoadByIdTry(SqlBoxContext ctx,
Class<T> entityClass,
Object id,
Object... optionItems)
Create a new Entity, load from DB according given ID, return null if entity does not exist in DB |
|
static int |
entityLoadTry(SqlBoxContext ctx,
Object entityBean,
Object... optionItems)
Load entity according entity's id fields, return row affected |
|
static
|
entityOrClassToBean(Object entityOrClass)
Transfer Object to TableModel, object can be SqlBox instance, entityClass or entity Bean |
|
static int |
entityUpdateTry(SqlBoxContext ctx,
Object entityBean,
Object... optionItems)
Update entityBean according primary key, return row affected |
|
static TableModel[] |
findAllModels(Object... sqlItems)
Extract models from sqlItems |
|
static TableModel |
findEntityOrClassTableModel(Object entityOrClass)
|
|
static TableModel |
findFirstModel(Object... optionItems)
|
|
static Object[] |
findModelAlias(Object... sqlItems)
Find model and alias items from sqlItems |
|
static Object[] |
findNotModelAlias(Object... sqlItems)
Find not model/alias items from sqlItems |
|
static TableModel |
findTableModel(Object entityOrClass,
Object... optionItems)
if optionItems has a TabelModel, use it, otherwise find tablemodel from entityOrClass |
|
static TableModel |
findTailModel(SqlBoxContext ctx,
TableModel entityModel,
Object... optionItems)
Return first tail TableModel, if not found return null |
|
static SqlBoxContext |
getShardedDB(SqlBoxContext currentCtx,
Object entityOrClass,
Object... shardKey)
Use current SqlBoxContext's shardingTools to calculate the master SqlBoxContext |
|
static String |
getShardedTB(SqlBoxContext ctx,
Object entityOrClass,
Object... shardKey)
Use current SqlBoxContext's shardingTools to calculate the real shardTable name |
|
static TableModel[] |
loadMetaTableModels(SqlBoxContext ctx,
Dialect dialect)
Read database Meta info into SqlBox[] |
|
static
|
mapToEntityBean(TableModel model,
Map<String,Object> oneRow)
Convert one row data into EntityBean |
|
static Object |
readValueFromBeanFieldOrTail(Object entityBean,
ColumnModel columnModel)
Read value from entityBean field or tail |
|
static void |
writeValueToBeanFieldOrTail(Object entityBean,
ColumnModel columnModel,
Object value)
write value to entityBean field or tail |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SqlBoxContextUtils()
| Method Detail |
|---|
public static TableModel[] loadMetaTableModels(SqlBoxContext ctx,
Dialect dialect)
public static String getShardedTB(SqlBoxContext ctx,
Object entityOrClass,
Object... shardKey)
public static SqlBoxContext getShardedDB(SqlBoxContext currentCtx,
Object entityOrClass,
Object... shardKey)
public static TableModel findTableModel(Object entityOrClass,
Object... optionItems)
public static TableModel findEntityOrClassTableModel(Object entityOrClass)
public static TableModel findFirstModel(Object... optionItems)
public static TableModel findTailModel(SqlBoxContext ctx,
TableModel entityModel,
Object... optionItems)
public static TableModel[] findAllModels(Object... sqlItems)
public static Object[] findModelAlias(Object... sqlItems)
public static Object[] findNotModelAlias(Object... sqlItems)
public static void createLastAutoAliasName(PreparedSQL ps)
public static <T> T mapToEntityBean(TableModel model,
Map<String,Object> oneRow)
public static <T> T entityOrClassToBean(Object entityOrClass)
1. TableModel instance, will use it 2. SqlBox instance, will use its tableModel 3. Class, will call TableModelUtils.entity2Model to create tableModel 4. Object, will call TableModelUtils.entity2Model(entityOrClass.getClass()) to create a SqlBox instance
protected static void appendLeftJoinSQL(PreparedSQL ps)
select a.**, b.**, c.**... from xxx a left join xxx b on a.bid=b.id left join xxx c on b.cid=c.id ...
public static Object readValueFromBeanFieldOrTail(Object entityBean,
ColumnModel columnModel)
public static void writeValueToBeanFieldOrTail(Object entityBean,
ColumnModel columnModel,
Object value)
public static int entityInsertTry(SqlBoxContext ctx,
Object entityBean,
Object... optionItems)
public static int entityUpdateTry(SqlBoxContext ctx,
Object entityBean,
Object... optionItems)
public static int entityDeleteTry(SqlBoxContext ctx,
Object entityBean,
Object... optionItems)
public static int entityDeleteByIdTry(SqlBoxContext ctx,
Class<?> entityClass,
Object id,
Object... optionItems)
public static int entityLoadTry(SqlBoxContext ctx,
Object entityBean,
Object... optionItems)
public static <T> T entityLoadByIdTry(SqlBoxContext ctx,
Class<T> entityClass,
Object id,
Object... optionItems)
public static boolean entityExist(SqlBoxContext ctx,
Object entityBean,
Object... optionItems)
public static boolean entityExistById(SqlBoxContext ctx,
Class<?> entityClass,
Object id,
Object... optionItems)
public static int entityCountAll(SqlBoxContext ctx,
Class<?> entityClass,
Object... optionItems)
public static <T> List<T> entityFindAll(SqlBoxContext ctx,
Class<T> entityClass,
Object... optionItems)
public static <T> List<T> entityFindBySample(SqlBoxContext ctx,
Object sampleBean,
Object... sqlItems)
public static EntityNet entityAutoNet(SqlBoxContext ctx,
Class<?>... entityClasses)
public static <E> E entityFindRelatedOne(SqlBoxContext ctx,
Object entity,
Object... sqlItems)
public static <E> List<E> entityFindRelatedList(SqlBoxContext ctx,
Object entity,
Object... sqlItems)
public static <E> Set<E> entityFindRelatedSet(SqlBoxContext ctx,
Object entity,
Object... sqlItems)
public static <E> Map<Object,E> entityFindRelatedMap(SqlBoxContext ctx,
Object entity,
Object... sqlItems)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||