Commit fe7d9fcc authored by 李振振's avatar 李振振

polardbx的curd测试

parent b42edb8a
...@@ -17,39 +17,40 @@ ...@@ -17,39 +17,40 @@
<java.version>11</java.version> <java.version>11</java.version>
</properties> </properties>
<dependencies> <dependencies>
<!-- https://mvnrepository.com/artifact/com.ibm.informix/jdbc -->
<dependency>
<groupId>com.ibm.informix</groupId>
<artifactId>jdbc</artifactId>
<version>4.50.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version> <version>8.0.28</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.6.0</version>
</dependency>
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
<version>5.8.15</version> <version>5.8.15</version>
</dependency> </dependency>
<dependency> <!-- <dependency>-->
<groupId>org.springframework.boot</groupId> <!-- <groupId>org.springframework.boot</groupId>-->
<artifactId>spring-boot-starter-data-jpa</artifactId> <!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
<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>-->
<dependency> <!-- <dependency>-->
<groupId>com.alibaba</groupId> <!-- <groupId>com.alibaba</groupId>-->
<artifactId>druid-spring-boot-starter</artifactId> <!-- <artifactId>druid-spring-boot-starter</artifactId>-->
<version>1.2.15</version> <!-- <version>1.2.15</version>-->
</dependency> <!-- </dependency>-->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
...@@ -97,6 +98,19 @@ ...@@ -97,6 +98,19 @@
<artifactId>mybatis-plus-core</artifactId> <artifactId>mybatis-plus-core</artifactId>
<version>3.5.3.1</version> <version>3.5.3.1</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.dameng/DmJdbcDriver18 -->
<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
<version>8.1.2.192</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.dameng/Dm8JdbcDriver18 -->
<!-- <dependency>-->
<!-- <groupId>com.dameng</groupId>-->
<!-- <artifactId>Dm8JdbcDriver18</artifactId>-->
<!-- <version>8.1.1.49</version>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>com.baomidou</groupId> <groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId> <artifactId>mybatis-plus-boot-starter</artifactId>
...@@ -116,7 +130,6 @@ ...@@ -116,7 +130,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration> <configuration>
<excludes> <excludes>
<exclude> <exclude>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
...@@ -157,6 +170,14 @@ ...@@ -157,6 +170,14 @@
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build> </build>
</project> </project>
...@@ -2,10 +2,10 @@ package com.beagle.informix; ...@@ -2,10 +2,10 @@ package com.beagle.informix;
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
@EnableTransactionManagement(order = 2) //@EnableTransactionManagement(order = 2)
public class BaseApplication { public class BaseApplication {
public static void main(String[] args) { public static void main(String[] args) {
......
package com.beagle.informix.entity.jpa; //package com.beagle.informix.entity.jpa;
//
import lombok.Data; //import lombok.Data;
//
import javax.persistence.*; //import javax.persistence.*;
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
@Table(name = "cti_vccinfo_new") ////@、Table(name = "cti_vccinfo_new")
@Entity ////@Entity
public class Vccinfo implements Serializable { //public class Vccinfo implements Serializable {
private static final long serialVersionUID = 1L; // private static final long serialVersionUID = 1L;
@Id // @Id
// todo 这个id自动生成方式还需测试 // // todo 这个id自动生成方式还需测试
@Column(name = "vccid") // @Column(name = "vccid")
@GeneratedValue(strategy = GenerationType.IDENTITY) // @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer vId; // private Integer vId;
@Column(name = "vccname") // @Column(name = "vccname")
private String vName; // private String vName;
@Column(name = "effective") // @Column(name = "effective")
private Integer effective; // private Integer effective;
@Column(name = "agentmax") // @Column(name = "agentmax")
private Integer agentMax; // private Integer agentMax;
@Column(name = "ivrmax") // @Column(name = "ivrmax")
private Integer ivrMax; // private Integer ivrMax;
@Column(name = "updatekey") // @Column(name = "updatekey")
private String updateKey; // private String updateKey;
@Column(name = "tclob") // @Column(name = "tclob")
@Basic(fetch = FetchType.LAZY) // @Basic(fetch = FetchType.LAZY)
private String tClob; // private String tClob;
//
@Lob // @Lob
@Basic(fetch = FetchType.LAZY) // @Basic(fetch = FetchType.LAZY)
@Column(name = "tblob", columnDefinition = "longblob", nullable = true) // @Column(name = "tblob", columnDefinition = "longblob", nullable = true)
private byte[] tBlob; // private byte[] tBlob;
} //}
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 java.util.List; //import java.util.List;
//
@Mapper //@Mapper
public interface VccinfoMapper extends BaseMapper<Vccinfo> { //public interface VccinfoMapper extends BaseMapper<Vccinfo> {
@Results( // @Results(
@Result(column = "tblob",property = "tBlobStr") // @Result(column = "tblob",property = "tBlobStr")
) // )
@Select("SELECT * FROM cti_vccinfo_new where vccid = #{vId}") // @Select("SELECT * FROM cti_vccinfo_new where vccid = #{vId}")
List<Vccinfo> queryList(@Param("vId") Integer vId); // List<Vccinfo> queryList(@Param("vId") Integer vId);
//
/** // /**
* 必须使用org.apache.ibatis.type.BlobTypeHandler转换后,才能保存到数据库 // * 必须使用org.apache.ibatis.type.BlobTypeHandler转换后,才能保存到数据库
* @param vccinfo // * @param vccinfo
*/ // */
void insertData(@Param("vccinfo") Vccinfo vccinfo); // void insertData(@Param("vccinfo") Vccinfo vccinfo);
} //}
package com.beagle.informix.repository; //package com.beagle.informix.repository;
//
import com.beagle.informix.entity.jpa.Vccinfo; ////import com.beagle.informix.entity.jpa.Vccinfo;
import org.springframework.data.repository.CrudRepository; ////import org.springframework.data.repository.CrudRepository;
//
import java.util.List; //import java.util.List;
//
/** ///**
* @author lzz // * @author lzz
* date 2023/5/30 // * date 2023/5/30
* @version 1.0 // * @version 1.0
* description: // * description:
*/ // */
public interface VccinfoDao { //public interface VccinfoDao {
Vccinfo getVccInfoById(Integer vId); // Vccinfo getVccInfoById(Integer vId);
List<Vccinfo> getAllVccInfo(); // List<Vccinfo> getAllVccInfo();
void addVccinfo(Vccinfo vccinfo); // void addVccinfo(Vccinfo vccinfo);
void updateVccinfo(Vccinfo vccinfo); // void updateVccinfo(Vccinfo vccinfo);
void deleteVccinfo(Integer vId); // void deleteVccinfo(Integer vId);
} //}
package com.beagle.informix.repository.impl; //package com.beagle.informix.repository.impl;
//
import com.beagle.informix.entity.jpa.Vccinfo; //import com.beagle.informix.entity.jpa.Vccinfo;
import com.beagle.informix.repository.VccinfoDao; //import com.beagle.informix.repository.VccinfoDao;
//
import org.springframework.stereotype.Repository; //import org.springframework.stereotype.Repository;
//
import javax.persistence.EntityManager; ////import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction; ////import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceContext; ////import javax.persistence.PersistenceContext;
import javax.persistence.Query; ////import javax.persistence.Query;
import javax.transaction.Transactional; ////import javax.transaction.Transactional;
import java.util.List; //import java.util.List;
//
/** ///**
* @author lzz // * @author lzz
* date 2023/5/30 // * date 2023/5/30
* @version 1.0 // * @version 1.0
* description: // * description:
*/ // */
@Repository //@Repository
public class VccinfoDaoImpl implements VccinfoDao { //public class VccinfoDaoImpl implements VccinfoDao {
@PersistenceContext //// @PersistenceContext
private EntityManager entityManager; //// private EntityManager entityManager;
//
@Override // @Override
public Vccinfo getVccInfoById(Integer vId) { // public Vccinfo getVccInfoById(Integer vId) {
return entityManager.find(Vccinfo.class, vId); // return entityManager.find(Vccinfo.class, vId);
} // }
//
@Override // @Override
public List<Vccinfo> getAllVccInfo() { // public List<Vccinfo> getAllVccInfo() {
String sql = "FROM Vccinfo as vInfo ORDER BY vInfo.effective"; // String sql = "FROM Vccinfo as vInfo ORDER BY vInfo.effective";
return (List<Vccinfo>) entityManager.createQuery(sql).getResultList(); // return (List<Vccinfo>) entityManager.createQuery(sql).getResultList();
} // }
//
@Override // @Override
public void addVccinfo(Vccinfo vccinfo) { // public void addVccinfo(Vccinfo vccinfo) {
entityManager.persist(vccinfo); // entityManager.persist(vccinfo);
// entityManager.createNativeQuery("insert into cti_vccinfo_new (vccid ,vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob)\n" + //// entityManager.createNativeQuery("insert into cti_vccinfo_new (vccid ,vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob)\n" +
// " VALUES(?,?,?,?,?,?,?,?") //// " VALUES(?,?,?,?,?,?,?,?")
// .setParameter(1, vccinfo.getVId()) //// .setParameter(1, vccinfo.getVId())
// .setParameter(2, vccinfo.getVName()) //// .setParameter(2, vccinfo.getVName())
// .setParameter(3, vccinfo.getEffective()) //// .setParameter(3, vccinfo.getEffective())
// .setParameter(4, vccinfo.getAgentMax()) //// .setParameter(4, vccinfo.getAgentMax())
// .setParameter(5, vccinfo.getIvrMax()) //// .setParameter(5, vccinfo.getIvrMax())
// .setParameter(6, vccinfo.getUpdateKey()) //// .setParameter(6, vccinfo.getUpdateKey())
// .setParameter(7, vccinfo.getTClob()) //// .setParameter(7, vccinfo.getTClob())
// .setParameter(8, vccinfo.getTBlob()).executeUpdate(); //// .setParameter(8, vccinfo.getTBlob()).executeUpdate();
//
} // }
//
@Override // @Override
@Transactional // @Transactional
public void updateVccinfo(Vccinfo vccinfo) { // public void updateVccinfo(Vccinfo vccinfo) {
// 提示异常 Caused by: java.sql.SQLException: Code-set conversion function failed due to illegal sequence or invalid value. // // 提示异常 Caused by: java.sql.SQLException: Code-set conversion function failed due to illegal sequence or invalid value.
/*Vccinfo old = entityManager.find(Vccinfo.class, "jpa"); // /*Vccinfo old = entityManager.find(Vccinfo.class, "jpa");
old.setVName("informix—name"); // old.setVName("informix—name");
entityManager.merge(old);*/ // entityManager.merge(old);*/
//
// 第一步:准备好jpql // // 第一步:准备好jpql
// ?1表示第一个参数,?2表示第二个参数 //// ?1表示第一个参数,?2表示第二个参数
String jpql = "update Vccinfo s set s.vName = ?1 where s.vId = ?2"; // String jpql = "update Vccinfo s set s.vName = ?1 where s.vId = ?2";
EntityTransaction transaction = null; // EntityTransaction transaction = null;
//
try { // try {
// transaction = entityManager.getTransaction(); //// transaction = entityManager.getTransaction();
// transaction.begin(); //// transaction.begin();
//
// 第二步:设置jpql的参数 // // 第二步:设置jpql的参数
Query query = entityManager.createQuery(jpql); // Query query = entityManager.createQuery(jpql);
query.setParameter(1, "赵六666999"); // query.setParameter(1, "赵六666999");
query.setParameter(2, "%jpa%"); // query.setParameter(2, "%jpa%");
//
// 第三步:执行jpql // // 第三步:执行jpql
int rows = query.executeUpdate(); // int rows = query.executeUpdate();
System.out.println("影响的行数:" + rows); // System.out.println("影响的行数:" + rows);
//
transaction.commit(); // transaction.commit();
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
// transaction.rollback(); //// transaction.rollback();
} finally { // } finally {
entityManager.close(); // entityManager.close();
} // }
} // }
//
@Override // @Override
public void deleteVccinfo(Integer vId) { // public void deleteVccinfo(Integer vId) {
entityManager.remove(getVccInfoById(vId)); // entityManager.remove(getVccInfoById(vId));
} // }
} //}
package com.beagle.informix.service.impl; //package com.beagle.informix.service.impl;
//
import cn.hutool.json.JSONUtil; //import cn.hutool.json.JSONUtil;
import com.beagle.informix.entity.jpa.Vccinfo; ////import com.beagle.informix.entity.jpa.Vccinfo;
import com.beagle.informix.repository.VccinfoDao; //import com.beagle.informix.repository.VccinfoDao;
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.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
//
import javax.annotation.Resource; //import javax.annotation.Resource;
import javax.transaction.Transactional; ////import javax.transaction.Transactional;
import java.io.File; //import java.io.File;
import java.io.FileInputStream; //import java.io.FileInputStream;
import java.util.List; //import java.util.List;
//
/** ///**
* Caused by: java.sql.SQLException: Transactions not supported // * Caused by: java.sql.SQLException: Transactions not supported
* ifx事务默认不开启,需要使用命令 通过ontape -s -B dbname来设置,注意不是服务名,而是数据库名 // * ifx事务默认不开启,需要使用命令 通过ontape -s -B dbname来设置,注意不是服务名,而是数据库名
* // *
* Code-set conversion function failed due to illegal sequence or invalid value. // * Code-set conversion function failed due to illegal sequence or invalid value.
* 启动失败字符集错误,暂时还未找到解决办法 // * 启动失败字符集错误,暂时还未找到解决办法
* @author lzz // * @author lzz
* date 2023/5/29 // * date 2023/5/29
* @version 1.0 // * @version 1.0
* description: // * description:
*/ // */
@Slf4j //@Slf4j
@Service("informixHibernateService") //@Service("informixHibernateService")
public class InformixHibernateServiceImpl implements InformixService { //public class InformixHibernateServiceImpl implements InformixService {
@Resource // @Resource
private VccinfoDao vccinfoDao; // private VccinfoDao vccinfoDao;
@Resource // @Resource
private ResourceLoader resourceLoader; // private ResourceLoader resourceLoader;
@Override // @Override
@Transactional //// @Transactional
public void doConnectJob() throws Exception{ // public void doConnectJob() throws Exception{
insert(); // insert();
// update(); //// update();
// query(); //// query();
// delete(); //// delete();
} // }
private void insert() throws Exception{ // private void insert() throws Exception{
Vccinfo vccinfo = new Vccinfo(); // Vccinfo vccinfo = new Vccinfo();
// vccinfo.setVId(23); //// vccinfo.setVId(23);
vccinfo.setEffective(1); // vccinfo.setEffective(1);
vccinfo.setVName("hibernate"); // vccinfo.setVName("hibernate");
vccinfo.setIvrMax(1); // vccinfo.setIvrMax(1);
vccinfo.setAgentMax(1); // vccinfo.setAgentMax(1);
vccinfo.setUpdateKey("jpa key"); // vccinfo.setUpdateKey("jpa key");
// 组装clob // // 组装clob
vccinfo.setTClob("@Ddsfsdferewr"); // vccinfo.setTClob("@Ddsfsdferewr");
// 组装blob数据 // // 组装blob数据
// 处理blob字段 // // 处理blob字段
// proxy 处理blob字段时,存放二进制文件(exe),打开异常,存放文本时正常 // // proxy 处理blob字段时,存放二进制文件(exe),打开异常,存放文本时正常
org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:test1.doc"); // org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:test1.doc");
File inputStream = resource.getFile(); // File inputStream = resource.getFile();
try (FileInputStream fis = new FileInputStream(inputStream)){ // try (FileInputStream fis = new FileInputStream(inputStream)){
vccinfo.setTBlob(fis.readAllBytes()); // vccinfo.setTBlob(fis.readAllBytes());
} // }
// insert // // insert
vccinfoDao.addVccinfo(vccinfo); // vccinfoDao.addVccinfo(vccinfo);
} // }
//
private void update(int id) { // private void update(int id) {
Vccinfo vccinfo = new Vccinfo(); // Vccinfo vccinfo = new Vccinfo();
vccinfo.setVId(id); // vccinfo.setVId(id);
vccinfoDao.updateVccinfo(vccinfo); // vccinfoDao.updateVccinfo(vccinfo);
} // }
private void query(int id) { // private void query(int id) {
//
//
List<Vccinfo> vccinfoList = vccinfoDao.getAllVccInfo(); // List<Vccinfo> vccinfoList = vccinfoDao.getAllVccInfo();
log.info("queryAll:{}",JSONUtil.toJsonStr(vccinfoDao.getAllVccInfo())); // log.info("queryAll:{}",JSONUtil.toJsonStr(vccinfoDao.getAllVccInfo()));
log.info("queryById:{}",JSONUtil.toJsonStr(vccinfoDao.getVccInfoById(id))); // log.info("queryById:{}",JSONUtil.toJsonStr(vccinfoDao.getVccInfoById(id)));
} // }
private void delete(int id) { // private void delete(int id) {
vccinfoDao.deleteVccinfo(id); // vccinfoDao.deleteVccinfo(id);
} // }
} //}
package com.beagle.informix.service.impl; //package com.beagle.informix.service.impl;
//
import com.beagle.informix.service.InformixService; //import com.beagle.informix.service.InformixService;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
//
/** ///**
* @author lzz // * @author lzz
* date 2023/5/29 // * date 2023/5/29
* @version 1.0 // * @version 1.0
* description: // * description:
*/ // */
@Service("informixIbatisService") //@Service("informixIbatisService")
public class InformixIbatisServiceImpl implements InformixService { //public class InformixIbatisServiceImpl implements InformixService {
@Override // @Override
public void doConnectJob() { // public void doConnectJob() {
// 手写连接jdbc驱动 // // 手写连接jdbc驱动
} // }
//
} //}
...@@ -44,44 +44,44 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -44,44 +44,44 @@ 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异常的问题 // todo 使用jdbc连接proxy,对应的query(clob、blob字段)存在jdbc 类型转换mysql异常的问题
// // Unknown exception: Can not find JDBC type `2005` in column type
// Driver driver = getDriver();
// Connection conn = getConnection(driver);
// insert(conn);
//// update(conn);
//// query(conn);
//// delete(conn);
// closeConnection(conn);
// deregisterDriver(driver);
// Unknown exception: Can not find JDBC type `2005` in column type // 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 < 500; i++) {
try {
Driver driver = getDriver(); Driver driver = getDriver();
Connection conn = getConnection(driver); Connection conn = getConnection(driver);
completableFuture.runAsync(()->{ insert(conn);
try { // update(conn);
query(conn); // query(conn);
}catch (Exception ee) { // delete(conn);
ee.printStackTrace();
}
}, executorService).whenComplete((v, e) -> {
if (e != null) {
e.printStackTrace();
}
try {
closeConnection(conn); closeConnection(conn);
deregisterDriver(driver); deregisterDriver(driver);
}catch (Exception ex) { // Unknown exception: Can not find JDBC type `2005` in column type
ex.printStackTrace(); CompletableFuture completableFuture = new CompletableFuture<>();
} ExecutorService executorService = Executors.newFixedThreadPool(500);
}); // for (int i = 0; i < 1; i++) {
} catch (Exception e) { // try {
throw new RuntimeException(e); // 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 Driver getDriver() throws Exception{ private Driver getDriver() throws Exception{
// 定义informix的驱动信息 // 定义informix的驱动信息
...@@ -98,7 +98,7 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -98,7 +98,7 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
// 创建testdb数据库、my_test_create_table表 // 创建testdb数据库、my_test_create_table表
// 现在模拟插入、更新、删除、查询等sql // 现在模拟插入、更新、删除、查询等sql
// 插入 // 插入
String insertSql = "insert into cti_vccinfo_new (vccid ,vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob) values (?, ? , ?, ?, ? , ?,?,? )"; String insertSql = "insert into SYSDBA.cti_vccinfo_new (vccid ,vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob) values (?, ? , ?, ?, ? , ?,?,? )";
PreparedStatement stat = conn.prepareStatement(insertSql); PreparedStatement stat = conn.prepareStatement(insertSql);
stat.setObject(1, "123456"); stat.setObject(1, "123456");
stat.setObject(2, "vname"); stat.setObject(2, "vname");
...@@ -126,9 +126,9 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -126,9 +126,9 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
stat.executeUpdate(); stat.executeUpdate();
} }
private void query(Connection conn) throws Exception { private void query(Connection conn) throws Exception {
String querySQL = "SELECT id FROM sc_test "; String querySQL = "SELECT id FROM sc_test";
PreparedStatement stat = conn.prepareStatement(querySQL); Statement stat = conn.createStatement();
ResultSet resultSet = stat.executeQuery(); ResultSet resultSet = stat.executeQuery(querySQL);
} }
...@@ -142,10 +142,10 @@ public class InformixJdbcProxyServiceImpl implements InformixService { ...@@ -142,10 +142,10 @@ public class InformixJdbcProxyServiceImpl implements InformixService {
Properties properties = new Properties(); Properties properties = new Properties();
// 组装连接数据库信息 // 组装连接数据库信息
// jdbc:informix-sqli://<server>:<port1526>/<database>:informixserver=<dbservername> // jdbc:informix-sqli://<server>:<port1526>/<database>:informixserver=<dbservername>
StringBuilder jdbcBuilder = new StringBuilder("jdbc:mysql://localhost:3307"); StringBuilder jdbcBuilder = new StringBuilder("jdbc:mysql://localhost:3307")
// .append("/") // .append("/")
// .append("SYSDBA") // .append("SYSDBA");
// .append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true"); .append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true");
DriverManager.setLoginTimeout(10); DriverManager.setLoginTimeout(10);
properties.put("user", "root"); properties.put("user", "root");
properties.put("password", "Apurelove9014"); properties.put("password", "Apurelove9014");
......
...@@ -46,13 +46,40 @@ public class InformixJdbcServiceImpl implements InformixService { ...@@ -46,13 +46,40 @@ public class InformixJdbcServiceImpl implements InformixService {
public void doConnectJob() throws Exception{ public void doConnectJob() throws Exception{
Driver driver = getDriver(); Driver driver = getDriver();
Connection conn = getConnection(driver); Connection conn = getConnection(driver);
insert(conn); // updateTable(conn);
update(conn); createTable(conn);
query(conn); // insert(conn);
delete(conn); // update(conn);
// query(conn);
// delete(conn);
// createTable2(conn);
deregisterDriver(driver); deregisterDriver(driver);
closeConnection(conn); closeConnection(conn);
} }
private void createTable(Connection connection) throws Exception{
String sql = "CREATE SEQUENCE if not exists engine_test45_id_seq INCREMENT BY 1 START WITH 1 MINVALUE 1 MAXVALUE 999999999;\nCREATE TABLE engine_test45 (id INTEGER DEFAULT engine_test44_id_seq.Nextval NOT NULL PRIMARY KEY,ffff TIMESTAMP(3));\nCOMMENT ON TABLE engine_test45 IS 'sdfadf';";
Statement statement = connection.createStatement();
statement.execute(sql);
}
// 不能执行ddl语句
private void createTable2(Connection connection) throws Exception{
String sql = "CREATE TABLE engine_test45 (id INTEGER NOT NULL PRIMARY KEY,ffff TIMESTAMP(3));\n" +
"CREATE TABLE engine_test46 (id INTEGER NOT NULL PRIMARY KEY,ffff TIMESTAMP(3));\n" +
"CREATE TABLE engine_test47 (id INTEGER NOT NULL PRIMARY KEY,ffff TIMESTAMP(3));";
Statement statement = connection.createStatement();
statement.executeUpdate(sql);
}
// ok
private void updateTable(Connection connection) throws Exception{
String sql = "update sc_test set name = 'test' where id = 3;\n" +
"update sc_test set name = 'test' where id = 2;\n" +
"update sc_test set name = 'test' where id = 4;";
Statement statement = connection.createStatement();
statement.execute(sql);
}
private void insert(Connection conn) throws Exception{ private void insert(Connection conn) throws Exception{
// 创建testdb数据库、my_test_create_table表 // 创建testdb数据库、my_test_create_table表
// 现在模拟插入、更新、删除、查询等sql // 现在模拟插入、更新、删除、查询等sql
...@@ -85,27 +112,11 @@ public class InformixJdbcServiceImpl implements InformixService { ...@@ -85,27 +112,11 @@ public class InformixJdbcServiceImpl implements InformixService {
stat.executeUpdate(); stat.executeUpdate();
} }
private void query(Connection conn) throws Exception { private void query(Connection conn) throws Exception {
String querySQL = "select * from cti_vccinfo_new where vccid = '123456' "; String querySQL = "select * from cti_vccinfo_new;\n" +
"select * from engine_test14;\n" +
"select * from sc_test;";
PreparedStatement stat = conn.prepareStatement(querySQL); PreparedStatement stat = conn.prepareStatement(querySQL);
ResultSet resultSet = stat.executeQuery(); ResultSet resultSet = stat.executeQuery();
if (resultSet != null) {
while (resultSet.next()) {
log.info("vccid =>" + resultSet.getString("vccid"));
Clob clob = resultSet.getClob("tclob");
BufferedReader reader = new BufferedReader(clob.getCharacterStream());
String clobStr = "";
String finalClobStr = "";
while ((clobStr = reader.readLine())!= null) {
finalClobStr += clobStr;
}
log.info("tclob =>" + finalClobStr);
Blob blob = resultSet.getBlob("tblob");
BufferedInputStream bins= new BufferedInputStream(blob.getBinaryStream());
byte [] bytes = bins.readAllBytes();
String blobStr= new String(bytes, StandardCharsets.UTF_8);
log.info("tblob =>" + blobStr);
}
}
} }
private void delete(Connection conn) throws Exception{ private void delete(Connection conn) throws Exception{
String deleteSql = "delete from cti_vccinfo_new where vccid = '123456' "; String deleteSql = "delete from cti_vccinfo_new where vccid = '123456' ";
...@@ -116,19 +127,16 @@ public class InformixJdbcServiceImpl implements InformixService { ...@@ -116,19 +127,16 @@ public class InformixJdbcServiceImpl implements InformixService {
Properties properties = new Properties(); Properties properties = new Properties();
// 组装连接数据库信息 // 组装连接数据库信息
// jdbc:informix-sqli://<server>:<port1526>/<database>:informixserver=<dbservername> // jdbc:informix-sqli://<server>:<port1526>/<database>:informixserver=<dbservername>
StringBuilder jdbcBuilder = new StringBuilder("jdbc:informix-sqli://") StringBuilder jdbcBuilder = new StringBuilder("jdbc:dm://")
.append("localhost:9088") .append("localhost:5236");
.append("/")
.append("testdb")
.append(":INFORMIXSERVER=informix");
DriverManager.setLoginTimeout(10); DriverManager.setLoginTimeout(10);
properties.put("user", "informix"); properties.put("user", "SYSDBA");
properties.put("password", "in4mix"); properties.put("password", "SYSDBA");
return DriverManager.getConnection(jdbcBuilder.toString(), properties); return DriverManager.getConnection(jdbcBuilder.toString(), properties);
} }
private Driver getDriver() throws Exception{ private Driver getDriver() throws Exception{
// 定义informix的驱动信息 // 定义informix的驱动信息
String driverUrl = "com.informix.jdbc.IfxDriver"; String driverUrl = "dm.jdbc.driver.DmDriver";
// 还需要加入informix的jdbc驱动jar包 // 还需要加入informix的jdbc驱动jar包
Class<?> driverClass = Class.forName(driverUrl); Class<?> driverClass = Class.forName(driverUrl);
return (Driver) driverClass.getConstructor().newInstance(); return (Driver) driverClass.getConstructor().newInstance();
......
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.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.apache.ibatis.annotations.Result; //import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results; //import org.apache.ibatis.annotations.Results;
import org.springframework.core.io.ResourceLoader; //import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
//
import javax.annotation.Resource; //import javax.annotation.Resource;
import javax.transaction.Transactional; //import javax.transaction.Transactional;
import java.io.File; //import java.io.File;
import java.io.FileInputStream; //import java.io.FileInputStream;
import java.sql.Connection; //import java.sql.Connection;
import java.sql.Driver; //import java.sql.Driver;
import java.util.List; //import java.util.List;
import java.util.concurrent.CompletableFuture; //import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService; //import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; //import java.util.concurrent.Executors;
//
/** ///**
* @author lzz // * @author lzz
* date 2023/5/29 // * date 2023/5/29
* @version 1.0 // * @version 1.0
* description: // * description:
*/ // */
@Service("informixMybatisService") //@Service("informixMybatisService")
@Slf4j //@Slf4j
public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccinfo> implements InformixService { //public class InformixMybatisServiceImpl extends ServiceImpl<VccinfoMapper, Vccinfo> implements InformixService {
@Resource // @Resource
private ResourceLoader resourceLoader; // private ResourceLoader resourceLoader;
@Resource // @Resource
private VccinfoMapper vccinfoMapper; // private VccinfoMapper vccinfoMapper;
@Override // @Override
@Transactional // @Transactional
public void doConnectJob() throws Exception{ // public void doConnectJob() throws Exception{
CompletableFuture completableFuture = new CompletableFuture<>(); // CompletableFuture completableFuture = new CompletableFuture<>();
ExecutorService executorService = Executors.newFixedThreadPool(500); // ExecutorService executorService = Executors.newFixedThreadPool(500);
for (int i = 0; i < 500; i++) { // for (int i = 0; i < 500; i++) {
try { // try {
//
completableFuture.runAsync(()->{ // completableFuture.runAsync(()->{
queryMethod(); // queryMethod();
}, executorService).whenComplete((v, e) -> { // }, executorService).whenComplete((v, e) -> {
if (e != null) { // if (e != null) {
e.printStackTrace(); // e.printStackTrace();
} // }
}); // });
} catch (Exception e) { // } catch (Exception e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
} // }
} // }
private void insertMethod() throws Exception{ // private void insertMethod() throws Exception{
Vccinfo vccinfo = new Vccinfo(); // Vccinfo vccinfo = new Vccinfo();
vccinfo.setVId(3); // vccinfo.setVId(3);
vccinfo.setEffective(1); // vccinfo.setEffective(1);
vccinfo.setVName("mybatis"); // vccinfo.setVName("mybatis");
vccinfo.setIvrMax(1); // vccinfo.setIvrMax(1);
vccinfo.setAgentMax(1); // vccinfo.setAgentMax(1);
vccinfo.setUpdateKey("mybatis key"); // vccinfo.setUpdateKey("mybatis key");
// 组装clob // // 组装clob
vccinfo.setTClob("测试clob数据!@#@Ddsfsdferewr"); // vccinfo.setTClob("测试clob数据!@#@Ddsfsdferewr");
// 组装blob数据 // // 组装blob数据
// 处理blob字段 // // 处理blob字段
org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:EnableLoopback.exe"); // org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:EnableLoopback.exe");
File inputStream = resource.getFile(); // File inputStream = resource.getFile();
try (FileInputStream fis = new FileInputStream(inputStream)){ // try (FileInputStream fis = new FileInputStream(inputStream)){
vccinfo.setTBlob(fis.readAllBytes()); // vccinfo.setTBlob(fis.readAllBytes());
} // }
// insert // // insert
// 如果使用实体保存,则需要在blob字段上新增BlobTypeHandler转换 // // 如果使用实体保存,则需要在blob字段上新增BlobTypeHandler转换
// 如果使用xml的insert保存,也需要在属性上设置BlobTypeHandler转换 // // 如果使用xml的insert保存,也需要在属性上设置BlobTypeHandler转换
baseMapper.insertData(vccinfo); // baseMapper.insertData(vccinfo);
} // }
//
private void updateMethod() throws Exception { // private void updateMethod() throws Exception {
LambdaQueryWrapper<Vccinfo> queryWrapper = new LambdaQueryWrapper<>(); // LambdaQueryWrapper<Vccinfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Vccinfo::getVId, "ibatis"); // queryWrapper.eq(Vccinfo::getVId, "ibatis");
Vccinfo vccinfo = new Vccinfo(); // Vccinfo vccinfo = new Vccinfo();
vccinfo.setVName("mybatis-update"); // vccinfo.setVName("mybatis-update");
baseMapper.update(vccinfo, queryWrapper); // baseMapper.update(vccinfo, queryWrapper);
} // }
//
private void queryMethod() { // private void queryMethod() {
List<Vccinfo> vccinfoList = vccinfoMapper.queryList(1); // List<Vccinfo> vccinfoList = vccinfoMapper.queryList(1);
log.info("queryAll:{}", JSONUtil.toJsonStr(vccinfoList)); // log.info("queryAll:{}", JSONUtil.toJsonStr(vccinfoList));
} // }
private void delete() { // private void delete() {
LambdaQueryWrapper<Vccinfo> queryWrapper = new LambdaQueryWrapper<>(); // LambdaQueryWrapper<Vccinfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Vccinfo::getVId, "ibatis"); // queryWrapper.eq(Vccinfo::getVId, "ibatis");
baseMapper.delete(queryWrapper); // 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: 500
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
...@@ -13,16 +13,16 @@ import javax.annotation.Resource; ...@@ -13,16 +13,16 @@ import javax.annotation.Resource;
@SpringBootTest(classes = BaseApplication.class) @SpringBootTest(classes = BaseApplication.class)
class InformixServiceTest { class InformixServiceTest {
// @Resource(name = "informixJdbcService") @Resource(name = "informixJdbcService")
// private InformixService informixJdbcService; private InformixService informixJdbcService;
@Resource(name = "informixJdbcProxyService") @Resource(name = "informixJdbcProxyService")
private InformixService informixJdbcProxyService; private InformixService informixJdbcProxyService;
@Resource(name = "informixHibernateService") // @Resource(name = "informixHibernateService")
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() {
...@@ -57,4 +57,14 @@ class InformixServiceTest { ...@@ -57,4 +57,14 @@ class InformixServiceTest {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Test
void testJdbcInfo() {
try {
informixJdbcService.doConnectJob();
} catch (Exception e) {
e.printStackTrace();
}
}
} }
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