栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SPL-在SpringBoot中的集成(三)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SPL-在SpringBoot中的集成(三)

需要的MAVEN依赖
    
        org.springframework.boot
        spring-boot-starter-parent
        2.3.2.RELEASE
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            junit
            junit
            test
        

        
            org.springframework.boot
            spring-boot-starter-test
            
                
                    com.vaadin.external.google
                    android-json
                
            
            test
        
        
            org.projectlombok
            lombok
        
        
            mysql
            mysql-connector-java
        


        
            com.scudata.esproc
            esproc
            20220601
        
        
            org.hsqldb
            hsqldb
            2.2.8
        
        
            com.ibm.icu
            icu4j
            60.3
        

        
            org.lucee
            jdom
            1.1.3
        

        
            com.alibaba
            druid-spring-boot-starter
            1.1.10
        
        
            org.apache.poi
            poi
            5.2.2
        
        
            org.apache.xmlbeans
            xmlbeans
            5.1.0
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                2.0.6.RELEASE
            
        
    
SPL无配置文件版

这个版本不依赖raqsoftConfig.xml配置文件,数据库需要我们手动自己添加进去

application.yml

server:
  port: 9546


spring:
  datasource:
    ds1:
      driverclassName: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://192.168.118.129:3306/voidme?useCursorFetch=true&useSSL=false
      username: root
      password: root
      dbType: MYSQL
    ds2:
      driverclassName: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://192.168.118.129:3306/sso?useCursorFetch=true&useSSL=false
      username: root
      password: root
      dbType: MYSQL

JdbcConfig

@Configuration
public class JdbcConfig {
    @Bean("local_mysql_1")
    @ConfigurationProperties("spring.datasource.ds1")
    public DataSource datasourceMysql1() {
        return DruidDataSourceBuilder.create().build();
    }

    @Bean("local_mysql_2")
    @ConfigurationProperties("spring.datasource.ds2")
    public DataSource datasourceMysql2() {
        return DruidDataSourceBuilder.create().build();
    }

}

AppInitListener

@Component
public class AppInitListener extends ApplicationObjectSupport implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        Map beansOfType = getApplicationContext().getBeansOfType(DataSource.class);

        for (Map.Entry stringDataSourceEntry : beansOfType.entrySet()) {
            DruidDataSource value = (DruidDataSource)stringDataSourceEntry.getValue();
            int dbType = DBTypes.getDBType(value.getDbType());
            SpringDBSessionFactory.create(stringDataSourceEntry.getKey(), dbType);
        }
    }
}

SplAppliction

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, })
@ComponentScan({"com.scudata.*","com.splparer.*"})
public class SplAppliction {


    public static void main(String[] args) {
        SpringApplication.run(SplAppliction.class, args);
    }
}

SplTest

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SplAppliction.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class SplTest {
    @SneakyThrows
    @Test
    public void contextLoads() {
//        FileInputStream fileInputStream=new FileInputStream(new File("C:\Users\huanmin\Desktop\spl\p.spl"));
//        PgmCellSet pgmCellSet = AppUtil.readSPL(fileInputStream);  //文本文件
//        PgmCellSet pgmCellSet = AppUtil.readSPL("C:\Users\huanmin\Desktop\spl\p.spl");  //文本文件
        PgmCellSet pgmCellSet = AppUtil.readCellSet("C:\Users\huanmin\Desktop\spl\p.dfx");  //dfx, sqlx 二进制文件
        Context context = new Context(); //上下文,参数..设置
        pgmCellSet.setContext(context);
        Object execute = pgmCellSet.execute();
        System.out.println(execute);
    }

}

p.splx

结果如下:

SPL配置文件版

这个版本支持的功能比较全,直接调用SPL驱动,需要搭配raqsoftConfig.xml配置文件进行

raqsoftConfig.xml 文件可在本地windows客户端中-选项-环境里自行配置配置好后,就会将内容同步到本地安装目录下esProcconfigraqsoftConfig.xml里 更全配置信息



    
        
            
                
                
                
                
                
                
                
                
                
                
                
                
            
        
        
            UTF-8



            
                C:UsershuanminDesktopspl
            
            yyyy-MM-dd
            HH:mm:ss
            yyyy-MM-dd HH:mm:ss
            
            
            resources/temp
            65536
            
            0
            
            
            1048576
            nan,null,n/a
            
            
        
        
            
            INFO
        
    
    


        
        
        
        

        
        
            
        
    



application.yml

server:
  port: 9546


spring:
  datasource:
      driverclassName: com.esproc.jdbc.InternalDriver
      url: jdbc:esproc:local://
      username: root
      password: root
      minIdle: 5
      maxActive: 100
      initialSize: 10

JdbcConfig

@Configuration
public class JdbcConfig {

    @Bean
    @ConfigurationProperties("spring.datasource")
    public DataSource datasource() {
        return DruidDataSourceBuilder.create().build();
    }

}

SplController

@RestController
@RequestMapping("/spl")
public class SplController {

    @Autowired
    private SplServiceImpl service;
    @GetMapping("")
    public void execute() {
        service.contextLoads();
    }
}

SplService

public interface    SplService {
    public void contextLoads() ;

}

SplServiceImpl

@Component
public class SplServiceImpl implements SplService {
    @Autowired
    private DataSource dataSource;

    @SneakyThrows
    @Override
    public void contextLoads() {
        long l = System.currentTimeMillis();
        //获得数据库连接
        Connection connection = dataSource.getConnection();
        CallableStatement st = connection.prepareCall("call p()");
        //执行存储过程
        st.execute();
        //获取结果集
        ResultSet rs = st.getResultSet();
        SplUtil.show(rs);
        connection.close();
        long l1 = System.currentTimeMillis();
        System.out.println("======================:"+String.valueOf(l1-l));
    }
}

SplUtil

public class SplUtil {


    //显示表格值内容
    public static void show(  ResultSet rs) throws SQLException {
        //简单处理结果集,将结果集中的字段名与数据输出
        ResultSetMetaData rsmd = rs.getMetaData();
        int colCount = rsmd.getColumnCount();
        for ( int  c = 1; c <= colCount;c++) {
            String title = rsmd.getColumnName(c);
            if( c > 1 ) {
                System.out.print("t");
            }
            else {
                System.out.print("n");
            }
            System.out.print(title);
        }

        while (rs.next()) {
            for(int c = 1; c<= colCount; c++) {
                if ( c > 1 ) {
                    System.out.print("t");
                }
                else {
                    System.out.print("n");
                }
                Object o = rs.getObject(c);
                System.out.print(o);
            }
        }

        System.out.println();
    }
}

SplAppliction

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, })
@ComponentScan({"com.scudata.*","com.spl.*"})
public class SplAppliction {


    public static void main(String[] args) {
        SpringApplication.run(SplAppliction.class, args);
    }
}

注意
  1. java调用SPL,网格中的代码都会被执行一遍, 但是return只会获取第一个
  2. 在spl中通过connect进行使用数据库连接,使用完毕后就要关闭,否则就会一直占用连接 ,当然还可以connect@x 方式来调用
  3. java 调用SPL第一次会加载类库等, 稍微有点慢大概需要300毫秒, 之后就快了也就几毫秒

点赞 -收藏-关注-便于以后复习和收到最新内容
有其他问题在评论区讨论-或者私信我-收到会在第一时间回复
感谢,配合,希望我的努力对你有帮助^_^

免责声明:本文部分素材来源于网络,版权归原创者所有,如存在文章/图片/音视频等使用不当的情况,请随时私信联系我。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1004091.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号