public abstract class Dialect extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
Dialect.Holder |
Modifier and Type | Field and Description |
---|---|
protected boolean |
keepByteAndShort |
protected ModelBuilder |
modelBuilder |
protected RecordBuilder |
recordBuilder |
Constructor and Description |
---|
Dialect() |
Modifier and Type | Method and Description |
---|---|
<T> List<T> |
buildModelList(ResultSet rs,
Class<? extends Model> modelClass) |
List<Record> |
buildRecordList(Config config,
ResultSet rs) |
void |
fillStatement(PreparedStatement pst,
List<Object> paras) |
void |
fillStatement(PreparedStatement pst,
Object... paras) |
protected void |
fillStatementHandleDateType(PreparedStatement pst,
List<Object> paras)
fillStatement 时处理日期类型
|
protected void |
fillStatementHandleDateType(PreparedStatement pst,
Object... paras)
fillStatement 时处理日期类型
|
abstract String |
forDbDeleteById(String tableName,
String[] pKeys) |
abstract String |
forDbFindById(String tableName,
String[] pKeys) |
abstract void |
forDbSave(String tableName,
String[] pKeys,
Record record,
StringBuilder sql,
List<Object> paras) |
abstract void |
forDbUpdate(String tableName,
String[] pKeys,
Object[] ids,
Record record,
StringBuilder sql,
List<Object> paras) |
abstract String |
forModelDeleteById(Table table) |
abstract String |
forModelFindById(Table table,
String columns) |
abstract void |
forModelSave(Table table,
Map<String,Object> attrs,
StringBuilder sql,
List<Object> paras) |
abstract void |
forModelUpdate(Table table,
Map<String,Object> attrs,
Set<String> modifyFlag,
StringBuilder sql,
List<Object> paras) |
abstract String |
forPaginate(int pageNumber,
int pageSize,
StringBuilder findSql) |
abstract String |
forTableBuilderDoBuild(String tableName) |
String |
getDefaultPrimaryKey() |
void |
getModelGeneratedKey(Model<?> model,
PreparedStatement pst,
Table table)
用于获取 Model.save() 以后自动生成的主键值,可通过覆盖此方法实现更精细的控制
目前只有 PostgreSqlDialect,覆盖过此方法
|
void |
getRecordGeneratedKey(PreparedStatement pst,
Record record,
String[] pKeys)
用于获取 Db.save(tableName, record) 以后自动生成的主键值,可通过覆盖此方法实现更精细的控制
目前只有 PostgreSqlDialect,覆盖过此方法
|
boolean |
isKeepByteAndShort()
指示 MetaBuilder 生成的 ColumnMeta.javaType 是否保持住 Byte、Short 类型
进而 BaseModelBuilder 生成针对 Byte、Short 类型的获取方法:
getByte(String)、getShort(String)
|
boolean |
isOracle() |
boolean |
isPrimaryKey(String colName,
String[] pKeys) |
boolean |
isTakeOverDbPaginate() |
boolean |
isTakeOverModelPaginate() |
protected void |
processGeneratedBigIntegerKey(Model<?> model,
String pKey,
Object v)
mysql 数据库的 bigint unsigned 对应的 java 类型为 BigInteger
但是 rs.getObject(1) 返回值为 Long 型,造成 model.save() 以后
model.getId() 时的类型转换异常
|
String |
replaceOrderBy(String sql) |
Dialect |
setKeepByteAndShort(boolean keepByteAndShort)
指示 Generator、ModelBuilder、RecordBuilder 是否保持住 Byte、Short 类型
|
Dialect |
setModelBuilder(ModelBuilder modelBuilder)
配置自定义 ModelBuilder
通过继承扩展 ModelBuilder 可以对 JDBC 到 java 数据类型进行定制化转换
不同数据库从 JDBC 到 java 数据类型的映射关系有所不同
此外,还可以通过改变 ModelBuilder.buildLabelNamesAndTypes()
方法逻辑,实现下划线字段名转驼峰变量名的功能
|
Dialect |
setRecordBuilder(RecordBuilder recordBuilder)
配置自定义 RecordBuilder
通过继承扩展 RecordBuilder 可以对 JDBC 到 java 数据类型进行定制化转换
不同数据库从 JDBC 到 java 数据类型的映射关系有所不同
此外,还可以通过改变 RecordBuilder.buildLabelNamesAndTypes()
方法逻辑,实现下划线字段名转驼峰变量名的功能
|
Page<Record> |
takeOverDbPaginate(Connection conn,
int pageNumber,
int pageSize,
Boolean isGroupBySql,
String totalRowSql,
StringBuilder findSql,
Object... paras) |
Page |
takeOverModelPaginate(Connection conn,
Class<? extends Model> modelClass,
int pageNumber,
int pageSize,
Boolean isGroupBySql,
String totalRowSql,
StringBuilder findSql,
Object... paras) |
void |
trimPrimaryKeys(String[] pKeys)
一、forDbXxx 系列方法中若有如下两种情况之一,则需要调用此方法对 pKeys 数组进行 trim():
1:方法中调用了 isPrimaryKey(...):为了防止在主键相同情况下,由于前后空串造成 isPrimaryKey 返回 false
2:为了防止 tableName、colName 与数据库保留字冲突的,添加了包裹字符的:为了防止串包裹区内存在空串
如 mysql 使用的 "`" 字符以及 PostgreSql 使用的 "\"" 字符
不满足以上两个条件之一的 forDbXxx 系列方法也可以使用 trimPrimaryKeys(...) 方法让 sql 更加美观,但不是必须
二、forModelXxx 由于在映射时已经trim(),故不再需要调用此方法
|
protected boolean keepByteAndShort
protected ModelBuilder modelBuilder
protected RecordBuilder recordBuilder
public abstract String forPaginate(int pageNumber, int pageSize, StringBuilder findSql)
public abstract void forModelSave(Table table, Map<String,Object> attrs, StringBuilder sql, List<Object> paras)
public abstract void forModelUpdate(Table table, Map<String,Object> attrs, Set<String> modifyFlag, StringBuilder sql, List<Object> paras)
public abstract void forDbSave(String tableName, String[] pKeys, Record record, StringBuilder sql, List<Object> paras)
public abstract void forDbUpdate(String tableName, String[] pKeys, Object[] ids, Record record, StringBuilder sql, List<Object> paras)
public Dialect setKeepByteAndShort(boolean keepByteAndShort)
public boolean isKeepByteAndShort()
public Dialect setModelBuilder(ModelBuilder modelBuilder)
public Dialect setRecordBuilder(RecordBuilder recordBuilder)
public <T> List<T> buildModelList(ResultSet rs, Class<? extends Model> modelClass) throws SQLException, InstantiationException, IllegalAccessException
public List<Record> buildRecordList(Config config, ResultSet rs) throws SQLException
SQLException
public void getModelGeneratedKey(Model<?> model, PreparedStatement pst, Table table) throws SQLException
SQLException
protected void processGeneratedBigIntegerKey(Model<?> model, String pKey, Object v)
public void getRecordGeneratedKey(PreparedStatement pst, Record record, String[] pKeys) throws SQLException
SQLException
public boolean isOracle()
public boolean isTakeOverDbPaginate()
public Page<Record> takeOverDbPaginate(Connection conn, int pageNumber, int pageSize, Boolean isGroupBySql, String totalRowSql, StringBuilder findSql, Object... paras) throws SQLException
SQLException
public boolean isTakeOverModelPaginate()
public Page takeOverModelPaginate(Connection conn, Class<? extends Model> modelClass, int pageNumber, int pageSize, Boolean isGroupBySql, String totalRowSql, StringBuilder findSql, Object... paras) throws Exception
Exception
public void fillStatement(PreparedStatement pst, List<Object> paras) throws SQLException
SQLException
public void fillStatement(PreparedStatement pst, Object... paras) throws SQLException
SQLException
public String getDefaultPrimaryKey()
public void trimPrimaryKeys(String[] pKeys)
protected void fillStatementHandleDateType(PreparedStatement pst, List<Object> paras) throws SQLException
SQLException
protected void fillStatementHandleDateType(PreparedStatement pst, Object... paras) throws SQLException
SQLException
Copyright © 2018. All rights reserved.