com.github.drinkjava2.jsqlbox
Class SqlBoxContext

java.lang.Object
  extended by org.apache.commons.dbutils.AbstractQueryRunner
      extended by org.apache.commons.dbutils.QueryRunner
          extended by com.github.drinkjava2.jdbpro.ImprovedQueryRunner
              extended by com.github.drinkjava2.jdbpro.DbPro
                  extended by com.github.drinkjava2.jsqlbox.SqlBoxContext
All Implemented Interfaces:
NormalJdbcTool

public class SqlBoxContext
extends DbPro

SqlBoxContext is extended from DbPro, DbPro is extended from QueryRunner, by this way SqlBoxContext have all JDBC methods of QueryRunner and DbPro.
As a ORM tool, SqlBoxContext focus on ORM methods like entity bean's CRUD methods and EntityNet methods.

Since:
1.0.0
Author:
Yong Zhu

Field Summary
protected  Dialect dialect
          Dialect of current SqlBoxContext, optional
protected static SqlBoxContext globalSqlBoxContext
           
static String NO_GLOBAL_SQLBOXCONTEXT_FOUND
           
protected  ShardingTool[] shardingTools
           
protected  SnowflakeCreator snowflakeCreator
           
protected  SqlMapperGuesser sqlMapperGuesser
          In SqlMapper style, A guesser needed to guess and execute SQL methods
 
Fields inherited from class com.github.drinkjava2.jdbpro.ImprovedQueryRunner
allowShowSQL, batchSize, connectionManager, iocTool, logger, masters, masterSlaveOption, name, slaves, sqlHandlers, sqlTemplateEngine
 
Fields inherited from class org.apache.commons.dbutils.AbstractQueryRunner
ds
 
Constructor Summary
SqlBoxContext()
           
SqlBoxContext(DataSource ds)
           
SqlBoxContext(DataSource ds, SqlBoxContextConfig config)
           
SqlBoxContext(SqlBoxContextConfig config)
           
 
Method Summary
static
<T> T
createMapper(Class<?> abstractClass)
          Create a subClass instance of a abstract ActiveRecordSupport class based on default global SqlBoxContext
protected  boolean dealOneSqlItem(boolean iXxxStyle, PreparedSQL ps, Object item)
          Override DbPro's dealItem method to deal SqlBoxContext's SqlItem
protected  void dialectShortcutMethods__________________________()
           
 EntityNet entityAutoNet(Class<?>... entityClass)
          Build a entityNet, only give both between start class and end classes
 int entityCountAll(Class<?> entityClass, Object... optionItems)
          Return how many records for current entity class
protected  void entityCrudMethods______________________________()
           
 void entityDelete(Object entity, Object... optionItems)
          Delete entity in database, if not 1 row deleted, throw SqlBoxException
 void entityDeleteById(Class<?> entityClass, Object id, Object... optionItems)
          Delete entity by given id, if not 1 row deleted, throw SqlBoxException
 int entityDeleteByIdTry(Class<?> entityClass, Object id, Object... optionItems)
          Delete entity by given id, return how many rows deleted
 int entityDeleteTry(Object entity, Object... optionItems)
          Delete entity in database, return how many rows affected
 boolean entityExist(Object entity, Object... optionItems)
          Check if entity exist by its id
 boolean entityExistById(Class<?> entityClass, Object id, Object... optionItems)
          Check if entity exist by given id
<T> List<T>
entityFindAll(Class<T> entityClass, Object... optionItems)
          Find all entity of given entity class, if not found, return empty list
<T> List<T>
entityFindByIds(Class<T> entityClass, Iterable<?> ids, Object... optionItems)
          Find all entity according its id, if not found, return empty list
<T> List<T>
entityFindBySample(Object sampleBean, Object... optionItems)
          Find entity according a sample bean, ignore null fields, if not found, return empty list
<T> List<T>
entityFindBySQL(Object... optionItems)
          Find entity according SQL, if not found, return empty list
<E> List<E>
entityFindRelatedList(Object entityOrIterable, Object... sqlItems)
          Find related entity list by given entity or Iterable
<E> Map<Object,E>
entityFindRelatedMap(Object entity, Object... sqlItems)
          Find related entity map(key is entityID) by given entity or Iterable
<E> E
entityFindRelatedOne(Object entity, Object... sqlItems)
          Find one related entity by given entity
<E> Set<E>
entityFindRelatedSet(Object entity, Object... sqlItems)
          Find related entity set by given entity or Iterable
<T> T
entityInsert(T entity, Object... optionItems)
          Insert entity to database, if not 1 row updated, throw SqlBoxException
