From fe7d9fcc42d56a6ee01622e9c475ca5ad4d782c0 Mon Sep 17 00:00:00 2001 From: lizhenzhen Date: Thu, 14 Sep 2023 16:43:22 +0800 Subject: [PATCH] =?UTF-8?q?polardbx=E7=9A=84curd=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 65 ++++-- .../com/beagle/informix/BaseApplication.java | 4 +- .../beagle/informix/entity/jpa/Vccinfo.java | 86 ++++---- .../informix/entity/mybatis/Vccinfo.java | 82 +++---- .../beagle/informix/mapper/VccinfoMapper.java | 44 ++-- .../informix/repository/VccinfoDao.java | 40 ++-- .../repository/impl/VccinfoDaoImpl.java | 184 ++++++++-------- .../impl/InformixHibernateServiceImpl.java | 160 +++++++------- .../impl/InformixIbatisServiceImpl.java | 38 ++-- .../impl/InformixJdbcProxyServiceImpl.java | 84 ++++---- .../service/impl/InformixJdbcServiceImpl.java | 70 +++--- .../impl/InformixMybatisServiceImpl.java | 202 +++++++++--------- src/main/resources/application.yaml | 64 +++--- .../service/impl/InformixServiceTest.java | 18 +- 14 files changed, 590 insertions(+), 551 deletions(-) diff --git a/pom.xml b/pom.xml index fc5e471..910724b 100644 --- a/pom.xml +++ b/pom.xml @@ -17,39 +17,40 @@ 11 - - - com.ibm.informix - jdbc - 4.50.7.1 - + mysql mysql-connector-java 8.0.28 + + + org.postgresql + postgresql + 42.6.0 + cn.hutool hutool-all 5.8.15 - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-jdbc - - - - - com.alibaba - druid-spring-boot-starter - 1.2.15 - + + + + + + + + + + + + + + + org.projectlombok lombok @@ -97,6 +98,19 @@ mybatis-plus-core 3.5.3.1 + + + com.dameng + DmJdbcDriver18 + 8.1.2.192 + + + + + + + + com.baomidou mybatis-plus-boot-starter @@ -116,7 +130,6 @@ org.springframework.boot spring-boot-maven-plugin - org.projectlombok @@ -157,6 +170,14 @@ + + + src/main/java + + + src/main/resources + + diff --git a/src/main/java/com/beagle/informix/BaseApplication.java b/src/main/java/com/beagle/informix/BaseApplication.java index e1fc9fc..27b1a5c 100644 --- a/src/main/java/com/beagle/informix/BaseApplication.java +++ b/src/main/java/com/beagle/informix/BaseApplication.java @@ -2,10 +2,10 @@ package com.beagle.informix; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.transaction.annotation.EnableTransactionManagement; +//import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication -@EnableTransactionManagement(order = 2) +//@EnableTransactionManagement(order = 2) public class BaseApplication { public static void main(String[] args) { diff --git a/src/main/java/com/beagle/informix/entity/jpa/Vccinfo.java b/src/main/java/com/beagle/informix/entity/jpa/Vccinfo.java index 5467448..3a006ca 100644 --- a/src/main/java/com/beagle/informix/entity/jpa/Vccinfo.java +++ b/src/main/java/com/beagle/informix/entity/jpa/Vccinfo.java @@ -1,43 +1,43 @@ -package com.beagle.informix.entity.jpa; - -import lombok.Data; - -import javax.persistence.*; -import java.io.Serializable; -import java.sql.Blob; - -/** - * @author lzz - * date 2023/5/30 - * @version 1.0 - * description: - */ -@Data -@Table(name = "cti_vccinfo_new") -@Entity -public class Vccinfo implements Serializable { - private static final long serialVersionUID = 1L; - @Id - // todo 这个id自动生成方式还需测试 - @Column(name = "vccid") - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer vId; - @Column(name = "vccname") - private String vName; - @Column(name = "effective") - private Integer effective; - @Column(name = "agentmax") - private Integer agentMax; - @Column(name = "ivrmax") - private Integer ivrMax; - @Column(name = "updatekey") - private String updateKey; - @Column(name = "tclob") - @Basic(fetch = FetchType.LAZY) - private String tClob; - - @Lob - @Basic(fetch = FetchType.LAZY) - @Column(name = "tblob", columnDefinition = "longblob", nullable = true) - private byte[] tBlob; -} +//package com.beagle.informix.entity.jpa; +// +//import lombok.Data; +// +//import javax.persistence.*; +//import java.io.Serializable; +//import java.sql.Blob; +// +///** +// * @author lzz +// * date 2023/5/30 +// * @version 1.0 +// * description: +// */ +//@Data +////@、Table(name = "cti_vccinfo_new") +////@Entity +//public class Vccinfo implements Serializable { +// private static final long serialVersionUID = 1L; +// @Id +// // todo 这个id自动生成方式还需测试 +// @Column(name = "vccid") +// @GeneratedValue(strategy = GenerationType.IDENTITY) +// private Integer vId; +// @Column(name = "vccname") +// private String vName; +// @Column(name = "effective") +// private Integer effective; +// @Column(name = "agentmax") +// private Integer agentMax; +// @Column(name = "ivrmax") +// private Integer ivrMax; +// @Column(name = "updatekey") +// private String updateKey; +// @Column(name = "tclob") +// @Basic(fetch = FetchType.LAZY) +// private String tClob; +// +// @Lob +// @Basic(fetch = FetchType.LAZY) +// @Column(name = "tblob", columnDefinition = "longblob", nullable = true) +// private byte[] tBlob; +//} 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 645a4eb..2e61498 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 2d560dd..26f5439 100644 --- a/src/main/java/com/beagle/informix/mapper/VccinfoMapper.java +++ b/src/main/java/com/beagle/informix/mapper/VccinfoMapper.java @@ -1,22 +1,22 @@ -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 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); +//} diff --git a/src/main/java/com/beagle/informix/repository/VccinfoDao.java b/src/main/java/com/beagle/informix/repository/VccinfoDao.java index bfa588f..61953ec 100644 --- a/src/main/java/com/beagle/informix/repository/VccinfoDao.java +++ b/src/main/java/com/beagle/informix/repository/VccinfoDao.java @@ -1,20 +1,20 @@ -package com.beagle.informix.repository; - -import com.beagle.informix.entity.jpa.Vccinfo; -import org.springframework.data.repository.CrudRepository; - -import java.util.List; - -/** - * @author lzz - * date 2023/5/30 - * @version 1.0 - * description: - */ -public interface VccinfoDao { - Vccinfo getVccInfoById(Integer vId); - List getAllVccInfo(); - void addVccinfo(Vccinfo vccinfo); - void updateVccinfo(Vccinfo vccinfo); - void deleteVccinfo(Integer vId); -} +//package com.beagle.informix.repository; +// +////import com.beagle.informix.entity.jpa.Vccinfo; +////import org.springframework.data.repository.CrudRepository; +// +//import java.util.List; +// +///** +// * @author lzz +// * date 2023/5/30 +// * @version 1.0 +// * description: +// */ +//public interface VccinfoDao { +// Vccinfo getVccInfoById(Integer vId); +// List getAllVccInfo(); +// void addVccinfo(Vccinfo vccinfo); +// void updateVccinfo(Vccinfo vccinfo); +// void deleteVccinfo(Integer vId); +//} diff --git a/src/main/java/com/beagle/informix/repository/impl/VccinfoDaoImpl.java b/src/main/java/com/beagle/informix/repository/impl/VccinfoDaoImpl.java index 4234317..23fc872 100644 --- a/src/main/java/com/beagle/informix/repository/impl/VccinfoDaoImpl.java +++ b/src/main/java/com/beagle/informix/repository/impl/VccinfoDaoImpl.java @@ -1,92 +1,92 @@ -package com.beagle.informix.repository.impl; - -import com.beagle.informix.entity.jpa.Vccinfo; -import com.beagle.informix.repository.VccinfoDao; - -import org.springframework.stereotype.Repository; - -import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import javax.transaction.Transactional; -import java.util.List; - -/** - * @author lzz - * date 2023/5/30 - * @version 1.0 - * description: - */ -@Repository -public class VccinfoDaoImpl implements VccinfoDao { - @PersistenceContext - private EntityManager entityManager; - - @Override - public Vccinfo getVccInfoById(Integer vId) { - return entityManager.find(Vccinfo.class, vId); - } - - @Override - public List getAllVccInfo() { - String sql = "FROM Vccinfo as vInfo ORDER BY vInfo.effective"; - return (List) entityManager.createQuery(sql).getResultList(); - } - - @Override - public void addVccinfo(Vccinfo vccinfo) { - entityManager.persist(vccinfo); -// entityManager.createNativeQuery("insert into cti_vccinfo_new (vccid ,vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob)\n" + -// " VALUES(?,?,?,?,?,?,?,?") -// .setParameter(1, vccinfo.getVId()) -// .setParameter(2, vccinfo.getVName()) -// .setParameter(3, vccinfo.getEffective()) -// .setParameter(4, vccinfo.getAgentMax()) -// .setParameter(5, vccinfo.getIvrMax()) -// .setParameter(6, vccinfo.getUpdateKey()) -// .setParameter(7, vccinfo.getTClob()) -// .setParameter(8, vccinfo.getTBlob()).executeUpdate(); - - } - - @Override - @Transactional - public void updateVccinfo(Vccinfo vccinfo) { - // 提示异常 Caused by: java.sql.SQLException: Code-set conversion function failed due to illegal sequence or invalid value. - /*Vccinfo old = entityManager.find(Vccinfo.class, "jpa"); - old.setVName("informix—name"); - entityManager.merge(old);*/ - - // 第一步:准备好jpql -// ?1表示第一个参数,?2表示第二个参数 - String jpql = "update Vccinfo s set s.vName = ?1 where s.vId = ?2"; - EntityTransaction transaction = null; - - try { -// transaction = entityManager.getTransaction(); -// transaction.begin(); - - // 第二步:设置jpql的参数 - Query query = entityManager.createQuery(jpql); - query.setParameter(1, "赵六666999"); - query.setParameter(2, "%jpa%"); - - // 第三步:执行jpql - int rows = query.executeUpdate(); - System.out.println("影响的行数:" + rows); - - transaction.commit(); - } catch (Exception e) { - e.printStackTrace(); -// transaction.rollback(); - } finally { - entityManager.close(); - } - } - - @Override - public void deleteVccinfo(Integer vId) { - entityManager.remove(getVccInfoById(vId)); - } -} +//package com.beagle.informix.repository.impl; +// +//import com.beagle.informix.entity.jpa.Vccinfo; +//import com.beagle.informix.repository.VccinfoDao; +// +//import org.springframework.stereotype.Repository; +// +////import javax.persistence.EntityManager; +////import javax.persistence.EntityTransaction; +////import javax.persistence.PersistenceContext; +////import javax.persistence.Query; +////import javax.transaction.Transactional; +//import java.util.List; +// +///** +// * @author lzz +// * date 2023/5/30 +// * @version 1.0 +// * description: +// */ +//@Repository +//public class VccinfoDaoImpl implements VccinfoDao { +//// @PersistenceContext +//// private EntityManager entityManager; +// +// @Override +// public Vccinfo getVccInfoById(Integer vId) { +// return entityManager.find(Vccinfo.class, vId); +// } +// +// @Override +// public List getAllVccInfo() { +// String sql = "FROM Vccinfo as vInfo ORDER BY vInfo.effective"; +// return (List) entityManager.createQuery(sql).getResultList(); +// } +// +// @Override +// public void addVccinfo(Vccinfo vccinfo) { +// entityManager.persist(vccinfo); +//// entityManager.createNativeQuery("insert into cti_vccinfo_new (vccid ,vccname, effective, agentmax,ivrmax,updatekey,tclob,tblob)\n" + +//// " VALUES(?,?,?,?,?,?,?,?") +//// .setParameter(1, vccinfo.getVId()) +//// .setParameter(2, vccinfo.getVName()) +//// .setParameter(3, vccinfo.getEffective()) +//// .setParameter(4, vccinfo.getAgentMax()) +//// .setParameter(5, vccinfo.getIvrMax()) +//// .setParameter(6, vccinfo.getUpdateKey()) +//// .setParameter(7, vccinfo.getTClob()) +//// .setParameter(8, vccinfo.getTBlob()).executeUpdate(); +// +// } +// +// @Override +// @Transactional +// public void updateVccinfo(Vccinfo vccinfo) { +// // 提示异常 Caused by: java.sql.SQLException: Code-set conversion function failed due to illegal sequence or invalid value. +// /*Vccinfo old = entityManager.find(Vccinfo.class, "jpa"); +// old.setVName("informix—name"); +// entityManager.merge(old);*/ +// +// // 第一步:准备好jpql +//// ?1表示第一个参数,?2表示第二个参数 +// String jpql = "update Vccinfo s set s.vName = ?1 where s.vId = ?2"; +// EntityTransaction transaction = null; +// +// try { +//// transaction = entityManager.getTransaction(); +//// transaction.begin(); +// +// // 第二步:设置jpql的参数 +// Query query = entityManager.createQuery(jpql); +// query.setParameter(1, "赵六666999"); +// query.setParameter(2, "%jpa%"); +// +// // 第三步:执行jpql +// int rows = query.executeUpdate(); +// System.out.println("影响的行数:" + rows); +// +// transaction.commit(); +// } catch (Exception e) { +// e.printStackTrace(); +//// transaction.rollback(); +// } finally { +// entityManager.close(); +// } +// } +// +// @Override +// public void deleteVccinfo(Integer vId) { +// entityManager.remove(getVccInfoById(vId)); +// } +//} diff --git a/src/main/java/com/beagle/informix/service/impl/InformixHibernateServiceImpl.java b/src/main/java/com/beagle/informix/service/impl/InformixHibernateServiceImpl.java index 95c9ea6..c5fe8b5 100644 --- a/src/main/java/com/beagle/informix/service/impl/InformixHibernateServiceImpl.java +++ b/src/main/java/com/beagle/informix/service/impl/InformixHibernateServiceImpl.java @@ -1,80 +1,80 @@ -package com.beagle.informix.service.impl; - -import cn.hutool.json.JSONUtil; -import com.beagle.informix.entity.jpa.Vccinfo; -import com.beagle.informix.repository.VccinfoDao; -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 javax.transaction.Transactional; -import java.io.File; -import java.io.FileInputStream; -import java.util.List; - -/** - * Caused by: java.sql.SQLException: Transactions not supported - * ifx事务默认不开启,需要使用命令 通过ontape -s -B dbname来设置,注意不是服务名,而是数据库名 - * - * Code-set conversion function failed due to illegal sequence or invalid value. - * 启动失败字符集错误,暂时还未找到解决办法 - * @author lzz - * date 2023/5/29 - * @version 1.0 - * description: - */ -@Slf4j -@Service("informixHibernateService") -public class InformixHibernateServiceImpl implements InformixService { - @Resource - private VccinfoDao vccinfoDao; - @Resource - private ResourceLoader resourceLoader; - @Override - @Transactional - public void doConnectJob() throws Exception{ - insert(); -// update(); -// query(); -// delete(); - } - private void insert() throws Exception{ - Vccinfo vccinfo = new Vccinfo(); -// vccinfo.setVId(23); - vccinfo.setEffective(1); - vccinfo.setVName("hibernate"); - vccinfo.setIvrMax(1); - vccinfo.setAgentMax(1); - vccinfo.setUpdateKey("jpa key"); - // 组装clob - vccinfo.setTClob("@Ddsfsdferewr"); - // 组装blob数据 - // 处理blob字段 - // proxy 处理blob字段时,存放二进制文件(exe),打开异常,存放文本时正常 - org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:test1.doc"); - File inputStream = resource.getFile(); - try (FileInputStream fis = new FileInputStream(inputStream)){ - vccinfo.setTBlob(fis.readAllBytes()); - } - // insert - vccinfoDao.addVccinfo(vccinfo); - } - - private void update(int id) { - Vccinfo vccinfo = new Vccinfo(); - vccinfo.setVId(id); - vccinfoDao.updateVccinfo(vccinfo); - } - private void query(int id) { - - - List vccinfoList = vccinfoDao.getAllVccInfo(); - log.info("queryAll:{}",JSONUtil.toJsonStr(vccinfoDao.getAllVccInfo())); - log.info("queryById:{}",JSONUtil.toJsonStr(vccinfoDao.getVccInfoById(id))); - } - private void delete(int id) { - vccinfoDao.deleteVccinfo(id); - } -} +//package com.beagle.informix.service.impl; +// +//import cn.hutool.json.JSONUtil; +////import com.beagle.informix.entity.jpa.Vccinfo; +//import com.beagle.informix.repository.VccinfoDao; +//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 javax.transaction.Transactional; +//import java.io.File; +//import java.io.FileInputStream; +//import java.util.List; +// +///** +// * Caused by: java.sql.SQLException: Transactions not supported +// * ifx事务默认不开启,需要使用命令 通过ontape -s -B dbname来设置,注意不是服务名,而是数据库名 +// * +// * Code-set conversion function failed due to illegal sequence or invalid value. +// * 启动失败字符集错误,暂时还未找到解决办法 +// * @author lzz +// * date 2023/5/29 +// * @version 1.0 +// * description: +// */ +//@Slf4j +//@Service("informixHibernateService") +//public class InformixHibernateServiceImpl implements InformixService { +// @Resource +// private VccinfoDao vccinfoDao; +// @Resource +// private ResourceLoader resourceLoader; +// @Override +//// @Transactional +// public void doConnectJob() throws Exception{ +// insert(); +//// update(); +//// query(); +//// delete(); +// } +// private void insert() throws Exception{ +// Vccinfo vccinfo = new Vccinfo(); +//// vccinfo.setVId(23); +// vccinfo.setEffective(1); +// vccinfo.setVName("hibernate"); +// vccinfo.setIvrMax(1); +// vccinfo.setAgentMax(1); +// vccinfo.setUpdateKey("jpa key"); +// // 组装clob +// vccinfo.setTClob("@Ddsfsdferewr"); +// // 组装blob数据 +// // 处理blob字段 +// // proxy 处理blob字段时,存放二进制文件(exe),打开异常,存放文本时正常 +// org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:test1.doc"); +// File inputStream = resource.getFile(); +// try (FileInputStream fis = new FileInputStream(inputStream)){ +// vccinfo.setTBlob(fis.readAllBytes()); +// } +// // insert +// vccinfoDao.addVccinfo(vccinfo); +// } +// +// private void update(int id) { +// Vccinfo vccinfo = new Vccinfo(); +// vccinfo.setVId(id); +// vccinfoDao.updateVccinfo(vccinfo); +// } +// private void query(int id) { +// +// +// List vccinfoList = vccinfoDao.getAllVccInfo(); +// log.info("queryAll:{}",JSONUtil.toJsonStr(vccinfoDao.getAllVccInfo())); +// log.info("queryById:{}",JSONUtil.toJsonStr(vccinfoDao.getVccInfoById(id))); +// } +// private void delete(int id) { +// vccinfoDao.deleteVccinfo(id); +// } +//} diff --git a/src/main/java/com/beagle/informix/service/impl/InformixIbatisServiceImpl.java b/src/main/java/com/beagle/informix/service/impl/InformixIbatisServiceImpl.java index 2676f4c..a39d0d8 100644 --- a/src/main/java/com/beagle/informix/service/impl/InformixIbatisServiceImpl.java +++ b/src/main/java/com/beagle/informix/service/impl/InformixIbatisServiceImpl.java @@ -1,19 +1,19 @@ -package com.beagle.informix.service.impl; - -import com.beagle.informix.service.InformixService; -import org.springframework.stereotype.Service; - -/** - * @author lzz - * date 2023/5/29 - * @version 1.0 - * description: - */ -@Service("informixIbatisService") -public class InformixIbatisServiceImpl implements InformixService { - @Override - public void doConnectJob() { - // 手写连接jdbc驱动 - } - -} +//package com.beagle.informix.service.impl; +// +//import com.beagle.informix.service.InformixService; +//import org.springframework.stereotype.Service; +// +///** +// * @author lzz +// * date 2023/5/29 +// * @version 1.0 +// * description: +// */ +//@Service("informixIbatisService") +//public class InformixIbatisServiceImpl implements InformixService { +// @Override +// public void doConnectJob() { +// // 手写连接jdbc驱动 +// } +// +//} 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 eca321c..3d3053a 100644 --- a/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java +++ b/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java @@ -44,44 +44,44 @@ 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 -// Driver driver = getDriver(); -// Connection conn = getConnection(driver); -// insert(conn); -//// update(conn); -//// query(conn); -//// delete(conn); -// closeConnection(conn); -// deregisterDriver(driver); + // 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 CompletableFuture completableFuture = new CompletableFuture<>(); ExecutorService executorService = Executors.newFixedThreadPool(500); - for (int i = 0; i < 500; 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); - } - } +// 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 Driver getDriver() throws Exception{ // 定义informix的驱动信息 @@ -98,7 +98,7 @@ public class InformixJdbcProxyServiceImpl implements InformixService { // 创建testdb数据库、my_test_create_table表 // 现在模拟插入、更新、删除、查询等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); stat.setObject(1, "123456"); stat.setObject(2, "vname"); @@ -126,9 +126,9 @@ public class InformixJdbcProxyServiceImpl implements InformixService { stat.executeUpdate(); } private void query(Connection conn) throws Exception { - String querySQL = "SELECT id FROM sc_test "; - PreparedStatement stat = conn.prepareStatement(querySQL); - ResultSet resultSet = stat.executeQuery(); + String querySQL = "SELECT id FROM sc_test"; + Statement stat = conn.createStatement(); + ResultSet resultSet = stat.executeQuery(querySQL); } @@ -142,10 +142,10 @@ public class InformixJdbcProxyServiceImpl implements InformixService { Properties properties = new Properties(); // 组装连接数据库信息 // jdbc:informix-sqli://:/:informixserver= - StringBuilder jdbcBuilder = new StringBuilder("jdbc:mysql://localhost:3307"); + StringBuilder jdbcBuilder = new StringBuilder("jdbc:mysql://localhost:3307") // .append("/") -// .append("SYSDBA") -// .append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true"); +// .append("SYSDBA"); + .append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true"); DriverManager.setLoginTimeout(10); properties.put("user", "root"); properties.put("password", "Apurelove9014"); diff --git a/src/main/java/com/beagle/informix/service/impl/InformixJdbcServiceImpl.java b/src/main/java/com/beagle/informix/service/impl/InformixJdbcServiceImpl.java index bc12ca4..c26e799 100644 --- a/src/main/java/com/beagle/informix/service/impl/InformixJdbcServiceImpl.java +++ b/src/main/java/com/beagle/informix/service/impl/InformixJdbcServiceImpl.java @@ -46,13 +46,40 @@ public class InformixJdbcServiceImpl implements InformixService { public void doConnectJob() throws Exception{ Driver driver = getDriver(); Connection conn = getConnection(driver); - insert(conn); - update(conn); - query(conn); - delete(conn); +// updateTable(conn); + createTable(conn); +// insert(conn); +// update(conn); +// query(conn); +// delete(conn); +// createTable2(conn); deregisterDriver(driver); 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{ // 创建testdb数据库、my_test_create_table表 // 现在模拟插入、更新、删除、查询等sql @@ -85,27 +112,11 @@ public class InformixJdbcServiceImpl implements InformixService { stat.executeUpdate(); } 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); 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{ String deleteSql = "delete from cti_vccinfo_new where vccid = '123456' "; @@ -116,19 +127,16 @@ public class InformixJdbcServiceImpl implements InformixService { Properties properties = new Properties(); // 组装连接数据库信息 // jdbc:informix-sqli://:/:informixserver= - StringBuilder jdbcBuilder = new StringBuilder("jdbc:informix-sqli://") - .append("localhost:9088") - .append("/") - .append("testdb") - .append(":INFORMIXSERVER=informix"); + StringBuilder jdbcBuilder = new StringBuilder("jdbc:dm://") + .append("localhost:5236"); DriverManager.setLoginTimeout(10); - properties.put("user", "informix"); - properties.put("password", "in4mix"); + properties.put("user", "SYSDBA"); + properties.put("password", "SYSDBA"); return DriverManager.getConnection(jdbcBuilder.toString(), properties); } private Driver getDriver() throws Exception{ // 定义informix的驱动信息 - String driverUrl = "com.informix.jdbc.IfxDriver"; + String driverUrl = "dm.jdbc.driver.DmDriver"; // 还需要加入informix的jdbc驱动jar包 Class driverClass = Class.forName(driverUrl); return (Driver) driverClass.getConstructor().newInstance(); 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 8288c27..ca81208 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,101 @@ -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); - } - } - } - 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); - } - -} +//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); +// } +// } +// } +// 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); +// } +// +//} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 9dfc044..8ae24e8 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: 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 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 856ffcf..da64c82 100644 --- a/src/test/java/com/beagle/informix/service/impl/InformixServiceTest.java +++ b/src/test/java/com/beagle/informix/service/impl/InformixServiceTest.java @@ -13,16 +13,16 @@ import javax.annotation.Resource; @SpringBootTest(classes = BaseApplication.class) class InformixServiceTest { -// @Resource(name = "informixJdbcService") -// private InformixService informixJdbcService; + @Resource(name = "informixJdbcService") + private InformixService informixJdbcService; @Resource(name = "informixJdbcProxyService") private InformixService informixJdbcProxyService; - @Resource(name = "informixHibernateService") +// @Resource(name = "informixHibernateService") private InformixService informixHibernateService; // @Resource(name = "informixIbatisService") // private InformixService informixIbatisService; - @Resource(name = "informixMybatisService") +// @Resource(name = "informixMybatisService") private InformixService informixMybatisService; // @Test // void testJdbcInfo() { @@ -57,4 +57,14 @@ class InformixServiceTest { e.printStackTrace(); } } + + @Test + void testJdbcInfo() { + try { + informixJdbcService.doConnectJob(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } -- 2.26.0