Search in sources :

Example 66 with SqlToyConfig

use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.

the class TidbDialect method load.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.sagacity.sqltoy.dialect.Dialect#load(java.io.Serializable,
	 * java.util.List, java.sql.Connection)
	 */
@Override
public Serializable load(final SqlToyContext sqlToyContext, Serializable entity, List<Class> cascadeTypes, LockMode lockMode, Connection conn, final Integer dbType, final String dialect, final String tableName) throws Exception {
    EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
    // 获取loadsql(loadsql 可以通过@loadSql进行改变,所以需要sqltoyContext重新获取)
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(entityMeta.getLoadSql(tableName), SqlType.search, dialect);
    String loadSql = sqlToyConfig.getSql(dialect);
    loadSql = loadSql.concat(getLockSql(loadSql, dbType, lockMode));
    return (Serializable) DialectUtils.load(sqlToyContext, sqlToyConfig, loadSql, entityMeta, entity, cascadeTypes, conn, dbType);
}
Also used : EntityMeta(org.sagacity.sqltoy.config.model.EntityMeta) Serializable(java.io.Serializable) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig)

Example 67 with SqlToyConfig

use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.

the class Query method findTop.

/**
 * @todo 取前多少条记录
 * @param topSize
 * @return
 */
public List<?> findTop(final double topSize) {
    QueryExecutor queryExecute = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(queryExecute, SqlType.search, getDialect());
    QueryResult result = dialectFactory.findTop(sqlToyContext, queryExecute, sqlToyConfig, topSize, getDataSource(sqlToyConfig));
    return result.getRows();
}
Also used : QueryResult(org.sagacity.sqltoy.model.QueryResult) QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig)

Example 68 with SqlToyConfig

use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.

the class Query method count.

/**
 * @todo 查询记录集的数量
 * @return
 */
public Long count() {
    QueryExecutor queryExecute = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(queryExecute, SqlType.search, getDialect());
    return dialectFactory.getCountBySql(sqlToyContext, queryExecute, sqlToyConfig, getDataSource(sqlToyConfig));
}
Also used : QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig)

Example 69 with SqlToyConfig

use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.

the class Query method getValue.

/**
 * @todo 获取单值
 * @return
 */
public Object getValue() {
    QueryExecutor queryExecute = new QueryExecutor(sql).names(names).values(values);
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(queryExecute, SqlType.search, getDialect());
    QueryResult result = dialectFactory.findByQuery(sqlToyContext, queryExecute, sqlToyConfig, null, getDataSource(sqlToyConfig));
    List rows = result.getRows();
    if (rows != null && rows.size() > 0) {
        return ((List) rows.get(0)).get(0);
    }
    return null;
}
Also used : QueryResult(org.sagacity.sqltoy.model.QueryResult) QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig) List(java.util.List)

Example 70 with SqlToyConfig

use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.

the class Query method findPage.

/**
 * @TODO 进行分页查询
 * @param page
 * @return
 */
public Page<?> findPage(final Page page) {
    QueryExecutor queryExecute = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(queryExecute, SqlType.search, getDialect());
    if (page.getSkipQueryCount()) {
        return (Page<?>) dialectFactory.findSkipTotalCountPage(sqlToyContext, queryExecute, sqlToyConfig, page.getPageNo(), page.getPageSize(), getDataSource(sqlToyConfig)).getPageResult();
    }
    return (Page<?>) dialectFactory.findPage(sqlToyContext, queryExecute, sqlToyConfig, page.getPageNo(), page.getPageSize(), getDataSource(sqlToyConfig)).getPageResult();
}
Also used : QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig) Page(org.sagacity.sqltoy.model.Page)

Aggregations

SqlToyConfig (org.sagacity.sqltoy.config.model.SqlToyConfig)82 EntityMeta (org.sagacity.sqltoy.config.model.EntityMeta)22 Serializable (java.io.Serializable)20 QueryExecutor (org.sagacity.sqltoy.model.QueryExecutor)20 QueryResult (org.sagacity.sqltoy.model.QueryResult)20 Connection (java.sql.Connection)19 ArrayList (java.util.ArrayList)19 DataSourceCallbackHandler (org.sagacity.sqltoy.callback.DataSourceCallbackHandler)19 List (java.util.List)16 DataAccessException (org.sagacity.sqltoy.exception.DataAccessException)16 QueryExecutorExtend (org.sagacity.sqltoy.model.inner.QueryExecutorExtend)15 SqlToyResult (org.sagacity.sqltoy.config.model.SqlToyResult)12 BaseException (org.sagacity.sqltoy.exception.BaseException)10 NoSqlConfigModel (org.sagacity.sqltoy.config.model.NoSqlConfigModel)5 DataSource (javax.sql.DataSource)4 Test (org.junit.jupiter.api.Test)4 ParallQueryExecutor (org.sagacity.sqltoy.dialect.executor.ParallQueryExecutor)4 QueryExecutor (org.sagacity.sqltoy.executor.QueryExecutor)4 InputStream (java.io.InputStream)3 Document (org.w3c.dom.Document)3