<T> T
entityLoad(T entity, Object... optionItems)
          Load entity according its id, if not 1 row round, throw SqlBoxException
<T> T
entityLoadById(Class<T> entityClass, Object entityId, Object... optionItems)
          Load entity by given id, if not 1 row found, throw SqlBoxException
<T> T
entityLoadByIdTry(Class<T> entityClass, Object entityId, Object... optionItems)
          Load entity by given id, if not found, return null
 int entityLoadTry(Object entity, Object... optionItems)
          Load entity according its id, return how many rows found
<T> T
entityUpdate(Object entity, Object... optionItems)
          Update entity in database, if not 1 row updated, throw SqlBoxException
 int entityUpdateTry(Object entity, Object... optionItems)
          Update entity in database, return how many rows affected
static SqlBoxContext gctx()
          Shortcut method equal to getGlobalSqlBoxContext()
 Dialect getDialect()
           
static SqlBoxContext getGlobalSqlBoxContext()
          Get the global static SqlBoxContext instance
 SqlBoxContext getShardedDB(Object entityOrClass, Object... shardvalues)
          Get the sharded DB(=SqlBoxContext) instance by given shard values
 String getShardedTB(Object entityOrClass, Object... shardvalues)
          Get the sharded table name by given shard values
 ShardingTool[] getShardingTools()
           
 SnowflakeCreator getSnowflakeCreator()
           
 SqlMapperGuesser getSqlMapperGuesser()
           
protected  void getteSetters__________________________()
           
protected  DbPro handleShardDatabase(PreparedSQL predSQL, SqlItem item)
           
protected  String handleShardTable(PreparedSQL predSQL, SqlItem item)
           
<T> List<T>
iQueryForEntityList(Object... optionItems)
          Use i style to query for an entity list
protected  void miscMethods______________________________()
           
 String pagin(int pageNumber, int pageSize, String sql)
          Shortcut call to dialect.pagin method
 String paginAndTrans(int pageNumber, int pageSize, String sql)
          Shortcut call to dialect.paginAndTrans method
<T> List<T>
pQueryForEntityList(Object... optionItems)
          Use p style to query for an entity list
static void resetGlobalVariants()
          Reset all global SqlBox variants to default values
 void setDialect(Dialect dialect)
          Deprecated. 
static void setGlobalSqlBoxContext(SqlBoxContext globalSqlBoxContext)
           
 void setShardingTools(ShardingTool[] shardingTools)
          Deprecated. 
 void setSnowflakeCreator(SnowflakeCreator snowflakeCreator)
          Deprecated. 
 void setSqlMapperGuesser(SqlMapperGuesser sqlMapperGuesser)
          Deprecated. 
 String[] toCreateDDL(Class<?>... entityClasses)
          Shortcut call to dialect.toCreateDDL method
 String[] toCreateDDL(TableModel... tables)
          Shortcut call to dialect.toCreateDDL method
 String[] toDropAndCreateDDL(Class<?>... entityClasses)
          Shortcut call to dialect.toDropAndCreateDDL method
 String[] toDropAndCreateDDL(TableModel... tables)
          Shortcut call to dialect.toDropAndCreateDDL method
 String[] toDropDDL(Class<?>... entityClasses)
          Shortcut call to dialect.toDropDDL method
 String[] toDropDDL(TableModel... tables)
          Shortcut call to dialect.toDropDDL method
<T> List<T>
tQueryForEntityList(Object... optionItems)
          Use t style to query for an entity list
 String trans(String sql)
          Shortcut call to dialect.trans method
 
Methods inherited from class com.github.drinkjava2.jdbpro.DbPro
________iXxxxStyles________, ________nXxxxStyles________, ________prepareMethods________, ________pXxxxStyles________, ________tXxxxStyles________, dealSqlItems, iExecute, iInsert, iPrepare, iQuery, iQueryForLongValue, iQueryForMapList, iQueryForObject, iQueryForString, iUpdate, nExecute, nExecute, nExecute, nExecute, nInsert, nInsert, nQuery, nQuery, nQueryForLongValue, nQueryForLongValue, nQueryForMapList, nQueryForMapList, nQueryForObject, nQueryForObject, nQueryForString, nQueryForString, nUpdate, nUpdate, pExecute, pInsert, pPrepare, pQuery, pQueryForLongValue, pQueryForMapList, pQueryForObject, pQueryForString, pUpdate, quiteExecute, tExecute, tInsert, tQuery, tQueryForLongValue, tQueryForMapList, tQueryForObject, tQueryForString, tUpdate
 
