Commit 3acd910f authored by 李振振's avatar 李振振

11

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