SPL-在SpringBoot中的集成(三)

需要的MAVEN依赖

<parent><groupId>org.springframework.bootgroupId><artifactId>spring-boot-starter-parentartifactId><version>2.3.2.RELEASEversion>parent><dependencies><dependency><groupId>org.springframework.bootgroupId><artifactId>spring-boot-starter-webartifactId>dependency><dependency><groupId>junitgroupId><artifactId>junitartifactId><scope>testscope>dependency><dependency><groupId>org.springframework.bootgroupId><artifactId>spring-boot-starter-testartifactId><exclusions><exclusion><groupId>com.vaadin.external.googlegroupId><artifactId>android-jsonartifactId>exclusion>exclusions><scope>testscope>dependency><dependency><groupId>org.projectlombokgroupId><artifactId>lombokartifactId>dependency><dependency><groupId>mysqlgroupId><artifactId>mysql-connector-javaartifactId>dependency><dependency><groupId>com.scudata.esprocgroupId><artifactId>esprocartifactId><version>20220601version>dependency><dependency><groupId>org.hsqldbgroupId><artifactId>hsqldbartifactId><version>2.2.8version>dependency><dependency><groupId>com.ibm.icugroupId><artifactId>icu4jartifactId><version>60.3version>dependency><dependency><groupId>org.luceegroupId><artifactId>jdomartifactId><version>1.1.3version>dependency><dependency><groupId>com.alibabagroupId><artifactId>druid-spring-boot-starterartifactId><version>1.1.10version>dependency><dependency><groupId>org.apache.poigroupId><artifactId>poiartifactId><version>5.2.2version>dependency><dependency><groupId>org.apache.xmlbeansgroupId><artifactId>xmlbeansartifactId><version>5.1.0version>dependency>dependencies><build><plugins><plugin><groupId>org.springframework.bootgroupId><artifactId>spring-boot-maven-pluginartifactId><version>2.0.6.RELEASEversion>plugin>plugins>build>

SPL无配置文件版

这个版本不依赖raqsoftConfig.xml配置文件,数据库需要我们手动自己添加进去
在这里插入图片描述

application.yml

server:port: 9546spring:datasource:ds1:driverclassName: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://192.168.118.129:3306/voidme?useCursorFetch=true&useSSL=falseusername: rootpassword: rootdbType: MYSQLds2:driverclassName: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://192.168.118.129:3306/sso?useCursorFetch=true&useSSL=falseusername: rootpassword: rootdbType: 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 {@Overridepublic void run(ApplicationArguments args) throws Exception {Map<String, DataSource> beansOfType = getApplicationContext().getBeansOfType(DataSource.class);for (Map.Entry<String, DataSource> 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@Testpublic 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客户端中-选项-环境里自行配置配置好后,就会将内容同步到本地安装目录下esProc\config\raqsoftConfig.xml里 更全配置信息


<Config Version="3"><Runtime><DBList><DB name="local_mysql_1"><property name="url"value="jdbc:mysql://192.168.118.129:3306/voidme?useCursorFetch=true&useSSL=false"/><property name="driver" value="com.mysql.cj.jdbc.Driver"/><property name="type" value="10"/><property name="user" value="root"/><property name="password" value="root"/><property name="batchSize" value="0"/><property name="autoConnect" value="true"/><property name="useSchema" value="false"/><property name="addTilde" value="false"/><property name="needTransContent" value="false"/><property name="needTransSentence" value="false"/><property name="caseSentence" value="false"/>DB>DBList><Esproc><charSet>UTF-8charSet><splPathList><splPath>C:\Users\huanmin\Desktop\splsplPath>splPathList><dateFormat>yyyy-MM-dddateFormat><timeFormat>HH:mm:sstimeFormat><dateTimeFormat>yyyy-MM-dd HH:mm:ssdateTimeFormat><mainPath/><tempPath>resources/temptempPath><bufSize>65536bufSize><localHost/><localPort>0localPort><parallelNum/><cursorParallelNum/><simpleTableBlockSize>1048576simpleTableBlockSize><nullStrings>nan,null,n/anullStrings><fetchCount/><extLibsPath/>Esproc><Logger><Level>INFOLevel>Logger>Runtime><JDBC><Init>Init>JDBC>
Config>

application.yml

server:port: 9546spring:datasource:driverclassName: com.esproc.jdbc.InternalDriverurl: jdbc:esproc:local://username: rootpassword: rootminIdle: 5maxActive: 100initialSize: 10

JdbcConfig

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

SplController

@RestController
@RequestMapping("/spl")
public class SplController {@Autowiredprivate SplServiceImpl service;@GetMapping("")public void execute() {service.contextLoads();}
}

SplService

public interface    SplService {public void contextLoads() ;}

SplServiceImpl

@Component
public class SplServiceImpl implements SplService {@Autowiredprivate DataSource dataSource;@SneakyThrows@Overridepublic 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毫秒, 之后就快了也就几毫秒

在这里插入图片描述

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

免责声明:本文部分素材来源于网络,版权归原创者所有,如存在文章/图片/音视频等使用不当的情况,请随时私信联系我。


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部