Methods inherited from class com.github.drinkjava2.jdbpro.ImprovedQueryRunner
close, fillStatement, formatParametersForLoggerOutput, formatSqlForLoggerOutput, getAllowShowSQL, getBatchSize, getConnectionManager, getIocTool, getLogger, getMasters, getMasterSlaveOption, getName, getSlaves, getSqlBatchCache, getSqlHandlers, getSqlTemplateEngine, getThreadLocalSqlHandlers, isBatchEnabled, listListToArray2D, nBatch, nBatch, nBatchBegin, nBatchEnd, nBatchFlush, nInsertBatch, nInsertBatch, objectsListToArray2D, prepareCall, prepareConnection, prepareStatement, queryForLongValue, queryForLongValue, queryForObject, queryForObject, runExecute, runInsert, runPreparedSQL, runQuery, runRealSqlMethod, runUpdate, setAllowShowSQL, setBatchSize, setConnectionManager, setIocTool, setLogger, setMasters, setMasterSlaveOption, setName, setSlaves, setSqlHandlers, setSqlTemplateEngine, setThreadLocalSqlHandlers
 
Methods inherited from class org.apache.commons.dbutils.QueryRunner
batch, batch, execute, execute, execute, execute, insert, insert, insert, insert, insertBatch, insertBatch, query, query, query, query, query, query, query, query, update, update, update, update, update, update
 
Methods inherited from class org.apache.commons.dbutils.AbstractQueryRunner
close, close, fillStatementWithBean, fillStatementWithBean, getDataSource, isPmdKnownBroken, prepareStatement, rethrow, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_GLOBAL_SQLBOXCONTEXT_FOUND

public static final String NO_GLOBAL_SQLBOXCONTEXT_FOUND
See Also:
Constant Field Values

globalSqlBoxContext

protected static SqlBoxContext globalSqlBoxContext

dialect

protected Dialect dialect
Dialect of current SqlBoxContext, optional


sqlMapperGuesser

protected SqlMapperGuesser sqlMapperGuesser
In SqlMapper style, A guesser needed to guess and execute SQL methods


shardingTools

protected ShardingTool[] shardingTools

snowflakeCreator

protected SnowflakeCreator snowflakeCreator
Constructor Detail

SqlBoxContext

public SqlBoxContext()

SqlBoxContext

public SqlBoxContext(DataSource ds)

SqlBoxContext

public SqlBoxContext(SqlBoxContextConfig config)

SqlBoxContext

public SqlBoxContext(DataSource ds,
                     SqlBoxContextConfig config)
Method Detail

miscMethods______________________________

protected void miscMethods______________________________()

resetGlobalVariants

public static void resetGlobalVariants()
Reset all global SqlBox variants to default values


gctx

public static SqlBoxContext gctx()
Shortcut method equal to getGlobalSqlBoxContext()


getGlobalSqlBoxContext

public static SqlBoxContext getGlobalSqlBoxContext()
Get the global static SqlBoxContext instance


dealOneSqlItem

protected boolean dealOneSqlItem(boolean iXxxStyle,
                                 PreparedSQL ps,
                                 Object item)
Override DbPro's dealItem method to deal SqlBoxContext's SqlItem

Overrides:
dealOneSqlItem in class DbPro

createMapper

public static <T> T createMapper(Class<?> abstractClass)
Create a subClass instance of a abstract ActiveRecordSupport class based on default global SqlBoxContext


getShardedTB

public String getShardedTB(Object entityOrClass,
                           Object... shardvalues)
Get the sharded table name by given shard values


getShardedDB

public SqlBoxContext getShardedDB(Object entityOrClass,
                                  Object... shardvalues)
Get the sharded DB(=SqlBoxContext) instance by given shard values


handleShardTable

protected String handleShardTable(PreparedSQL predSQL,
                                  SqlItem item)

handleShardDatabase

protected DbPro handleShardDatabase(PreparedSQL predSQL,
                                    SqlItem item)

iQueryForEntityList

public <T> List<T> iQueryForEntityList(Object... optionItems)
Use i style to query for an entity list


pQueryForEntityList

public <T> List<T> pQueryForEntityList(Object... optionItems)
Use p style to query for an entity list


tQueryForEntityList

public <T> List<T> tQueryForEntityList(Object... optionItems)
Use t style to query for an entity list


entityCrudMethods______________________________

protected void entityCrudMethods______________________________()

entityInsert

public <T> T entityInsert(T entity,
                          Object... optionItems)
Insert entity to database, if not 1 row updated, throw SqlBoxException


entityUpdate

public <T> T entityUpdate(Object entity,
                          Object... optionItems)
Update entity in database, if not 1 row updated, throw SqlBoxException


entityUpdateTry

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


entityDelete

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


entityDeleteTry

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


entityDeleteById

