diff --git a/pom.xml b/pom.xml
index 910724b0b5ddfbc4ffe2f14059719be6c996f3b2..cebef2b3d6d69445a656c7ba7472d1b1eefb8db2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,8 +58,8 @@
com.alibaba
- druid
- 1.2.15
+ druid-spring-boot-starter
+ 1.2.16
org.springframework.boot
@@ -93,11 +93,6 @@
RELEASE
test
-
- com.baomidou
- mybatis-plus-core
- 3.5.3.1
-
com.dameng
@@ -115,12 +110,12 @@
com.baomidou
mybatis-plus-boot-starter
3.5.3.1
-
-
- org.springframework.boot
- spring-boot-starter-jdbc
-
-
+
+
+
+
+
+
diff --git a/src/main/java/com/beagle/informix/BaseApplication.java b/src/main/java/com/beagle/informix/BaseApplication.java
index 27b1a5cf713537d038b886fdf3e8fcc72a2139dd..13b3caa2c86e5d640ea54542caae46883e980fab 100644
--- a/src/main/java/com/beagle/informix/BaseApplication.java
+++ b/src/main/java/com/beagle/informix/BaseApplication.java
@@ -1,10 +1,12 @@
package com.beagle.informix;
+import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
+@MapperScan("com.beagle.informix")
//@EnableTransactionManagement(order = 2)
public class BaseApplication {
diff --git a/src/main/java/com/beagle/informix/entity/mybatis/Vccinfo.java b/src/main/java/com/beagle/informix/entity/mybatis/Vccinfo.java
index 2e61498ca9ca8b620c609c0dcef78d085b226bd3..645a4eba896837cf261c9cac069e5a3ab5c15ad1 100644
--- a/src/main/java/com/beagle/informix/entity/mybatis/Vccinfo.java
+++ b/src/main/java/com/beagle/informix/entity/mybatis/Vccinfo.java
@@ -1,41 +1,41 @@
-//package com.beagle.informix.entity.mybatis;
-//import com.baomidou.mybatisplus.annotation.IdType;
-//import com.baomidou.mybatisplus.annotation.TableField;
-//import com.baomidou.mybatisplus.annotation.TableId;
-//import com.baomidou.mybatisplus.annotation.TableName;
-//import lombok.Data;
-//import java.io.Serializable;
-//import java.sql.Blob;
-//
-///**
-// * @author lzz
-// * date 2023/5/30
-// * @version 1.0
-// * description:
-// */
-//@Data
-//@TableName(value = "cti_vccinfo_new")
-//public class Vccinfo implements Serializable {
-// private static final long serialVersionUID = 1L;
-// @TableId(value = "vccid", type = IdType.AUTO )
-// private Integer vId;
-// @TableField(value = "vccname")
-// private String vName;
-// @TableField(value = "effective")
-// private Integer effective;
-// @TableField(value = "agentmax")
-// private Integer agentMax;
-// @TableField(value = "ivrmax")
-// private Integer ivrMax;
-// @TableField(value = "updatekey")
-// private String updateKey;
-// @TableField(value = "tclob")
-// private String tClob;
-// /**
-// * 如果是pg等数据库,字段声明为bytea,则不需要BlobTypeHandler转换,如果声明为blob,则需要转换
-// */
-//
-//// @TableField(value = "tblob", typeHandler = org.apache.ibatis.type.BlobTypeHandler.class)
-// @TableField(value = "tblob")
-// private byte[] tBlob;
-//}
+package com.beagle.informix.entity.mybatis;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import java.io.Serializable;
+import java.sql.Blob;
+
+/**
+ * @author lzz
+ * date 2023/5/30
+ * @version 1.0
+ * description:
+ */
+@Data
+@TableName(value = "cti_vccinfo_new")
+public class Vccinfo implements Serializable {
+ private static final long serialVersionUID = 1L;
+ @TableId(value = "vccid", type = IdType.AUTO )
+ private Integer vId;
+ @TableField(value = "vccname")
+ private String vName;
+ @TableField(value = "effective")
+ private Integer effective;
+ @TableField(value = "agentmax")
+ private Integer agentMax;
+ @TableField(value = "ivrmax")
+ private Integer ivrMax;
+ @TableField(value = "updatekey")
+ private String updateKey;
+ @TableField(value = "tclob")
+ private String tClob;
+ /**
+ * 如果是pg等数据库,字段声明为bytea,则不需要BlobTypeHandler转换,如果声明为blob,则需要转换
+ */
+
+// @TableField(value = "tblob", typeHandler = org.apache.ibatis.type.BlobTypeHandler.class)
+ @TableField(value = "tblob")
+ private byte[] tBlob;
+}
diff --git a/src/main/java/com/beagle/informix/mapper/VccinfoMapper.java b/src/main/java/com/beagle/informix/mapper/VccinfoMapper.java
index 26f54397d9349c38679d38db3d15361755f80f94..021b42fce1526761f4bad94c83bc09d908ee60e9 100644
--- a/src/main/java/com/beagle/informix/mapper/VccinfoMapper.java
+++ b/src/main/java/com/beagle/informix/mapper/VccinfoMapper.java
@@ -1,22 +1,25 @@
-//package com.beagle.informix.mapper;
-//
-//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-//import com.beagle.informix.entity.mybatis.Vccinfo;
-//import org.apache.ibatis.annotations.*;
-//
-//import java.util.List;
-//
-//@Mapper
-//public interface VccinfoMapper extends BaseMapper {
-// @Results(
-// @Result(column = "tblob",property = "tBlobStr")
-// )
-// @Select("SELECT * FROM cti_vccinfo_new where vccid = #{vId}")
-// List queryList(@Param("vId") Integer vId);
-//
-// /**
-// * 必须使用org.apache.ibatis.type.BlobTypeHandler转换后,才能保存到数据库
-// * @param vccinfo
-// */
-// void insertData(@Param("vccinfo") Vccinfo vccinfo);
-//}
+package com.beagle.informix.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.beagle.informix.entity.mybatis.Vccinfo;
+import org.apache.ibatis.annotations.*;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Mapper
+public interface VccinfoMapper extends BaseMapper {
+ @Results(
+ @Result(column = "tblob",property = "tBlobStr")
+ )
+ @Select("SELECT * FROM cti_vccinfo_new where vccid = #{vId}")
+ List queryList(@Param("vId") Integer vId);
+
+ /**
+ * 必须使用org.apache.ibatis.type.BlobTypeHandler转换后,才能保存到数据库
+ * @param vccinfo
+ */
+ void insertData(@Param("vccinfo") Vccinfo vccinfo);
+
+ int selectTest();
+}
diff --git a/src/main/java/com/beagle/informix/service/InformixService.java b/src/main/java/com/beagle/informix/service/InformixService.java
index 5021f3da8a9fbf832bbad3d472770872ff155560..9c38a42064adc51d97ac4308061ab27131d864c7 100644
--- a/src/main/java/com/beagle/informix/service/InformixService.java
+++ b/src/main/java/com/beagle/informix/service/InformixService.java
@@ -1,9 +1,12 @@
package com.beagle.informix.service;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.beagle.informix.entity.mybatis.Vccinfo;
+
/**
* informix(IBM)数据库测试(jdbc、hibernate、ibatis、mybatis)
*/
-public interface InformixService {
+public interface InformixService {
void doConnectJob() throws Exception;
}
diff --git a/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java b/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java
index 3d3053a923cad20caad44e09f547bb9b41857960..5a431089ed38bdeebb0c2b6babcfad0bb11bcaca 100644
--- a/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java
+++ b/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java
@@ -32,6 +32,13 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
this.resourceLoader = resourceLoader;
}
+ public static void main(String[] args) {
+ try {
+ new InformixJdbcProxyServiceImpl(null).doConnectJob();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
/**
* informix.url=jdbc:informix-sqli://localhost:9088/sysadmin:INFORMIXSERVER=informix
* informix.driverClassName=com.informix.jdbc.IfxDriver
@@ -44,45 +51,34 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
*/
@Override
public void doConnectJob() throws Exception{
- // todo 使用jdbc连接proxy,对应的query(clob、blob字段)存在jdbc 类型转换mysql异常的问题
- // Unknown exception: Can not find JDBC type `2005` in column type
+ testAloneConnectionJob();
+ }
+ private void testSameConnectionJob(Connection connection) throws Exception{
Driver driver = getDriver();
Connection conn = getConnection(driver);
- insert(conn);
-// update(conn);
-// query(conn);
-// delete(conn);
+ // 连接一直开启的话,发送的sql在proxy中都是使用一个同一个会话
+ for (int i = 0; i < 100; i++) {
+ String querySQL = "SELECT 1";
+ Statement stat = connection.createStatement();
+ ResultSet resultSet = stat.executeQuery(querySQL);
+ }
closeConnection(conn);
deregisterDriver(driver);
- // Unknown exception: Can not find JDBC type `2005` in column type
- CompletableFuture completableFuture = new CompletableFuture<>();
- ExecutorService executorService = Executors.newFixedThreadPool(500);
-// for (int i = 0; i < 1; i++) {
-// try {
-// Driver driver = getDriver();
-// Connection conn = getConnection(driver);
-// completableFuture.runAsync(()->{
-// try {
-// query(conn);
-// }catch (Exception ee) {
-// ee.printStackTrace();
-// }
-// }, executorService).whenComplete((v, e) -> {
-// if (e != null) {
-// e.printStackTrace();
-// }
-// try {
-// closeConnection(conn);
-// deregisterDriver(driver);
-// }catch (Exception ex) {
-// ex.printStackTrace();
-// }
-// });
-// } catch (Exception e) {
-// throw new RuntimeException(e);
-// }
-// }
}
+
+ private void testAloneConnectionJob() throws Exception{
+ Driver driver = getDriver();
+ for (int i = 0; i < 100; i++) {
+ // 这种情况下的话,每次新建一个连接,在proxy中都会对应新增一个连接
+ Connection conn = getConnection(driver);
+ String querySQL = "SELECT 1";
+ Statement stat = conn.createStatement();
+ ResultSet resultSet = stat.executeQuery(querySQL);
+ closeConnection(conn);
+ }
+ deregisterDriver(driver);
+ }
+
private Driver getDriver() throws Exception{
// 定义informix的驱动信息
String driverUrl = "com.mysql.cj.jdbc.Driver";
diff --git a/src/main/java/com/beagle/informix/service/impl/InformixMybatisServiceImpl.java b/src/main/java/com/beagle/informix/service/impl/InformixMybatisServiceImpl.java
index ca81208872b8e9624d562bc8feaeab1af690f9ad..bfea35dcb68f5a0fe9c13a63f741e8932d3dfb50 100644
--- a/src/main/java/com/beagle/informix/service/impl/InformixMybatisServiceImpl.java
+++ b/src/main/java/com/beagle/informix/service/impl/InformixMybatisServiceImpl.java
@@ -1,101 +1,84 @@
-//package com.beagle.informix.service.impl;
-//
-//import cn.hutool.json.JSONUtil;
-//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-//import com.beagle.informix.entity.mybatis.Vccinfo;
-//import com.beagle.informix.mapper.VccinfoMapper;
-//import com.beagle.informix.service.InformixService;
-//import lombok.extern.slf4j.Slf4j;
-//import org.apache.ibatis.annotations.Result;
-//import org.apache.ibatis.annotations.Results;
-//import org.springframework.core.io.ResourceLoader;
-//import org.springframework.stereotype.Service;
-//
-//import javax.annotation.Resource;
-//import javax.transaction.Transactional;
-//import java.io.File;
-//import java.io.FileInputStream;
-//import java.sql.Connection;
-//import java.sql.Driver;
-//import java.util.List;
-//import java.util.concurrent.CompletableFuture;
-//import java.util.concurrent.ExecutorService;
-//import java.util.concurrent.Executors;
-//
-///**
-// * @author lzz
-// * date 2023/5/29
-// * @version 1.0
-// * description:
-// */
-//@Service("informixMybatisService")
-//@Slf4j
-//public class InformixMybatisServiceImpl extends ServiceImpl implements InformixService {
-// @Resource
-// private ResourceLoader resourceLoader;
-// @Resource
-// private VccinfoMapper vccinfoMapper;
-// @Override
-// @Transactional
-// public void doConnectJob() throws Exception{
-// CompletableFuture completableFuture = new CompletableFuture<>();
-// ExecutorService executorService = Executors.newFixedThreadPool(500);
-// for (int i = 0; i < 500; i++) {
-// try {
-//
-// completableFuture.runAsync(()->{
-// queryMethod();
-// }, executorService).whenComplete((v, e) -> {
-// if (e != null) {
-// e.printStackTrace();
-// }
-// });
-// } catch (Exception e) {
-// throw new RuntimeException(e);
-// }
+package com.beagle.informix.service.impl;
+
+import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.beagle.informix.entity.mybatis.Vccinfo;
+import com.beagle.informix.mapper.VccinfoMapper;
+import com.beagle.informix.service.InformixService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * @author lzz
+ * date 2023/5/29
+ * @version 1.0
+ * description:
+ */
+@Service("informixMybatisService")
+@Slf4j
+public class InformixMybatisServiceImpl extends ServiceImpl implements InformixService {
+ @Resource
+ private ResourceLoader resourceLoader;
+ @Override
+ public void doConnectJob() throws Exception{
+// for (int i = 0; i < 100; i++) {
+// this.baseMapper.selectTest();
// }
-// }
-// private void insertMethod() throws Exception{
-// Vccinfo vccinfo = new Vccinfo();
-// vccinfo.setVId(3);
-// vccinfo.setEffective(1);
-// vccinfo.setVName("mybatis");
-// vccinfo.setIvrMax(1);
-// vccinfo.setAgentMax(1);
-// vccinfo.setUpdateKey("mybatis key");
-// // 组装clob
-// vccinfo.setTClob("测试clob数据!@#@Ddsfsdferewr");
-// // 组装blob数据
-// // 处理blob字段
-// org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:EnableLoopback.exe");
-// File inputStream = resource.getFile();
-// try (FileInputStream fis = new FileInputStream(inputStream)){
-// vccinfo.setTBlob(fis.readAllBytes());
-// }
-// // insert
-// // 如果使用实体保存,则需要在blob字段上新增BlobTypeHandler转换
-// // 如果使用xml的insert保存,也需要在属性上设置BlobTypeHandler转换
-// baseMapper.insertData(vccinfo);
-// }
-//
-// private void updateMethod() throws Exception {
-// LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
-// queryWrapper.eq(Vccinfo::getVId, "ibatis");
-// Vccinfo vccinfo = new Vccinfo();
-// vccinfo.setVName("mybatis-update");
-// baseMapper.update(vccinfo, queryWrapper);
-// }
-//
-// private void queryMethod() {
-// List vccinfoList = vccinfoMapper.queryList(1);
-// log.info("queryAll:{}", JSONUtil.toJsonStr(vccinfoList));
-// }
-// private void delete() {
-// LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
-// queryWrapper.eq(Vccinfo::getVId, "ibatis");
-// baseMapper.delete(queryWrapper);
-// }
-//
-//}
+ ExecutorService executorService = Executors.newCachedThreadPool();
+ for (int i = 0; i < 1; i++) {
+ executorService.submit(()->{
+ System.out.println(this.baseMapper.selectTest());
+ });
+ }
+ }
+ private void insertMethod() throws Exception{
+ Vccinfo vccinfo = new Vccinfo();
+ vccinfo.setVId(3);
+ vccinfo.setEffective(1);
+ vccinfo.setVName("mybatis");
+ vccinfo.setIvrMax(1);
+ vccinfo.setAgentMax(1);
+ vccinfo.setUpdateKey("mybatis key");
+ // 组装clob
+ vccinfo.setTClob("测试clob数据!@#@Ddsfsdferewr");
+ // 组装blob数据
+ // 处理blob字段
+ org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:EnableLoopback.exe");
+ File inputStream = resource.getFile();
+ try (FileInputStream fis = new FileInputStream(inputStream)){
+ vccinfo.setTBlob(fis.readAllBytes());
+ }
+ // insert
+ // 如果使用实体保存,则需要在blob字段上新增BlobTypeHandler转换
+ // 如果使用xml的insert保存,也需要在属性上设置BlobTypeHandler转换
+ baseMapper.insertData(vccinfo);
+ }
+
+ private void updateMethod() throws Exception {
+ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.eq(Vccinfo::getVId, "ibatis");
+ Vccinfo vccinfo = new Vccinfo();
+ vccinfo.setVName("mybatis-update");
+ baseMapper.update(vccinfo, queryWrapper);
+ }
+
+ private void queryMethod() {
+ List vccinfoList = this.baseMapper.queryList(1);
+ log.info("queryAll:{}", JSONUtil.toJsonStr(vccinfoList));
+ }
+ private void delete() {
+ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.eq(Vccinfo::getVId, "ibatis");
+ baseMapper.delete(queryWrapper);
+ }
+
+}
diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml
index 8ae24e87b61e9bd53986d81c3021c021ed53bd8e..b0faffcb08c817bcdff5c269e7f97fe30957d067 100644
--- a/src/main/resources/application.yaml
+++ b/src/main/resources/application.yaml
@@ -1,32 +1,32 @@
-#spring:
-# datasource:
-## url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai
-# url: jdbc:mysql://localhost:3307
-## url: jdbc:mysql://localhost:3307/SYSDBA?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai
-## url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true
-# username: root
-# password: Apurelove9014
-# type: com.alibaba.druid.pool.DruidDataSource
-# druid:
-# max-active: 500
-# max-wait: 60000
-# initial-size: 500
-# connect-timeout: 30
-# min-idle: 500
-# min-evictable-idle-time-millis: 300000
-# validation-query: select 1
-# test-on-borrow: false
-# test-on-return: false
-# test-while-idle: false
-# time-between-eviction-runs-millis: 60000
-## driver-class-name: com.informix.jdbc.IfxDriver
-# driver-class-name: com.mysql.jdbc.Driver # com.mysql.cj.jdbc.Driver
-# jpa:
-# properties:
-# hibernate:
-# dialect: org.hibernate.dialect.InformixDialect
-# format_sql: true
-#mybatis-plus:
-# configuration:
-# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
-# map-underscore-to-camel-case: true
\ No newline at end of file
+spring:
+ datasource:
+# url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai
+ url: jdbc:mysql://localhost:3307
+# url: jdbc:mysql://localhost:3307/SYSDBA?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai
+# url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true
+ username: root
+ password: Apurelove9014
+ type: com.alibaba.druid.pool.DruidDataSource
+ druid:
+ max-active: 500
+ max-wait: 60000
+ initial-size: 500
+ connect-timeout: 30
+ min-idle: 20
+ min-evictable-idle-time-millis: 300000
+ validation-query: select 1
+ test-on-borrow: false
+ test-on-return: false
+ test-while-idle: false
+ time-between-eviction-runs-millis: 60000
+ # driver-class-name: com.informix.jdbc.IfxDriver
+ driver-class-name: com.mysql.jdbc.Driver # com.mysql.cj.jdbc.Driver
+ jpa:
+ properties:
+ hibernate:
+ dialect: org.hibernate.dialect.InformixDialect
+ format_sql: true
+mybatis-plus:
+ configuration:
+ log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+ map-underscore-to-camel-case: true
\ No newline at end of file
diff --git a/src/test/java/com/beagle/informix/service/impl/InformixServiceTest.java b/src/test/java/com/beagle/informix/service/impl/InformixServiceTest.java
index da64c8289a4d228a3a4a76e3e175369f6a1e4465..e742701cd02f43d0b60f13b59cd97c38f4dc1c5e 100644
--- a/src/test/java/com/beagle/informix/service/impl/InformixServiceTest.java
+++ b/src/test/java/com/beagle/informix/service/impl/InformixServiceTest.java
@@ -22,7 +22,7 @@ class InformixServiceTest {
private InformixService informixHibernateService;
// @Resource(name = "informixIbatisService")
// private InformixService informixIbatisService;
-// @Resource(name = "informixMybatisService")
+ @Resource(name = "informixMybatisService")
private InformixService informixMybatisService;
// @Test
// void testJdbcInfo() {