com.github.drinkjava2.jsqlbox
Class SqlBoxContextUtils

java.lang.Object
  extended by com.github.drinkjava2.jsqlbox.SqlBoxContextUtils

public abstract class SqlBoxContextUtils
extends Object

SqlBoxContextUtils is utility class store static methods about SqlBoxContext

Since:
1.0.0
Author:
Yong Zhu

Constructor Summary
SqlBoxContextUtils()
           
 
Method Summary
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
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
static int entityDeleteTry(SqlBoxContext ctx, Object entityBean, Object... optionItems)
          Delete entityBean in database according primary key value
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
<T> List<T>
entityFindAll(SqlBoxContext ctx, Class<T> entityClass, Object... optionItems)
           
static
<T> List<T>
entityFindByIds(SqlBoxContext ctx, Class<T> entityClass, Iterable<?> ids, Object... optionItems)
           
static
<T> List<T>
entityFindBySample(SqlBoxContext ctx, Object sampleBean, Object... sqlItems)
           
static
<E> List<E>
entityFindRelatedList(SqlBoxContext ctx, Object entity, Object... sqlItems)
           
static
<E> Map<Object,E>
entityFindRelatedMap(SqlBoxContext ctx, Object entity, Object... sqlItems)
           
static
<E> E
entityFindRelatedOne(SqlBoxContext ctx, Object entity, Object... sqlItems)
           
static
<E> Set<E>
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...)
static
<T> T
entityLoadByIdTry(SqlBoxContext ctx, Class<T> entityClass, Object idOrIdMap, Object... optionItems)
           
static int entityLoadTry(SqlBoxContext ctx, Object entityBean, Object... optionItems)
           
static
<T> T
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
static TableModel[] findAllModels(Object... sqlItems)
          Extract models from sqlItems
static TableModel findEntityOrClassTableModel(Object entityOrClass)
           
static TableModel findFirstModel(Object... optionItems)
           
static ColumnModel findMatchColumnForJavaField(String entityField, TableModel tableModel)
           
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)
           
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
<T> T
mapToEntityBean(TableModel model, Map<String,Object> oneRow)
          Convert one row data into EntityBean
static void notAllowSharding(ColumnModel col)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlBoxContextUtils

public SqlBoxContextUtils()
Method Detail

loadMetaTableModels

public static TableModel[] loadMetaTableModels(SqlBoxContext ctx,
                                               Dialect dialect)
Read database Meta info into SqlBox[]


findMatchColumnForJavaField

public static ColumnModel findMatchColumnForJavaField(String entityField,
                                                      TableModel tableModel)

getShardedTB

public static String getShardedTB(SqlBoxContext ctx,
                                  Object entityOrClass,
                                  Object... shardKey)
Use current SqlBoxContext's shardingTools to calculate the real shardTable name


getShardedDB

public static SqlBoxContext getShardedDB(SqlBoxContext currentCtx,
                                         Object entityOrClass,
                                         Object... shardKey)
Use current SqlBoxContext's shardingTools to calculate the master SqlBoxContext


findTableModel

public static TableModel findTableModel(Object entityOrClass,
                                        Object... optionItems)

findEntityOrClassTableModel

public static TableModel findEntityOrClassTableModel(Object entityOrClass)

findFirstModel

public static TableModel findFirstModel(Object... optionItems)

findAllModels

public static TableModel[] findAllModels(Object... sqlItems)
Extract models from sqlItems


findModelAlias

public static Object[] findModelAlias(Object... sqlItems)
Find model and alias items from sqlItems


findNotModelAlias

public static Object[] findNotModelAlias(Object... sqlItems)
Find not model/alias items from sqlItems


createLastAutoAliasName

public 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


mapToEntityBean

public static <T> T mapToEntityBean(TableModel model,
                                    Map<String,Object> oneRow)
Convert one row data into EntityBean


entityOrClassToBean

public static <T> T entityOrClassToBean(Object entityOrClass)
Transfer Object to TableModel, object can be SqlBox instance, entityClass or entity Bean
 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
 


notAllowSharding

public static void notAllowSharding(ColumnModel col)

appendLeftJoinSQL

public static void appendLeftJoinSQL(PreparedSQL ps)
Based on PreparedSQL's models and alias, automatically build and append a SQL like below:
 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 ...
 


entityInsertTry

public 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...)


entityUpdateTry

public static int entityUpdateTry(SqlBoxContext ctx,
                                  Object entityBean,
                                  Object... optionItems)
Update entityBean according primary key


entityDeleteTry

public static int entityDeleteTry(SqlBoxContext ctx,
                                  Object entityBean,
                                  Object... optionItems)
Delete entityBean in database according primary key value


entityDeleteByIdTry

public static int entityDeleteByIdTry(SqlBoxContext ctx,
                                      Class<?> entityClass,
                                      Object id,
                                      Object... optionItems)
Try delete entity by Id, return row affected


entityLoadTry

public static int entityLoadTry(SqlBoxContext ctx,
                                Object entityBean,
                                Object... optionItems)

entityLoadByIdTry

public static <T> T entityLoadByIdTry(SqlBoxContext ctx,
                                      Class<T> entityClass,
                                      Object idOrIdMap,
                                      Object... optionItems)

entityExist

public static boolean entityExist(SqlBoxContext ctx,
                                  Object entityBean,
                                  Object... optionItems)
Check if entityBean exist in database by its id


entityExistById

public static boolean entityExistById(SqlBoxContext ctx,
                                      Class<?> entityClass,
                                      Object id,
                                      Object... optionItems)
Try delete entity by Id, return row affected


entityCountAll

public static int entityCountAll(SqlBoxContext ctx,
                                 Class<?> entityClass,
                                 Object... optionItems)
Count quantity of all entity, this method does not support sharding


entityFindAll

public static <T> List<T> entityFindAll(SqlBoxContext ctx,
                                        Class<T> entityClass,
                                        Object... optionItems)

entityFindByIds

public static <T> List<T> entityFindByIds(SqlBoxContext ctx,
                                          Class<T> entityClass,
                                          Iterable<?> ids,
                                          Object... optionItems)

entityFindBySample

public static <T> List<T> entityFindBySample(SqlBoxContext ctx,
                                             Object sampleBean,
                                             Object... sqlItems)

entityAutoNet

public static EntityNet entityAutoNet(SqlBoxContext ctx,
                                      Class<?>... entityClasses)

entityFindRelatedOne

public static <E> E entityFindRelatedOne(SqlBoxContext ctx,
                                         Object entity,
                                         Object... sqlItems)

entityFindRelatedList

public static <E> List<E> entityFindRelatedList(SqlBoxContext ctx,
                                                Object entity,
                                                Object... sqlItems)

entityFindRelatedSet

public static <E> Set<E> entityFindRelatedSet(SqlBoxContext ctx,
                                              Object entity,
                                              Object... sqlItems)

entityFindRelatedMap

public static <E> Map<Object,E> entityFindRelatedMap(SqlBoxContext ctx,
                                                     Object entity,
                                                     Object... sqlItems)


Copyright © 2018. All rights reserved.