public void entityDeleteById(Class<?> entityClass,
                             Object id,
                             Object... optionItems)
Delete entity by given id, if not 1 row deleted, throw SqlBoxException


entityDeleteByIdTry

public int entityDeleteByIdTry(Class<?> entityClass,
                               Object id,
                               Object... optionItems)
Delete entity by given id, return how many rows deleted


entityExist

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


entityExistById

public boolean entityExistById(Class<?> entityClass,
                               Object id,
                               Object... optionItems)
Check if entity exist by given id


entityCountAll

public int entityCountAll(Class<?> entityClass,
                          Object... optionItems)
Return how many records for current entity class


entityLoad

public <T> T entityLoad(T entity,
                        Object... optionItems)
Load entity according its id, if not 1 row round, throw SqlBoxException


entityLoadTry

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


entityLoadById

public <T> T entityLoadById(Class<T> entityClass,
                            Object entityId,
                            Object... optionItems)
Load entity by given id, if not 1 row found, throw SqlBoxException


entityLoadByIdTry

public <T> T entityLoadByIdTry(Class<T> entityClass,
                               Object entityId,
                               Object... optionItems)
Load entity by given id, if not found, return null


entityFindAll

public <T> List<T> entityFindAll(Class<T> entityClass,
                                 Object... optionItems)
Find all entity of given entity class, if not found, return empty list


entityFindByIds

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


entityFindBySQL

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


entityFindBySample

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


entityAutoNet

public EntityNet entityAutoNet(Class<?>... entityClass)
Build a entityNet, only give both between start class and end classes


entityFindRelatedOne

public <E> E entityFindRelatedOne(Object entity,
                                  Object... sqlItems)
Find one related entity by given entity


entityFindRelatedList

public <E> List<E> entityFindRelatedList(Object entityOrIterable,
                                         Object... sqlItems)
Find related entity list by given entity or Iterable


entityFindRelatedSet

public <E> Set<E> entityFindRelatedSet(Object entity,
                                       Object... sqlItems)
Find related entity set by given entity or Iterable


entityFindRelatedMap

public <E> Map<Object,E> entityFindRelatedMap(Object entity,
                                              Object... sqlItems)
Find related entity map(key is entityID) by given entity or Iterable


dialectShortcutMethods__________________________

protected void dialectShortcutMethods__________________________()

pagin

public String pagin(int pageNumber,
                    int pageSize,
                    String sql)
Shortcut call to dialect.pagin method


trans

public String trans(String sql)
Shortcut call to dialect.trans method


paginAndTrans

public String paginAndTrans(int pageNumber,
                            int pageSize,
                            String sql)
Shortcut call to dialect.paginAndTrans method


toCreateDDL

public String[] toCreateDDL(Class<?>... entityClasses)
Shortcut call to dialect.toCreateDDL method


toDropDDL

public String[] toDropDDL(Class<?>... entityClasses)
Shortcut call to dialect.toDropDDL method


toDropAndCreateDDL

public String[] toDropAndCreateDDL(Class<?>... entityClasses)
Shortcut call to dialect.toDropAndCreateDDL method


toCreateDDL

public String[] toCreateDDL(TableModel... tables)
Shortcut call to dialect.toCreateDDL method


toDropDDL

public String[] toDropDDL(TableModel... tables)
Shortcut call to dialect.toDropDDL method


toDropAndCreateDDL

public String[] toDropAndCreateDDL(TableModel... tables)
Shortcut call to dialect.toDropAndCreateDDL method


getteSetters__________________________

protected void getteSetters__________________________()

getDialect

public Dialect getDialect()

setDialect

@Deprecated
public void setDialect(Dialect dialect)
Deprecated. 

This method is not thread safe, suggest only use at program starting


getSqlMapperGuesser

public SqlMapperGuesser getSqlMapperGuesser()

setSqlMapperGuesser

@Deprecated
public void setSqlMapperGuesser(SqlMapperGuesser sqlMapperGuesser)
Deprecated. 

This method is not thread safe, suggest only use at program starting


getShardingTools

public ShardingTool[] getShardingTools()

setShardingTools

@Deprecated
public void setShardingTools(ShardingTool[] shardingTools)
Deprecated. 

This method is not thread safe, suggest only use at program starting


getSnowflakeCreator

public SnowflakeCreator getSnowflakeCreator()

setSnowflakeCreator

@Deprecated
public void setSnowflakeCreator(SnowflakeCreator snowflakeCreator)
Deprecated. 

This method is not thread safe, suggest only use at program starting


setGlobalSqlBoxContext

public static void setGlobalSqlBoxContext(SqlBoxContext globalSqlBoxContext)


Copyright © 2018. All rights reserved.