Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MaxKey单点登录官方(MaxKeyTop)
Mybatis Jpa Extra
提交
84852be4
M
Mybatis Jpa Extra
项目概览
MaxKey单点登录官方(MaxKeyTop)
/
Mybatis Jpa Extra
8 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Mybatis Jpa Extra
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
84852be4
编写于
3月 23, 2019
作者:
MaxKey单点登录官方
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
c
上级
0e34bb90
变更
21
展开全部
隐藏空白更改
内联
并排
Showing
21 changed file
with
4383 addition
and
4362 deletion
+4383
-4362
.gitignore
.gitignore
+4
-3
mybatis-jpa-extra-2.1-api/.classpath
mybatis-jpa-extra-2.1-api/.classpath
+28
-26
mybatis-jpa-extra-2.1-api/.settings/org.eclipse.core.resources.prefs
...-extra-2.1-api/.settings/org.eclipse.core.resources.prefs
+4
-4
mybatis-jpa-extra-2.1-api/.settings/org.eclipse.jdt.core.prefs
...is-jpa-extra-2.1-api/.settings/org.eclipse.jdt.core.prefs
+14
-13
mybatis-jpa-extra-core/.classpath
mybatis-jpa-extra-core/.classpath
+34
-31
mybatis-jpa-extra-core/.settings/org.eclipse.core.resources.prefs
...jpa-extra-core/.settings/org.eclipse.core.resources.prefs
+5
-5
mybatis-jpa-extra-core/.settings/org.eclipse.jdt.core.prefs
mybatis-jpa-extra-core/.settings/org.eclipse.jdt.core.prefs
+6
-5
mybatis-jpa-extra-core/logs/mybatis-jpa-extra-Out.log
mybatis-jpa-extra-core/logs/mybatis-jpa-extra-Out.log
+2821
-2805
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/AllStatementHandlerInterceptor.java
...rg/apache/mybatis/jpa/AllStatementHandlerInterceptor.java
+108
-108
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/StatementHandlerInterceptor.java
...a/org/apache/mybatis/jpa/StatementHandlerInterceptor.java
+72
-72
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/DB2Dialect.java
.../main/java/org/apache/mybatis/jpa/dialect/DB2Dialect.java
+78
-78
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/DerbyDialect.java
...ain/java/org/apache/mybatis/jpa/dialect/DerbyDialect.java
+76
-76
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/Dialect.java
...src/main/java/org/apache/mybatis/jpa/dialect/Dialect.java
+92
-92
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/MySQLDialect.java
...ain/java/org/apache/mybatis/jpa/dialect/MySQLDialect.java
+76
-76
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/OracleDialect.java
...in/java/org/apache/mybatis/jpa/dialect/OracleDialect.java
+76
-76
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/PostgreSQLDialect.java
...ava/org/apache/mybatis/jpa/dialect/PostgreSQLDialect.java
+69
-69
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/SQLServerDialect.java
...java/org/apache/mybatis/jpa/dialect/SQLServerDialect.java
+76
-76
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/MapperSqlProvider.java
...org/apache/mybatis/jpa/persistence/MapperSqlProvider.java
+299
-302
mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/dao/service/StudentsService.java
.../apache/mybatis/jpa/test/dao/service/StudentsService.java
+28
-28
mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/domain/DemoDomain.java
...t/java/org/apache/mybatis/jpa/test/domain/DemoDomain.java
+273
-273
mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/domain/Students.java
...est/java/org/apache/mybatis/jpa/test/domain/Students.java
+144
-144
未找到文件。
.gitignore
浏览文件 @
84852be4
*.class
mybatis-jpa-extra-core/target/*
mybatis-jpa-extra-2.1-api/target/*
\ No newline at end of file
*.class
mybatis-jpa-extra-core/target/*
mybatis-jpa-extra-2.1-api/target/*
/.metadata/
mybatis-jpa-extra-2.1-api/.classpath
浏览文件 @
84852be4
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"src"
output=
"target/classes"
path=
"src/main/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
including=
"**/*.java"
kind=
"src"
output=
"target/test-classes"
path=
"src/test/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"output"
path=
"target/classes"
/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"src"
output=
"target/classes"
path=
"src/main/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
including=
"**/*.java"
kind=
"src"
output=
"target/test-classes"
path=
"src/test/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
<attribute
name=
"test"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.junit.JUNIT_CONTAINER/4"
/>
<classpathentry
kind=
"output"
path=
"target/classes"
/>
</classpath>
mybatis-jpa-extra-2.1-api/.settings/org.eclipse.core.resources.prefs
浏览文件 @
84852be4
eclipse.preferences.version=1
encoding//src/main/java=utf8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
encoding//src/main/java=utf8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
mybatis-jpa-extra-2.1-api/.settings/org.eclipse.jdt.core.prefs
浏览文件 @
84852be4
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.6
mybatis-jpa-extra-core/.classpath
浏览文件 @
84852be4
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"src"
output=
"target/classes"
path=
"src/main/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
including=
"**/*.java"
kind=
"src"
output=
"target/test-classes"
path=
"src/test/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
excluding=
"**"
kind=
"src"
output=
"target/test-classes"
path=
"src/test/resources"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"output"
path=
"target/classes"
/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"src"
output=
"target/classes"
path=
"src/main/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
including=
"**/*.java"
kind=
"src"
output=
"target/test-classes"
path=
"src/test/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
<attribute
name=
"test"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
excluding=
"**"
kind=
"src"
output=
"target/test-classes"
path=
"src/test/resources"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
<attribute
name=
"test"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.junit.JUNIT_CONTAINER/5"
/>
<classpathentry
kind=
"output"
path=
"target/classes"
/>
</classpath>
mybatis-jpa-extra-core/.settings/org.eclipse.core.resources.prefs
浏览文件 @
84852be4
eclipse.preferences.version=1
encoding//src/main/java=utf8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
encoding//src/main/java=utf8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
mybatis-jpa-extra-core/.settings/org.eclipse.jdt.core.prefs
浏览文件 @
84852be4
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.6
mybatis-jpa-extra-core/logs/mybatis-jpa-extra-Out.log
浏览文件 @
84852be4
此差异已折叠。
点击以展开。
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/AllStatementHandlerInterceptor.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa
;
import
java.lang.reflect.Method
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.Statement
;
import
java.util.List
;
import
java.util.Properties
;
import
org.apache.ibatis.executor.resultset.ResultSetHandler
;
import
org.apache.ibatis.executor.statement.PreparedStatementHandler
;
import
org.apache.ibatis.executor.statement.SimpleStatementHandler
;
import
org.apache.ibatis.executor.statement.StatementHandler
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.mapping.ParameterMapping
;
import
org.apache.ibatis.plugin.Interceptor
;
import
org.apache.ibatis.plugin.Intercepts
;
import
org.apache.ibatis.plugin.Invocation
;
import
org.apache.ibatis.plugin.Plugin
;
import
org.apache.ibatis.plugin.Signature
;
import
org.apache.ibatis.reflection.MetaObject
;
import
org.apache.ibatis.reflection.SystemMetaObject
;
import
org.apache.ibatis.session.RowBounds
;
import
org.apache.mybatis.jpa.
domain.BaseDomain
;
@Intercepts
({
@Signature
(
type
=
StatementHandler
.
class
,
method
=
"prepare"
,
args
=
{
Connection
.
class
,
Integer
.
class
}),
@Signature
(
type
=
StatementHandler
.
class
,
method
=
"parameterize"
,
args
=
{
Statement
.
class
}),
@Signature
(
type
=
ResultSetHandler
.
class
,
method
=
"handleResultSets"
,
args
=
{
Statement
.
class
})
})
public
class
AllStatementHandlerInterceptor
extends
AbstractStatementHandlerInterceptor
implements
Interceptor
{
public
Object
intercept
(
Invocation
invocation
)
throws
Throwable
{
Method
m
=
invocation
.
getMethod
();
if
(
"prepare"
.
equals
(
m
.
getName
()))
{
// һ���������Statement
return
prepare
(
invocation
);
}
else
if
(
"parameterize"
.
equals
(
m
.
getName
()))
{
// һ���������ò���
return
parameterize
(
invocation
);
}
else
if
(
"handleResultSets"
.
equals
(
m
.
getName
()))
{
// handleResultSets
return
handleResultSets
(
invocation
);
}
return
invocation
.
proceed
();
}
public
Object
plugin
(
Object
target
)
{
return
Plugin
.
wrap
(
target
,
this
);
}
public
void
setProperties
(
Properties
properties
)
{
}
private
Object
prepare
(
Invocation
invocation
)
throws
Throwable
{
StatementHandler
statement
=
getStatementHandler
(
invocation
);
if
(
statement
instanceof
SimpleStatementHandler
||
statement
instanceof
PreparedStatementHandler
)
{
MetaObject
metaObject
=
SystemMetaObject
.
forObject
(
statement
);
Object
parameterObject
=
metaObject
.
getValue
(
"parameterHandler.parameterObject"
);
BoundSql
boundSql
=
statement
.
getBoundSql
();
String
sql
=
boundSql
.
getSql
();
_logger
.
debug
(
"prepare boundSql : "
+
sql
);
_logger
.
debug
(
"startsWith SELECT : "
+
sql
.
toUpperCase
().
trim
().
startsWith
(
"SELECT"
));
if
(
sql
.
toUpperCase
().
trim
().
startsWith
(
"SELECT"
)
&&
(
parameterObject
instanceof
BaseDomain
))
{
if
(
statement
instanceof
SimpleStatementHandler
){
sql
=
dialect
.
getLimitString
(
sql
,
(
BaseDomain
)
parameterObject
);
}
else
if
(
statement
instanceof
PreparedStatementHandler
){
sql
=
dialect
.
getPreparedStatementLimitString
(
sql
,
(
BaseDomain
)
parameterObject
);
}
}
metaObject
.
setValue
(
"boundSql.sql"
,
sql
);
}
return
invocation
.
proceed
();
}
private
Object
parameterize
(
Invocation
invocation
)
throws
Throwable
{
Statement
statement
=
(
Statement
)
invocation
.
getArgs
()[
0
];
if
(
statement
instanceof
PreparedStatement
)
{
PreparedStatement
ps
=
(
PreparedStatement
)
statement
;
StatementHandler
statementHandler
=
getStatementHandler
(
invocation
);
RowBounds
rowBounds
=
getRowBounds
(
statementHandler
);
_logger
.
debug
(
rowBounds
.
toString
());
MetaObject
metaObject
=
SystemMetaObject
.
forObject
(
statementHandler
);
Object
parameterObject
=
metaObject
.
getValue
(
"parameterHandler.parameterObject"
);
BoundSql
boundSql
=
statementHandler
.
getBoundSql
();
if
(
boundSql
.
getSql
().
toUpperCase
().
trim
().
startsWith
(
"SELECT"
)
&&
(
parameterObject
instanceof
BaseDomain
))
{
List
<
ParameterMapping
>
pms
=
boundSql
.
getParameterMappings
();
System
.
out
.
println
(
pms
);
int
parameterSize
=
pms
.
size
();
dialect
.
setLimitParamters
(
ps
,
parameterSize
,(
BaseDomain
)
parameterObject
);
}
}
return
invocation
.
proceed
();
}
private
Object
handleResultSets
(
Invocation
invocation
)
throws
Throwable
{
//ResultSetHandler resultSetHandler = (ResultSetHandler) invocation.getTarget();
//MetaObject metaObject=MetaObject.forObject(resultSetHandler);
//RowBounds rowBounds=(RowBounds)metaObject.getValue("rowBounds");
//if (rowBounds.getLimit() > 0&& rowBounds.getLimit() < RowBounds.NO_ROW_LIMIT) {
// metaObject.setValue("rowBounds", RowBounds.DEFAULT);
//}
return
invocation
.
proceed
();
}
package
org.apache.mybatis.jpa
;
import
java.lang.reflect.Method
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.Statement
;
import
java.util.List
;
import
java.util.Properties
;
import
org.apache.ibatis.executor.resultset.ResultSetHandler
;
import
org.apache.ibatis.executor.statement.PreparedStatementHandler
;
import
org.apache.ibatis.executor.statement.SimpleStatementHandler
;
import
org.apache.ibatis.executor.statement.StatementHandler
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.mapping.ParameterMapping
;
import
org.apache.ibatis.plugin.Interceptor
;
import
org.apache.ibatis.plugin.Intercepts
;
import
org.apache.ibatis.plugin.Invocation
;
import
org.apache.ibatis.plugin.Plugin
;
import
org.apache.ibatis.plugin.Signature
;
import
org.apache.ibatis.reflection.MetaObject
;
import
org.apache.ibatis.reflection.SystemMetaObject
;
import
org.apache.ibatis.session.RowBounds
;
import
org.apache.mybatis.jpa.
persistence.JpaBaseDomain
;
@Intercepts
({
@Signature
(
type
=
StatementHandler
.
class
,
method
=
"prepare"
,
args
=
{
Connection
.
class
,
Integer
.
class
}),
@Signature
(
type
=
StatementHandler
.
class
,
method
=
"parameterize"
,
args
=
{
Statement
.
class
}),
@Signature
(
type
=
ResultSetHandler
.
class
,
method
=
"handleResultSets"
,
args
=
{
Statement
.
class
})
})
public
class
AllStatementHandlerInterceptor
extends
AbstractStatementHandlerInterceptor
implements
Interceptor
{
public
Object
intercept
(
Invocation
invocation
)
throws
Throwable
{
Method
m
=
invocation
.
getMethod
();
if
(
"prepare"
.
equals
(
m
.
getName
()))
{
// һ���������Statement
return
prepare
(
invocation
);
}
else
if
(
"parameterize"
.
equals
(
m
.
getName
()))
{
// һ���������ò���
return
parameterize
(
invocation
);
}
else
if
(
"handleResultSets"
.
equals
(
m
.
getName
()))
{
// handleResultSets
return
handleResultSets
(
invocation
);
}
return
invocation
.
proceed
();
}
public
Object
plugin
(
Object
target
)
{
return
Plugin
.
wrap
(
target
,
this
);
}
public
void
setProperties
(
Properties
properties
)
{
}
private
Object
prepare
(
Invocation
invocation
)
throws
Throwable
{
StatementHandler
statement
=
getStatementHandler
(
invocation
);
if
(
statement
instanceof
SimpleStatementHandler
||
statement
instanceof
PreparedStatementHandler
)
{
MetaObject
metaObject
=
SystemMetaObject
.
forObject
(
statement
);
Object
parameterObject
=
metaObject
.
getValue
(
"parameterHandler.parameterObject"
);
BoundSql
boundSql
=
statement
.
getBoundSql
();
String
sql
=
boundSql
.
getSql
();
_logger
.
debug
(
"prepare boundSql : "
+
sql
);
_logger
.
debug
(
"startsWith SELECT : "
+
sql
.
toUpperCase
().
trim
().
startsWith
(
"SELECT"
));
if
(
sql
.
toUpperCase
().
trim
().
startsWith
(
"SELECT"
)
&&
(
parameterObject
instanceof
JpaBaseDomain
))
{
if
(
statement
instanceof
SimpleStatementHandler
){
sql
=
dialect
.
getLimitString
(
sql
,
(
JpaBaseDomain
)
parameterObject
);
}
else
if
(
statement
instanceof
PreparedStatementHandler
){
sql
=
dialect
.
getPreparedStatementLimitString
(
sql
,
(
JpaBaseDomain
)
parameterObject
);
}
}
metaObject
.
setValue
(
"boundSql.sql"
,
sql
);
}
return
invocation
.
proceed
();
}
private
Object
parameterize
(
Invocation
invocation
)
throws
Throwable
{
Statement
statement
=
(
Statement
)
invocation
.
getArgs
()[
0
];
if
(
statement
instanceof
PreparedStatement
)
{
PreparedStatement
ps
=
(
PreparedStatement
)
statement
;
StatementHandler
statementHandler
=
getStatementHandler
(
invocation
);
RowBounds
rowBounds
=
getRowBounds
(
statementHandler
);
_logger
.
debug
(
rowBounds
.
toString
());
MetaObject
metaObject
=
SystemMetaObject
.
forObject
(
statementHandler
);
Object
parameterObject
=
metaObject
.
getValue
(
"parameterHandler.parameterObject"
);
BoundSql
boundSql
=
statementHandler
.
getBoundSql
();
if
(
boundSql
.
getSql
().
toUpperCase
().
trim
().
startsWith
(
"SELECT"
)
&&
(
parameterObject
instanceof
JpaBaseDomain
))
{
List
<
ParameterMapping
>
pms
=
boundSql
.
getParameterMappings
();
System
.
out
.
println
(
pms
);
int
parameterSize
=
pms
.
size
();
dialect
.
setLimitParamters
(
ps
,
parameterSize
,(
JpaBaseDomain
)
parameterObject
);
}
}
return
invocation
.
proceed
();
}
private
Object
handleResultSets
(
Invocation
invocation
)
throws
Throwable
{
//ResultSetHandler resultSetHandler = (ResultSetHandler) invocation.getTarget();
//MetaObject metaObject=MetaObject.forObject(resultSetHandler);
//RowBounds rowBounds=(RowBounds)metaObject.getValue("rowBounds");
//if (rowBounds.getLimit() > 0&& rowBounds.getLimit() < RowBounds.NO_ROW_LIMIT) {
// metaObject.setValue("rowBounds", RowBounds.DEFAULT);
//}
return
invocation
.
proceed
();
}
}
\ No newline at end of file
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/StatementHandlerInterceptor.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa
;
import
java.lang.reflect.Method
;
import
java.sql.Connection
;
import
java.util.Properties
;
import
org.apache.ibatis.executor.statement.PreparedStatementHandler
;
import
org.apache.ibatis.executor.statement.SimpleStatementHandler
;
import
org.apache.ibatis.executor.statement.StatementHandler
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.plugin.Interceptor
;
import
org.apache.ibatis.plugin.Intercepts
;
import
org.apache.ibatis.plugin.Invocation
;
import
org.apache.ibatis.plugin.Plugin
;
import
org.apache.ibatis.plugin.Signature
;
import
org.apache.ibatis.reflection.MetaObject
;
import
org.apache.ibatis.reflection.SystemMetaObject
;
import
org.apache.mybatis.jpa.
domain.Pagination
;
import
org.apache.mybatis.jpa.
service.JpaBaseService
;
@Intercepts
(
{
@Signature
(
type
=
StatementHandler
.
class
,
method
=
"prepare"
,
args
=
{
Connection
.
class
,
Integer
.
class
})})
public
class
StatementHandlerInterceptor
extends
AbstractStatementHandlerInterceptor
implements
Interceptor
{
public
Object
intercept
(
Invocation
invocation
)
throws
Throwable
{
Method
m
=
invocation
.
getMethod
();
if
(
"prepare"
.
equals
(
m
.
getName
()))
{
return
prepare
(
invocation
);
}
return
invocation
.
proceed
();
}
public
Object
plugin
(
Object
target
)
{
return
Plugin
.
wrap
(
target
,
this
);
}
public
void
setProperties
(
Properties
properties
)
{
}
private
Object
prepare
(
Invocation
invocation
)
throws
Throwable
{
StatementHandler
statement
=
getStatementHandler
(
invocation
);
if
(
statement
instanceof
SimpleStatementHandler
||
statement
instanceof
PreparedStatementHandler
)
{
MetaObject
metaObject
=
SystemMetaObject
.
forObject
(
statement
);
Object
parameterObject
=
metaObject
.
getValue
(
"parameterHandler.parameterObject"
);
BoundSql
boundSql
=
statement
.
getBoundSql
();
String
sql
=
boundSql
.
getSql
();
//log.debug("prepare boundSql ==> "+removeBreakingWhitespace(sql));
//log.debug("prepare boundSql ==> "+parameterObject);
if
((
parameterObject
instanceof
Pagination
)
&&
(
sql
.
toUpperCase
().
trim
().
startsWith
(
"SELECT"
))
)
{
Pagination
pagination
=(
Pagination
)
parameterObject
;
if
(
pagination
.
isPageable
()){
//log.debug("startsWith SELECT : "+sql.toUpperCase().trim().startsWith("SELECT"));
_logger
.
debug
(
"prepare boundSql ==> "
+
removeBreakingWhitespace
(
sql
));
if
(
statement
instanceof
SimpleStatementHandler
){
sql
=
dialect
.
getLimitString
(
sql
,
pagination
);
}
else
if
(
statement
instanceof
PreparedStatementHandler
){
JpaBaseService
.
pageResultsBoundSqlCache
.
put
(
pagination
.
getPageResultSelectUUID
(),
new
PageResultsSqlCache
(
sql
,
boundSql
));
sql
=
dialect
.
getLimitString
(
sql
,
pagination
);
}
_logger
.
debug
(
"prepare dialect boundSql : "
+
removeBreakingWhitespace
(
sql
));
metaObject
.
setValue
(
"boundSql.sql"
,
sql
);
}
}
}
return
invocation
.
proceed
();
}
package
org.apache.mybatis.jpa
;
import
java.lang.reflect.Method
;
import
java.sql.Connection
;
import
java.util.Properties
;
import
org.apache.ibatis.executor.statement.PreparedStatementHandler
;
import
org.apache.ibatis.executor.statement.SimpleStatementHandler
;
import
org.apache.ibatis.executor.statement.StatementHandler
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.plugin.Interceptor
;
import
org.apache.ibatis.plugin.Intercepts
;
import
org.apache.ibatis.plugin.Invocation
;
import
org.apache.ibatis.plugin.Plugin
;
import
org.apache.ibatis.plugin.Signature
;
import
org.apache.ibatis.reflection.MetaObject
;
import
org.apache.ibatis.reflection.SystemMetaObject
;
import
org.apache.mybatis.jpa.
persistence.JpaBaseService
;
import
org.apache.mybatis.jpa.
persistence.JpaPagination
;
@Intercepts
(
{
@Signature
(
type
=
StatementHandler
.
class
,
method
=
"prepare"
,
args
=
{
Connection
.
class
,
Integer
.
class
})})
public
class
StatementHandlerInterceptor
extends
AbstractStatementHandlerInterceptor
implements
Interceptor
{
public
Object
intercept
(
Invocation
invocation
)
throws
Throwable
{
Method
m
=
invocation
.
getMethod
();
if
(
"prepare"
.
equals
(
m
.
getName
()))
{
return
prepare
(
invocation
);
}
return
invocation
.
proceed
();
}
public
Object
plugin
(
Object
target
)
{
return
Plugin
.
wrap
(
target
,
this
);
}
public
void
setProperties
(
Properties
properties
)
{
}
private
Object
prepare
(
Invocation
invocation
)
throws
Throwable
{
StatementHandler
statement
=
getStatementHandler
(
invocation
);
if
(
statement
instanceof
SimpleStatementHandler
||
statement
instanceof
PreparedStatementHandler
)
{
MetaObject
metaObject
=
SystemMetaObject
.
forObject
(
statement
);
Object
parameterObject
=
metaObject
.
getValue
(
"parameterHandler.parameterObject"
);
BoundSql
boundSql
=
statement
.
getBoundSql
();
String
sql
=
boundSql
.
getSql
();
//log.debug("prepare boundSql ==> "+removeBreakingWhitespace(sql));
//log.debug("prepare boundSql ==> "+parameterObject);
if
((
parameterObject
instanceof
JpaPagination
)
&&
(
sql
.
toUpperCase
().
trim
().
startsWith
(
"SELECT"
))
)
{
JpaPagination
pagination
=(
JpaPagination
)
parameterObject
;
if
(
pagination
.
isPageable
()){
//log.debug("startsWith SELECT : "+sql.toUpperCase().trim().startsWith("SELECT"));
_logger
.
debug
(
"prepare boundSql ==> "
+
removeBreakingWhitespace
(
sql
));
if
(
statement
instanceof
SimpleStatementHandler
){
sql
=
dialect
.
getLimitString
(
sql
,
pagination
);
}
else
if
(
statement
instanceof
PreparedStatementHandler
){
JpaBaseService
.
pageResultsBoundSqlCache
.
put
(
pagination
.
getPageResultSelectUUID
(),
new
PageResultsSqlCache
(
sql
,
boundSql
));
sql
=
dialect
.
getLimitString
(
sql
,
pagination
);
}
_logger
.
debug
(
"prepare dialect boundSql : "
+
removeBreakingWhitespace
(
sql
));
metaObject
.
setValue
(
"boundSql.sql"
,
sql
);
}
}
}
return
invocation
.
proceed
();
}
}
\ No newline at end of file
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/DB2Dialect.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
domain.Pagination
;
public
class
DB2Dialect
extends
Dialect
{
public
DB2Dialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
@Override
public
String
getLimitString
(
String
sql
,
Pagination
pagination
)
{
if
(
pagination
.
getPageResults
()
==
0
)
{
return
sql
+
" fetch first "
+
pagination
.
getStartRow
()
+
" rows only"
;
}
StringBuilder
pagingSelectSql
=
new
StringBuilder
(
sql
.
length
()
+
200
)
.
append
(
"select * from ( select inner2_.*, rownumber() over(order by order of inner2_) as rownumber_ from ( "
)
.
append
(
sql
)
//nest the main query in an outer select
.
append
(
" fetch first "
)
.
append
(
pagination
.
getPageResults
())
.
append
(
" rows only ) as inner2_ ) as inner1_ where rownumber_ > "
)
.
append
(
pagination
.
getStartRow
())
.
append
(
" order by rownumber_"
);
return
pagingSelectSql
.
toString
();
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
Pagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
Pagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"DB2Dialect ["
+
DB2Dialect
.
class
+
"]"
;
}
}
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
persistence.JpaPagination
;
public
class
DB2Dialect
extends
Dialect
{
public
DB2Dialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
@Override
public
String
getLimitString
(
String
sql
,
JpaPagination
pagination
)
{
if
(
pagination
.
getPageResults
()
==
0
)
{
return
sql
+
" fetch first "
+
pagination
.
getStartRow
()
+
" rows only"
;
}
StringBuilder
pagingSelectSql
=
new
StringBuilder
(
sql
.
length
()
+
200
)
.
append
(
"select * from ( select inner2_.*, rownumber() over(order by order of inner2_) as rownumber_ from ( "
)
.
append
(
sql
)
//nest the main query in an outer select
.
append
(
" fetch first "
)
.
append
(
pagination
.
getPageResults
())
.
append
(
" rows only ) as inner2_ ) as inner1_ where rownumber_ > "
)
.
append
(
pagination
.
getStartRow
())
.
append
(
" order by rownumber_"
);
return
pagingSelectSql
.
toString
();
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
JpaPagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
JpaPagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"DB2Dialect ["
+
DB2Dialect
.
class
+
"]"
;
}
}
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/DerbyDialect.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
domain.Pagination
;
public
class
DerbyDialect
extends
Dialect
{
public
DerbyDialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
@Override
public
String
getLimitString
(
String
sql
,
Pagination
pagination
)
{
StringBuilder
pagingSelectSql
=
new
StringBuilder
(
sql
.
length
()
+
50
);
pagingSelectSql
.
append
(
sql
);
if
(
pagination
.
getStartRow
()
==
0
)
{
pagingSelectSql
.
append
(
" fetch first "
);
}
else
{
pagingSelectSql
.
append
(
" offset "
).
append
(
pagination
.
getStartRow
()
).
append
(
" rows fetch next "
);
}
pagingSelectSql
.
append
(
pagination
.
getPageResults
()
).
append
(
" rows only"
);
return
pagingSelectSql
.
toString
();
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
Pagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
Pagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"DerbyDialect ["
+
DerbyDialect
.
class
+
"]"
;
}
}
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
persistence.JpaPagination
;
public
class
DerbyDialect
extends
Dialect
{
public
DerbyDialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
@Override
public
String
getLimitString
(
String
sql
,
JpaPagination
pagination
)
{
StringBuilder
pagingSelectSql
=
new
StringBuilder
(
sql
.
length
()
+
50
);
pagingSelectSql
.
append
(
sql
);
if
(
pagination
.
getStartRow
()
==
0
)
{
pagingSelectSql
.
append
(
" fetch first "
);
}
else
{
pagingSelectSql
.
append
(
" offset "
).
append
(
pagination
.
getStartRow
()
).
append
(
" rows fetch next "
);
}
pagingSelectSql
.
append
(
pagination
.
getPageResults
()
).
append
(
" rows only"
);
return
pagingSelectSql
.
toString
();
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
JpaPagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
JpaPagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"DerbyDialect ["
+
DerbyDialect
.
class
+
"]"
;
}
}
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/Dialect.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.util.HashMap
;
import
org.apache.mybatis.jpa.
domain.Pagination
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* DB Access Dialect,inspiration from hibernate
*
* @author Crystal.Sea
* Create 2017-7-24
*
*/
public
abstract
class
Dialect
{
private
static
final
Logger
_logger
=
LoggerFactory
.
getLogger
(
Dialect
.
class
);
public
static
final
String
DEFAULT_BATCH_SIZE
=
"15"
;
public
static
final
String
NO_BATCH
=
"0"
;
protected
static
HashMap
<
String
,
String
>
dialectMap
;
static
{
dialectMap
=
new
HashMap
<
String
,
String
>();
dialectMap
.
put
(
"db2"
,
"org.apache.mybatis.jpa.dialect.DB2Dialect"
);
dialectMap
.
put
(
"derby"
,
"org.apache.mybatis.jpa.dialect.DerbyDialect"
);
dialectMap
.
put
(
"mysql"
,
"org.apache.mybatis.jpa.dialect.MySQLDialect"
);
dialectMap
.
put
(
"oracle"
,
"org.apache.mybatis.jpa.dialect.OracleDialect"
);
dialectMap
.
put
(
"postgresql"
,
"org.apache.mybatis.jpa.dialect.PostgreSQLDialect"
);
dialectMap
.
put
(
"sqlserver"
,
"org.apache.mybatis.jpa.dialect.SQLServerDialect"
);
_logger
.
trace
(
"Dialect Mapper : \n"
+
dialectMap
);
}
// constructors and factory methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
protected
Dialect
()
{
}
@Override
public
String
toString
()
{
return
getClass
().
getName
();
}
/**
* Given a limit and an offset, apply the limit clause to the query.
*
* @param query The query to which to apply the limit.
* @param offset The offset of the limit
* @param limit The limit of the limit ;)
* @return The modified query statement with the limit applied.
*/
public
String
getLimitString
(
String
query
,
Pagination
pagination
)
{
throw
new
UnsupportedOperationException
(
"Paged queries not supported by "
+
getClass
().
getName
());
}
public
String
getPreparedStatementLimitString
(
String
query
,
Pagination
pagination
)
{
throw
new
UnsupportedOperationException
(
"Paged queries not supported by "
+
getClass
().
getName
());
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
Pagination
pagination
)
{
throw
new
UnsupportedOperationException
(
"Paged queries not supported by "
+
getClass
().
getName
());
}
public
boolean
supportsLimit
()
{
return
false
;
}
/**
* @return the dialectMap
*/
public
static
HashMap
<
String
,
String
>
getDialectMap
()
{
return
dialectMap
;
}
}
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.util.HashMap
;
import
org.apache.mybatis.jpa.
persistence.JpaPagination
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* DB Access Dialect,inspiration from hibernate
*
* @author Crystal.Sea
* Create 2017-7-24
*
*/
public
abstract
class
Dialect
{
private
static
final
Logger
_logger
=
LoggerFactory
.
getLogger
(
Dialect
.
class
);
public
static
final
String
DEFAULT_BATCH_SIZE
=
"15"
;
public
static
final
String
NO_BATCH
=
"0"
;
protected
static
HashMap
<
String
,
String
>
dialectMap
;
static
{
dialectMap
=
new
HashMap
<
String
,
String
>();
dialectMap
.
put
(
"db2"
,
"org.apache.mybatis.jpa.dialect.DB2Dialect"
);
dialectMap
.
put
(
"derby"
,
"org.apache.mybatis.jpa.dialect.DerbyDialect"
);
dialectMap
.
put
(
"mysql"
,
"org.apache.mybatis.jpa.dialect.MySQLDialect"
);
dialectMap
.
put
(
"oracle"
,
"org.apache.mybatis.jpa.dialect.OracleDialect"
);
dialectMap
.
put
(
"postgresql"
,
"org.apache.mybatis.jpa.dialect.PostgreSQLDialect"
);
dialectMap
.
put
(
"sqlserver"
,
"org.apache.mybatis.jpa.dialect.SQLServerDialect"
);
_logger
.
trace
(
"Dialect Mapper : \n"
+
dialectMap
);
}
// constructors and factory methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
protected
Dialect
()
{
}
@Override
public
String
toString
()
{
return
getClass
().
getName
();
}
/**
* Given a limit and an offset, apply the limit clause to the query.
*
* @param query The query to which to apply the limit.
* @param offset The offset of the limit
* @param limit The limit of the limit ;)
* @return The modified query statement with the limit applied.
*/
public
String
getLimitString
(
String
query
,
JpaPagination
pagination
)
{
throw
new
UnsupportedOperationException
(
"Paged queries not supported by "
+
getClass
().
getName
());
}
public
String
getPreparedStatementLimitString
(
String
query
,
JpaPagination
pagination
)
{
throw
new
UnsupportedOperationException
(
"Paged queries not supported by "
+
getClass
().
getName
());
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
JpaPagination
pagination
)
{
throw
new
UnsupportedOperationException
(
"Paged queries not supported by "
+
getClass
().
getName
());
}
public
boolean
supportsLimit
()
{
return
false
;
}
/**
* @return the dialectMap
*/
public
static
HashMap
<
String
,
String
>
getDialectMap
()
{
return
dialectMap
;
}
}
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/MySQLDialect.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
domain.Pagination
;
public
class
MySQLDialect
extends
Dialect
{
public
MySQLDialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
static
int
getAfterSelectInsertPoint
(
String
sql
)
{
int
selectIndex
=
sql
.
toLowerCase
().
indexOf
(
"select"
);
final
int
selectDistinctIndex
=
sql
.
toLowerCase
().
indexOf
(
"select distinct"
);
return
selectIndex
+
(
selectDistinctIndex
==
selectIndex
?
15
:
6
);
}
@Override
public
String
getLimitString
(
String
sql
,
Pagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
pagination
.
calculate
();
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT "
+
pagination
.
getStartRow
()+
" , "
+
pagination
.
getPageResults
();
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT "
+
pagination
.
getPageResults
();
}
else
{
return
sql
+
" LIMIT "
+
pagination
.
getPageResults
();
}
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
Pagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
Pagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"MySQLDialect ["
+
MySQLDialect
.
class
+
"]"
;
}
}
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
persistence.JpaPagination
;
public
class
MySQLDialect
extends
Dialect
{
public
MySQLDialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
static
int
getAfterSelectInsertPoint
(
String
sql
)
{
int
selectIndex
=
sql
.
toLowerCase
().
indexOf
(
"select"
);
final
int
selectDistinctIndex
=
sql
.
toLowerCase
().
indexOf
(
"select distinct"
);
return
selectIndex
+
(
selectDistinctIndex
==
selectIndex
?
15
:
6
);
}
@Override
public
String
getLimitString
(
String
sql
,
JpaPagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
pagination
.
calculate
();
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT "
+
pagination
.
getStartRow
()+
" , "
+
pagination
.
getPageResults
();
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT "
+
pagination
.
getPageResults
();
}
else
{
return
sql
+
" LIMIT "
+
pagination
.
getPageResults
();
}
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
JpaPagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
JpaPagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"MySQLDialect ["
+
MySQLDialect
.
class
+
"]"
;
}
}
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/OracleDialect.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
domain.Pagination
;
public
class
OracleDialect
extends
Dialect
{
public
OracleDialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
@Override
public
String
getLimitString
(
String
sql
,
Pagination
pagination
)
{
if
(
pagination
.
getPageResults
()
==
0
)
{
return
sql
+
" fetch first "
+
pagination
.
getStartRow
()
+
" rows only"
;
}
StringBuilder
pagingSelect
=
new
StringBuilder
(
sql
.
length
()
+
200
)
.
append
(
"select * from (select inner_table_.*, rownum as rownumber_ from ( "
)
.
append
(
sql
)
//nest the main query in an outer select
.
append
(
") inner_table_ ) where rownumber_ > "
)
.
append
(
pagination
.
getStartRow
()
)
.
append
(
" and rownumber_ <="
)
.
append
(
pagination
.
getEndRow
()
)
.
append
(
" order by rownumber_"
);
return
pagingSelect
.
toString
();
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
Pagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
Pagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"OracleDialect ["
+
OracleDialect
.
class
+
"]"
;
}
}
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
persistence.JpaPagination
;
public
class
OracleDialect
extends
Dialect
{
public
OracleDialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
@Override
public
String
getLimitString
(
String
sql
,
JpaPagination
pagination
)
{
if
(
pagination
.
getPageResults
()
==
0
)
{
return
sql
+
" fetch first "
+
pagination
.
getStartRow
()
+
" rows only"
;
}
StringBuilder
pagingSelect
=
new
StringBuilder
(
sql
.
length
()
+
200
)
.
append
(
"select * from (select inner_table_.*, rownum as rownumber_ from ( "
)
.
append
(
sql
)
//nest the main query in an outer select
.
append
(
") inner_table_ ) where rownumber_ > "
)
.
append
(
pagination
.
getStartRow
()
)
.
append
(
" and rownumber_ <="
)
.
append
(
pagination
.
getEndRow
()
)
.
append
(
" order by rownumber_"
);
return
pagingSelect
.
toString
();
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
JpaPagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
JpaPagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"OracleDialect ["
+
OracleDialect
.
class
+
"]"
;
}
}
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/PostgreSQLDialect.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
domain.Pagination
;
public
class
PostgreSQLDialect
extends
Dialect
{
public
PostgreSQLDialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
@Override
public
String
getLimitString
(
String
sql
,
Pagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT "
+
pagination
.
getPageResults
()+
" , "
+
pagination
.
getStartRow
()
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT "
+
pagination
.
getPageResults
();
}
else
{
return
sql
+
" LIMIT 1000"
;
}
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
Pagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
Pagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"PostgreSQLDialect ["
+
PostgreSQLDialect
.
class
+
"]"
;
}
}
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
persistence.JpaPagination
;
public
class
PostgreSQLDialect
extends
Dialect
{
public
PostgreSQLDialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
@Override
public
String
getLimitString
(
String
sql
,
JpaPagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT "
+
pagination
.
getPageResults
()+
" , "
+
pagination
.
getStartRow
()
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT "
+
pagination
.
getPageResults
();
}
else
{
return
sql
+
" LIMIT 1000"
;
}
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
JpaPagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
JpaPagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"PostgreSQLDialect ["
+
PostgreSQLDialect
.
class
+
"]"
;
}
}
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/dialect/SQLServerDialect.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
domain.Pagination
;
public
class
SQLServerDialect
extends
Dialect
{
public
SQLServerDialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
@Override
public
String
getLimitString
(
String
sql
,
Pagination
pagination
)
{
StringBuilder
pagingSelectSql
=
new
StringBuilder
(
""
);
if
(
pagination
.
getPageResults
()>
0
){
pagingSelectSql
.
append
(
"SELECT TOP "
+
pagination
.
getPageResults
()+
" * FROM ( "
);
pagingSelectSql
.
append
(
"SELECT ROW_NUMBER() OVER() AS ROWNUMBER,MYBATIS_QUERY_TEMP_TABLE.* FROM ( "
);
pagingSelectSql
.
append
(
"MYBATIS_QUERY_TEMP_TABLE ) MYBATIS_QUERY_TEMP_PAGE "
);
if
(
pagination
.
getStartRow
()>
0
){
pagingSelectSql
.
append
(
"WHERE ROWNUMBER > "
+
pagination
.
getStartRow
());
}
}
else
{
return
sql
;
}
return
pagingSelectSql
.
toString
();
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
Pagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
Pagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"SQLServerDialect ["
+
SQLServerDialect
.
class
+
"]"
;
}
}
package
org.apache.mybatis.jpa.dialect
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.apache.mybatis.jpa.
persistence.JpaPagination
;
public
class
SQLServerDialect
extends
Dialect
{
public
SQLServerDialect
()
{
super
();
}
@Override
public
boolean
supportsLimit
()
{
return
true
;
}
@Override
public
String
getLimitString
(
String
sql
,
JpaPagination
pagination
)
{
StringBuilder
pagingSelectSql
=
new
StringBuilder
(
""
);
if
(
pagination
.
getPageResults
()>
0
){
pagingSelectSql
.
append
(
"SELECT TOP "
+
pagination
.
getPageResults
()+
" * FROM ( "
);
pagingSelectSql
.
append
(
"SELECT ROW_NUMBER() OVER() AS ROWNUMBER,MYBATIS_QUERY_TEMP_TABLE.* FROM ( "
);
pagingSelectSql
.
append
(
"MYBATIS_QUERY_TEMP_TABLE ) MYBATIS_QUERY_TEMP_PAGE "
);
if
(
pagination
.
getStartRow
()>
0
){
pagingSelectSql
.
append
(
"WHERE ROWNUMBER > "
+
pagination
.
getStartRow
());
}
}
else
{
return
sql
;
}
return
pagingSelectSql
.
toString
();
}
@Override
public
String
getPreparedStatementLimitString
(
String
sql
,
JpaPagination
pagination
)
{
//LIMIT #{pageResults} OFFSET #{startRow}
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
return
sql
+
" LIMIT ? , ?"
;
}
else
if
(
pagination
.
getPageResults
()>
0
){
return
sql
+
" LIMIT ? "
;
}
else
{
return
sql
+
" LIMIT ?"
;
}
}
public
void
setLimitParamters
(
PreparedStatement
preparedStatement
,
int
parameterSize
,
JpaPagination
pagination
)
{
try
{
if
(
pagination
.
getPageResults
()>
0
&&
pagination
.
getStartRow
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
if
(
pagination
.
getPageResults
()>
0
){
preparedStatement
.
setInt
(++
parameterSize
,
pagination
.
getPageResults
());
}
else
{
preparedStatement
.
setInt
(++
parameterSize
,
1000
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"SQLServerDialect ["
+
SQLServerDialect
.
class
+
"]"
;
}
}
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/MapperSqlProvider.java
浏览文件 @
84852be4
此差异已折叠。
点击以展开。
mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/dao/service/StudentsService.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa.test.dao.service
;
import
org.apache.mybatis.jpa.
service.JpaBaseService
;
import
org.apache.mybatis.jpa.test.dao.persistence.StudentsMapper
;
import
org.apache.mybatis.jpa.test.domain.Students
;
import
org.springframework.stereotype.Service
;
@Service
public
class
StudentsService
extends
JpaBaseService
<
Students
>
{
public
StudentsService
()
{
super
(
StudentsMapper
.
class
);
}
/* (non-Javadoc)
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public
StudentsMapper
getMapper
()
{
// TODO Auto-generated method stub
return
(
StudentsMapper
)
super
.
getMapper
();
}
}
package
org.apache.mybatis.jpa.test.dao.service
;
import
org.apache.mybatis.jpa.
persistence.JpaBaseService
;
import
org.apache.mybatis.jpa.test.dao.persistence.StudentsMapper
;
import
org.apache.mybatis.jpa.test.domain.Students
;
import
org.springframework.stereotype.Service
;
@Service
public
class
StudentsService
extends
JpaBaseService
<
Students
>
{
public
StudentsService
()
{
super
(
StudentsMapper
.
class
);
}
/* (non-Javadoc)
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public
StudentsMapper
getMapper
()
{
// TODO Auto-generated method stub
return
(
StudentsMapper
)
super
.
getMapper
();
}
}
mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/domain/DemoDomain.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa.test.domain
;
import
java.util.Date
;
import
java.util.UUID
;
import
javax.persistence.Column
;
import
javax.persistence.Id
;
import
org.apache.mybatis.jpa.
domain.BaseDomain
;
import
org.apache.mybatis.jpa.util.JsonDateTimeDeserializer
;
import
org.apache.mybatis.jpa.util.JsonDateTimeSerializer
;
import
org.codehaus.jackson.map.annotate.JsonDeserialize
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
DemoDomain
extends
BaseDomain
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
5918892823601207632L
;
public
final
static
String
TABLE_KEY
=
"ID"
;
protected
final
static
Logger
_logger
=
LoggerFactory
.
getLogger
(
DemoDomain
.
class
);
/**
* Domain id
*/
@Id
@Column
protected
String
id
;
/**
* description
*/
protected
String
description
;
protected
int
status
;
protected
int
sortOrder
;
protected
String
createdBy
;
@JsonSerialize
(
using
=
JsonDateTimeSerializer
.
class
)
@JsonDeserialize
(
using
=
JsonDateTimeDeserializer
.
class
)
protected
Date
createdDate
;
protected
String
modifiedBy
;
@JsonSerialize
(
using
=
JsonDateTimeSerializer
.
class
)
@JsonDeserialize
(
using
=
JsonDateTimeDeserializer
.
class
)
protected
Date
modifiedDate
;
protected
String
startDate
;
protected
String
endDate
;
public
DemoDomain
()
{
}
/**
* @return the id
*/
public
String
getId
()
{
return
id
;
}
/**
* @param id the id to set
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
/**
* @return the status
*/
public
int
getStatus
()
{
return
status
;
}
/**
* @param status the status to set
*/
public
void
setStatus
(
int
status
)
{
this
.
status
=
status
;
}
/**
* @return the sortOrder
*/
public
int
getSortOrder
()
{
return
sortOrder
;
}
/**
* @param sortOrder the sortOrder to set
*/
public
void
setSortOrder
(
int
sortOrder
)
{
this
.
sortOrder
=
sortOrder
;
}
/**
* @return the createdBy
*/
public
String
getCreatedBy
()
{
return
createdBy
;
}
/**
* @param createdBy the createdBy to set
*/
public
void
setCreatedBy
(
String
createdBy
)
{
this
.
createdBy
=
createdBy
;
}
/**
* @return the createdDate
*/
public
Date
getCreatedDate
()
{
return
createdDate
;
}
/**
* @param createdDate the createdDate to set
*/
public
void
setCreatedDate
(
Date
createdDate
)
{
this
.
createdDate
=
createdDate
;
}
/**
* @return the modifiedBy
*/
public
String
getModifiedBy
()
{
return
modifiedBy
;
}
/**
* @param modifiedBy the modifiedBy to set
*/
public
void
setModifiedBy
(
String
modifiedBy
)
{
this
.
modifiedBy
=
modifiedBy
;
}
/**
* @return the modifiedDate
*/
public
Date
getModifiedDate
()
{
return
modifiedDate
;
}
/**
* @param modifiedDate the modifiedDate to set
*/
public
void
setModifiedDate
(
Date
modifiedDate
)
{
this
.
modifiedDate
=
modifiedDate
;
}
/**
* @return the description
*/
public
String
getDescription
()
{
return
description
;
}
/**
* @param description the description to set
*/
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
/**
* @return the startDate
*/
public
String
getStartDate
()
{
return
startDate
;
}
/**
* @param startDate the startDate to set
*/
public
void
setStartDate
(
String
startDate
)
{
this
.
startDate
=
startDate
;
}
/**
* @return the endDate
*/
public
String
getEndDate
()
{
return
endDate
;
}
/**
* @param endDate the endDate to set
*/
public
void
setEndDate
(
String
endDate
)
{
this
.
endDate
=
endDate
;
}
public
String
generateId
()
{
return
UUID
.
randomUUID
().
toString
().
toLowerCase
();
}
@Override
public
String
toString
()
{
return
"BaseDomain [id="
+
id
+
", status="
+
status
+
", sortOrder="
+
sortOrder
+
", createdBy="
+
createdBy
+
", createdDate="
+
createdDate
+
", modifiedBy="
+
modifiedBy
+
", modifiedDate="
+
modifiedDate
+
", description="
+
description
+
", startDate="
+
startDate
+
", endDate="
+
endDate
+
"]"
;
}
}
package
org.apache.mybatis.jpa.test.domain
;
import
java.util.Date
;
import
java.util.UUID
;
import
javax.persistence.Column
;
import
javax.persistence.Id
;
import
org.apache.mybatis.jpa.
persistence.JpaBaseDomain
;
import
org.apache.mybatis.jpa.util.JsonDateTimeDeserializer
;
import
org.apache.mybatis.jpa.util.JsonDateTimeSerializer
;
import
org.codehaus.jackson.map.annotate.JsonDeserialize
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
DemoDomain
extends
JpaBaseDomain
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
5918892823601207632L
;
public
final
static
String
TABLE_KEY
=
"ID"
;
protected
final
static
Logger
_logger
=
LoggerFactory
.
getLogger
(
DemoDomain
.
class
);
/**
* Domain id
*/
@Id
@Column
protected
String
id
;
/**
* description
*/
protected
String
description
;
protected
int
status
;
protected
int
sortOrder
;
protected
String
createdBy
;
@JsonSerialize
(
using
=
JsonDateTimeSerializer
.
class
)
@JsonDeserialize
(
using
=
JsonDateTimeDeserializer
.
class
)
protected
Date
createdDate
;
protected
String
modifiedBy
;
@JsonSerialize
(
using
=
JsonDateTimeSerializer
.
class
)
@JsonDeserialize
(
using
=
JsonDateTimeDeserializer
.
class
)
protected
Date
modifiedDate
;
protected
String
startDate
;
protected
String
endDate
;
public
DemoDomain
()
{
}
/**
* @return the id
*/
public
String
getId
()
{
return
id
;
}
/**
* @param id the id to set
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
/**
* @return the status
*/
public
int
getStatus
()
{
return
status
;
}
/**
* @param status the status to set
*/
public
void
setStatus
(
int
status
)
{
this
.
status
=
status
;
}
/**
* @return the sortOrder
*/
public
int
getSortOrder
()
{
return
sortOrder
;
}
/**
* @param sortOrder the sortOrder to set
*/
public
void
setSortOrder
(
int
sortOrder
)
{
this
.
sortOrder
=
sortOrder
;
}
/**
* @return the createdBy
*/
public
String
getCreatedBy
()
{
return
createdBy
;
}
/**
* @param createdBy the createdBy to set
*/
public
void
setCreatedBy
(
String
createdBy
)
{
this
.
createdBy
=
createdBy
;
}
/**
* @return the createdDate
*/
public
Date
getCreatedDate
()
{
return
createdDate
;
}
/**
* @param createdDate the createdDate to set
*/
public
void
setCreatedDate
(
Date
createdDate
)
{
this
.
createdDate
=
createdDate
;
}
/**
* @return the modifiedBy
*/
public
String
getModifiedBy
()
{
return
modifiedBy
;
}
/**
* @param modifiedBy the modifiedBy to set
*/
public
void
setModifiedBy
(
String
modifiedBy
)
{
this
.
modifiedBy
=
modifiedBy
;
}
/**
* @return the modifiedDate
*/
public
Date
getModifiedDate
()
{
return
modifiedDate
;
}
/**
* @param modifiedDate the modifiedDate to set
*/
public
void
setModifiedDate
(
Date
modifiedDate
)
{
this
.
modifiedDate
=
modifiedDate
;
}
/**
* @return the description
*/
public
String
getDescription
()
{
return
description
;
}
/**
* @param description the description to set
*/
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
/**
* @return the startDate
*/
public
String
getStartDate
()
{
return
startDate
;
}
/**
* @param startDate the startDate to set
*/
public
void
setStartDate
(
String
startDate
)
{
this
.
startDate
=
startDate
;
}
/**
* @return the endDate
*/
public
String
getEndDate
()
{
return
endDate
;
}
/**
* @param endDate the endDate to set
*/
public
void
setEndDate
(
String
endDate
)
{
this
.
endDate
=
endDate
;
}
public
String
generateId
()
{
return
UUID
.
randomUUID
().
toString
().
toLowerCase
();
}
@Override
public
String
toString
()
{
return
"BaseDomain [id="
+
id
+
", status="
+
status
+
", sortOrder="
+
sortOrder
+
", createdBy="
+
createdBy
+
", createdDate="
+
createdDate
+
", modifiedBy="
+
modifiedBy
+
", modifiedDate="
+
modifiedDate
+
", description="
+
description
+
", startDate="
+
startDate
+
", endDate="
+
endDate
+
"]"
;
}
}
mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/domain/Students.java
浏览文件 @
84852be4
package
org.apache.mybatis.jpa.test.domain
;
import
java.io.Serializable
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
org.apache.mybatis.jpa.
domain.BaseDomain
;
/*
ID varchar(40) not null,
NAME varchar(60) not null,
STATUS char(1) null,
CREATEBY varchar(40) null,
CREATEDATE date null,
UPDATEBY varchar(40) null,
UPDATEDATE date null,
constraint PK_ROLES primary key clustered (ID)
*/
/**
* @author Crystal.Sea
*
*/
@Table
(
name
=
"STUDENTS"
)
public
class
Students
extends
BaseDomain
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
6928570405840778151L
;
@Id
@Column
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
,
generator
=
"serial"
)
//@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SEQ_MYBATIS_STUD")
//@GeneratedValue(strategy=GenerationType.IDENTITY,generator="SEQ_MYBATIS_STUD")
private
String
id
;
@Column
private
String
stdNo
;
@Column
private
String
stdName
;
@Column
private
String
stdGender
;
@Column
private
int
stdAge
;
@Column
private
String
stdMajor
;
@Column
private
String
stdClass
;
public
Students
()
{
super
();
}
public
String
getStdNo
()
{
return
stdNo
;
}
public
void
setStdNo
(
String
stdNo
)
{
this
.
stdNo
=
stdNo
;
}
public
String
getStdName
()
{
return
stdName
;
}
public
void
setStdName
(
String
stdName
)
{
this
.
stdName
=
stdName
;
}
public
String
getStdGender
()
{
return
stdGender
;
}
public
void
setStdGender
(
String
stdGender
)
{
this
.
stdGender
=
stdGender
;
}
public
int
getStdAge
()
{
return
stdAge
;
}
public
void
setStdAge
(
int
stdAge
)
{
this
.
stdAge
=
stdAge
;
}
public
String
getStdMajor
()
{
return
stdMajor
;
}
public
void
setStdMajor
(
String
stdMajor
)
{
this
.
stdMajor
=
stdMajor
;
}
public
String
getStdClass
()
{
return
stdClass
;
}
public
void
setStdClass
(
String
stdClass
)
{
this
.
stdClass
=
stdClass
;
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
@Override
public
String
toString
()
{
return
"Students [stdNo="
+
stdNo
+
", stdName="
+
stdName
+
", stdgender="
+
stdGender
+
", stdAge="
+
stdAge
+
", stdMajor="
+
stdMajor
+
", stdClass="
+
stdClass
+
"]"
;
}
}
package
org.apache.mybatis.jpa.test.domain
;
import
java.io.Serializable
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
org.apache.mybatis.jpa.
persistence.JpaBaseDomain
;
/*
ID varchar(40) not null,
NAME varchar(60) not null,
STATUS char(1) null,
CREATEBY varchar(40) null,
CREATEDATE date null,
UPDATEBY varchar(40) null,
UPDATEDATE date null,
constraint PK_ROLES primary key clustered (ID)
*/
/**
* @author Crystal.Sea
*
*/
@Table
(
name
=
"STUDENTS"
)
public
class
Students
extends
JpaBaseDomain
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
6928570405840778151L
;
@Id
@Column
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
,
generator
=
"serial"
)
//@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SEQ_MYBATIS_STUD")
//@GeneratedValue(strategy=GenerationType.IDENTITY,generator="SEQ_MYBATIS_STUD")
private
String
id
;
@Column
private
String
stdNo
;
@Column
private
String
stdName
;
@Column
private
String
stdGender
;
@Column
private
int
stdAge
;
@Column
private
String
stdMajor
;
@Column
private
String
stdClass
;
public
Students
()
{
super
();
}
public
String
getStdNo
()
{
return
stdNo
;
}
public
void
setStdNo
(
String
stdNo
)
{
this
.
stdNo
=
stdNo
;
}
public
String
getStdName
()
{
return
stdName
;
}
public
void
setStdName
(
String
stdName
)
{
this
.
stdName
=
stdName
;
}
public
String
getStdGender
()
{
return
stdGender
;
}
public
void
setStdGender
(
String
stdGender
)
{
this
.
stdGender
=
stdGender
;
}
public
int
getStdAge
()
{
return
stdAge
;
}
public
void
setStdAge
(
int
stdAge
)
{
this
.
stdAge
=
stdAge
;
}
public
String
getStdMajor
()
{
return
stdMajor
;
}
public
void
setStdMajor
(
String
stdMajor
)
{
this
.
stdMajor
=
stdMajor
;
}
public
String
getStdClass
()
{
return
stdClass
;
}
public
void
setStdClass
(
String
stdClass
)
{
this
.
stdClass
=
stdClass
;
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
@Override
public
String
toString
()
{
return
"Students [stdNo="
+
stdNo
+
", stdName="
+
stdName
+
", stdgender="
+
stdGender
+
", stdAge="
+
stdAge
+
", stdMajor="
+
stdMajor
+
", stdClass="
+
stdClass
+
"]"
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录