Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-common
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
s_guodong
gjjs-bd-common
Commits
7e2523cb
Commit
7e2523cb
authored
Aug 28, 2024
by
gechengyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改mybatis相关操作,待完善
parent
d8eb3207
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
212 additions
and
14 deletions
+212
-14
XxxtskSchedued.java
...rc/main/java/com/brilliance/scheduled/XxxtskSchedued.java
+8
-1
application-mysql.yml
gjjs-bd-business/src/main/resources/application-mysql.yml
+60
-0
application-oracle.yml.bak20240826
...ess/src/main/resources/application-oracle.yml.bak20240826
+0
-0
application.yml
gjjs-bd-business/src/main/resources/application.yml
+1
-1
logback.xml
gjjs-bd-business/src/main/resources/logback.xml
+36
-2
lckmapper.xml
gjjs-bd-business/src/main/resources/mapper/lckmapper.xml
+5
-0
Test.java
gjjs-bd-business/src/test/java/com/brilliance/test/Test.java
+13
-0
DBLocker.java
...ain/java/com/brilliance/mda/support/mybatis/DBLocker.java
+14
-7
MyBatisDaoSession.java
...com/brilliance/mda/support/mybatis/MyBatisDaoSession.java
+44
-3
MybatisArgumentAdapter.java
...rilliance/mda/support/mybatis/MybatisArgumentAdapter.java
+13
-0
LckMapper.java
...ava/com/brilliance/mda/support/mybatis/lck/LckMapper.java
+7
-0
pom.xml
gjjs-bd-runtime/pom.xml
+7
-0
IDaoSession.java
...main/java/com/brilliance/mda/runtime/mda/IDaoSession.java
+1
-0
AbstractDaoSession.java
...m/brilliance/mda/runtime/mda/impl/AbstractDaoSession.java
+3
-0
mysql-connector-java-8.0.11.jar
lib/mysql-connector-java-8.0.11.jar
+0
-0
No files found.
gjjs-bd-business/src/main/java/com/brilliance/scheduled/XxxtskSchedued.java
View file @
7e2523cb
package
com
.
brilliance
.
scheduled
;
import
com.ceb.gjjs.mda.service.impl.JobTask
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
import
java.time.LocalDateTime
;
@Component
public
class
XxxtskSchedued
{
@Scheduled
(
fixedRate
=
5000
)
// 或者使用cron表达式
@Autowired
JobTask
jobTask
;
@Scheduled
(
fixedRate
=
30000
)
// 或者使用cron表达式
public
void
reportCurrentTime
()
{
System
.
out
.
println
(
"The time is now "
+
LocalDateTime
.
now
());
jobTask
.
start
();
}
}
gjjs-bd-business/src/main/resources/application-mysql.yml
0 → 100644
View file @
7e2523cb
server
:
port
:
8088
servlet
:
#context-path: /gjjs/business
servlet-path
:
/gjjs/business
spring
:
ipsnew
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://192.168.0.110:3306/ips?useUnicode=true&characterEncoding=utf8
username
:
ips
password
:
ips
type
:
com.alibaba.druid.pool.DruidDataSource
# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
# druid 配置: https://github.com/alibaba/druid/wiki/
#初始化链接数
initialSize
:
1
minIdle
:
1
maxActive
:
20
# 配置获取连接等待超时的时间
maxWait
:
60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis
:
60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis
:
300000
# validationQuery: select 1 from dual
testWhileIdle
:
true
testOnBorrow
:
false
testOnReturn
:
false
# 打开PSCache,并且指定每个连接上PSCache的大小
poolPreparedStatements
:
true
maxPoolPreparedStatementPerConnectionSize
:
20
# 配置监控统计拦截的filters,stat用于监控界面,'wall'用于防火墙防御sql注入, slf4j用于druid记录sql日志
filters
:
stat,slf4j
#,wall
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
connectionProperties
:
druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 合并多个DruidDataSource的监控数据
useGlobalDataSourceStat
:
false
redis
:
host
:
127.0.0.1
database
:
0
port
:
6379
password
:
envConfig
:
rootPath
:
workRoot
cache
:
#缓存类型(guava/redis)
type
:
redis
#缓存失效时间(秒)
expireAfterAccess
:
3600
#序列化方式
serializer
:
kryo
gjjs-bd-business/src/main/resources/application-oracle.yml
→
gjjs-bd-business/src/main/resources/application-oracle.yml
.bak20240826
View file @
7e2523cb
File moved
gjjs-bd-business/src/main/resources/application.yml
View file @
7e2523cb
spring
:
profiles
:
active
:
oracle
active
:
mysql
logging
:
config
:
classpath:logback.xml
...
...
gjjs-bd-business/src/main/resources/logback.xml
View file @
7e2523cb
...
...
@@ -16,6 +16,37 @@
</encoder>
</appender>
<appender
name=
"GJJSFILE"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<file>
${LOG_HOME}/gjjs.log
</file>
<append>
true
</append>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"
>
<fileNamePattern>
${LOG_HOME}/logs/gjjs.%d{yyyy-MM-dd}.%i.log.zip
</fileNamePattern>
<maxFileSize>
${maxFileSize}
</maxFileSize>
</rollingPolicy>
<encoder>
<pattern>
${pattern}
</pattern>
<charset>
${charset}
</charset>
<immediateFlush>
${immediateFlush}
</immediateFlush>
</encoder>
<!--<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>-->
</appender>
<!--<appender name="GJJSFILE" class="ch.qos.logback.core.FileAppender">
<file>gjjs.log</file>
<encoder>
<pattern>>${pattern}</pattern>
</encoder>
</appender>-->
<appender
name=
"INFO_FILE"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<file>
${LOG_HOME}/info.log
</file>
...
...
@@ -122,9 +153,11 @@
<root
level=
"INFO"
>
<appender-ref
ref=
"STDOUT"
/>
<appender-ref
ref=
"INFO_FILE_ASYNC"
/>
<!--
<appender-ref ref="INFO_FILE_ASYNC" />
<appender-ref ref="DEBUG_FILE_ASYNC" />
<appender-ref
ref=
"ERROR_FILE_ASYNC"
/>
<appender-ref ref="ERROR_FILE_ASYNC" />-->
<appender-ref
ref=
"GJJSFILE"
/>
</root>
</configuration>
\ No newline at end of file
gjjs-bd-business/src/main/resources/mapper/lckmapper.xml
View file @
7e2523cb
...
...
@@ -14,4 +14,8 @@
delete from LCK where TXT = #{key}
</select>
<select
id=
"deleteByName"
resultType=
"java.lang.Integer"
>
delete from LCK where NAM = #{key}
</select>
</mapper>
\ No newline at end of file
gjjs-bd-business/src/test/java/com/brilliance/test/Test.java
View file @
7e2523cb
package
com
.
brilliance
.
test
;
import
com.ceb.gjjs.mda.service.impl.JobTask
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.HashSet
;
public
class
Test
{
@Autowired
JobTask
jobTask
;
@org
.
junit
.
jupiter
.
api
.
Test
public
void
test
()
{
HashSet
set
=
new
HashSet
();
...
...
@@ -15,4 +21,11 @@ public class Test {
}
@org
.
junit
.
jupiter
.
api
.
Test
public
void
testTask
()
{
JobTask
jobTask
=
new
JobTask
();
jobTask
.
start
();;
}
}
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/DBLocker.java
View file @
7e2523cb
...
...
@@ -6,6 +6,7 @@ import com.brilliance.mda.runtime.mda.ILocker;
import
com.brilliance.mda.runtime.mda.LockInfo
;
import
com.brilliance.mda.runtime.mda.driver.MdaEnv
;
import
com.brilliance.mda.support.mybatis.lck.LckMapper
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -54,21 +55,27 @@ public class DBLocker implements ILocker {
MdaEnv
.
getContext
().
setErrorCode
(
Constants
.
ERROR_LOCKED
);
return
null
;
}
return
new
LockInfo
(
date
,
key
.
toString
());
// return new LockInfo(date, key.toString());
return
new
LockInfo
(
date
,
lockName
);
}
@Override
public
boolean
unlock
(
Serializable
key
)
{
try
{
lckMapper
.
delete
(
key
.
toString
());
}
catch
(
Exception
e
)
{
return
false
;
}
return
true
;
return
unlock
(
key
.
toString
(),
null
);
}
@Override
public
boolean
unlock
(
String
lockname
,
Serializable
key
)
{
int
count
=-
1
;
try
{
if
(
StringUtils
.
isNotEmpty
(
lockname
))
{
count
=
lckMapper
.
deleteByName
(
lockname
);
}
else
if
(
StringUtils
.
isNotEmpty
(
key
.
toString
()))
{
count
=
lckMapper
.
delete
(
key
.
toString
());
}
}
catch
(
Exception
e
)
{
return
false
;
}
return
true
;
}
}
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/MyBatisDaoSession.java
View file @
7e2523cb
...
...
@@ -32,8 +32,7 @@ import java.math.BigDecimal;
import
java.sql.SQLException
;
import
java.util.*
;
import
static
com
.
brilliance
.
mda
.
support
.
mybatis
.
MybatisArgumentAdapter
.
AdaType
.
DELETE
;
import
static
com
.
brilliance
.
mda
.
support
.
mybatis
.
MybatisArgumentAdapter
.
AdaType
.
SELECT
;
import
static
com
.
brilliance
.
mda
.
support
.
mybatis
.
MybatisArgumentAdapter
.
AdaType
.*;
import
static
com
.
brilliance
.
mda
.
support
.
mybatis
.
MybatisArgumentAdapter
.
HOLDER_SQL
;
/**
...
...
@@ -395,9 +394,31 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
return
list
.
size
();
}
// @Override
public
<
T
extends
IModule
>
int
dbReadsetByLimit
(
IModuleList
<
T
>
list
,
int
maxSize
,
Argument
...
args
)
{
if
(
isMultiDb
)
{
String
moduleDB
=
MdaUtils
.
getModuleListDB
(
list
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
}
list
.
clear
();
MybatisArgumentAdapter
adapter
=
new
MybatisArgumentAdapter
(
SELECTBYLIMIT
,
maxSize
,
list
.
getDataClass
(),
args
);
List
<
T
>
result
=
this
.
dyncRead
(
list
.
getDataClass
(),
adapter
);
list
.
addAll
(
result
);
return
list
.
size
();
}
@Override
public
<
T
extends
IModule
>
int
dbReadset
(
IModuleList
<
T
>
list
,
int
maxSize
,
Argument
...
args
)
{
return
0
;
int
retSize
=
0
;
if
(
maxSize
==
0
)
{
retSize
=
dbReadset
(
list
,
args
);
}
else
{
//TODO maxSize不为0时,需要优化
retSize
=
dbReadsetByLimit
(
list
,
maxSize
,
args
);
}
return
retSize
;
}
@Override
...
...
@@ -436,6 +457,11 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public
void
dbReadset
(
IModuleList
list
,
int
maxSize
)
{
if
(
maxSize
==
0
){
dbReadset
(
list
);
}
else
{
//TODO maxSize不为0时,需要优化
}
}
...
...
@@ -626,6 +652,21 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
return
new
ArrayList
<>(
list
);
}
private
<
T
>
List
<
T
>
dyncRead
(
Class
<
T
>
clazz
,
int
maxSize
,
MybatisArgumentAdapter
adapter
)
{
IContext
ctx
=
MdaEnv
.
getContext
();
BaseVO
baseVO
=
ctx
.
getVo
();
String
sqlId
=
getSqlId
(
clazz
,
SQLID_DYNCREAD
);
// sqlId =sqlId+" "
List
<
T
>
list
=
sqlSessionTemplate
.
selectList
(
sqlId
,
adapter
.
getSqlParams
());
PageInfo
<
T
>
pageInfo
=
new
PageInfo
<
T
>(
list
);
long
total
=
pageInfo
.
getTotal
();
baseVO
.
setTotal
(
total
);
if
(
list
==
null
||
list
.
size
()
==
0
)
{
setNoMoreRow
();
}
return
new
ArrayList
<>(
list
);
}
private
<
T
>
List
<
T
>
dyncRead
(
Class
<
T
>
clazz
,
Map
params
)
{
...
...
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/MybatisArgumentAdapter.java
View file @
7e2523cb
...
...
@@ -38,6 +38,8 @@ public class MybatisArgumentAdapter {
public
static
enum
AdaType
{
SELECT
(
"SELECT * FROM %s WHERE %s"
),
SELECTBYLIMIT
(
"SELECT * FROM %s WHERE %s limit %d"
),
JOIN_SELECT
(
"SELECT * %s"
),
DELETE
(
"DELETE FROM %s WHERE %s"
);
...
...
@@ -66,6 +68,8 @@ public class MybatisArgumentAdapter {
private
String
tableName
;
private
String
selectTable
;
private
int
maxSize
=
0
;
public
MybatisArgumentAdapter
(
AdaType
type
,
Class
<?
extends
IModule
>
clazz
,
Argument
...
args
)
{
this
.
clazz
=
clazz
;
...
...
@@ -75,6 +79,15 @@ public class MybatisArgumentAdapter {
this
.
init
();
}
public
MybatisArgumentAdapter
(
AdaType
type
,
int
maxSize
,
Class
<?
extends
IModule
>
clazz
,
Argument
...
args
)
{
this
.
clazz
=
clazz
;
this
.
maxSize
=
maxSize
;
this
.
pattern
=
type
.
getValue
();
this
.
args
=
args
;
this
.
tableName
=
convertTableName
();
this
.
init
();
}
public
MybatisArgumentAdapter
(
AdaType
type
,
Class
<?
extends
IModule
>
clazz
,
String
whereSql
)
{
this
(
type
,
clazz
,
whereSql
,
null
);
}
...
...
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/lck/LckMapper.java
View file @
7e2523cb
...
...
@@ -43,5 +43,11 @@ public class LckMapper {
return
template
.
delete
(
FNAME
+
".delete"
,
map
);
}
public
Integer
deleteByName
(
@Param
(
"key"
)
String
key
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"key"
,
key
);
return
template
.
delete
(
FNAME
+
".deleteByName"
,
map
);
}
}
\ No newline at end of file
gjjs-bd-runtime/pom.xml
View file @
7e2523cb
...
...
@@ -91,6 +91,13 @@
<systemPath>
${basedir}/../lib/ojdbc6-12.1.0.2.jar
</systemPath>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
8.0.33
</version>
<scope>
system
</scope>
<systemPath>
${basedir}/../lib/mysql-connector-java-8.0.11.jar
</systemPath>
</dependency>
</dependencies>
<distributionManagement>
<repository>
...
...
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/IDaoSession.java
View file @
7e2523cb
...
...
@@ -65,6 +65,7 @@ public interface IDaoSession {
void
dbReadset
(
IModuleList
list
,
int
maxSize
);
String
dbName
();
List
<
String
>
dbColumnNames
();
...
...
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractDaoSession.java
View file @
7e2523cb
package
com
.
brilliance
.
mda
.
runtime
.
mda
.
impl
;
import
com.brilliance.mda.runtime.mda.IModule
;
import
com.brilliance.mda.runtime.mda.IModuleList
;
import
com.brilliance.mda.runtime.mda.driver.MdaEnv
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.transaction.TransactionDefinition
;
...
...
@@ -49,4 +51,5 @@ public abstract class AbstractDaoSession {
return
status
.
get
()
!=
null
;
//return false;
}
}
lib/mysql-connector-java-8.0.11.jar
0 → 100644
View file @
7e2523cb
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment