|
1 | | -/** |
| 1 | +/* |
2 | 2 | * Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com> |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
15 | 15 | */ |
16 | 16 | package org.utplsql.sqldev.test; |
17 | 17 |
|
18 | | -import com.google.common.base.Objects; |
| 18 | +import java.io.IOException; |
19 | 19 | import java.io.StringReader; |
20 | 20 | import java.util.ArrayList; |
| 21 | +import java.util.List; |
21 | 22 | import java.util.Properties; |
| 23 | + |
| 24 | +import org.springframework.jdbc.core.JdbcTemplate; |
| 25 | +import org.springframework.jdbc.datasource.SingleConnectionDataSource; |
| 26 | +import org.utplsql.sqldev.exception.GenericRuntimeException; |
| 27 | + |
22 | 28 | import oracle.dbtools.raptor.newscriptrunner.ISQLCommand; |
23 | 29 | import oracle.dbtools.raptor.newscriptrunner.SQLCommand; |
24 | 30 | import oracle.dbtools.worksheet.scriptparser.sqlplus.SQLPlusScriptParser; |
25 | | -import org.eclipse.xtend2.lib.StringConcatenation; |
26 | | -import org.eclipse.xtext.xbase.lib.Exceptions; |
27 | | -import org.eclipse.xtext.xbase.lib.Functions.Function0; |
28 | | -import org.springframework.jdbc.core.JdbcTemplate; |
29 | | -import org.springframework.jdbc.datasource.SingleConnectionDataSource; |
30 | 31 |
|
31 | | -@SuppressWarnings("all") |
32 | 32 | public abstract class AbstractJdbcTest { |
33 | | - protected static SingleConnectionDataSource dataSource; |
34 | | - |
35 | | - protected static JdbcTemplate jdbcTemplate; |
36 | | - |
37 | | - protected static SingleConnectionDataSource sysDataSource; |
38 | | - |
39 | | - protected static JdbcTemplate sysJdbcTemplate; |
40 | | - |
41 | | - protected static final JdbcTemplate _staticInitializerForDataSourceAndJdbcTemplate = new Function0<JdbcTemplate>() { |
42 | | - public JdbcTemplate apply() { |
43 | | - try { |
44 | | - JdbcTemplate _xblockexpression = null; |
45 | | - { |
46 | | - final Properties p = new Properties(); |
47 | | - p.load(AbstractJdbcTest.class.getClass().getResourceAsStream("/test.properties")); |
48 | | - SingleConnectionDataSource _singleConnectionDataSource = new SingleConnectionDataSource(); |
49 | | - AbstractJdbcTest.dataSource = _singleConnectionDataSource; |
50 | | - AbstractJdbcTest.dataSource.setDriverClassName("oracle.jdbc.OracleDriver"); |
51 | | - StringConcatenation _builder = new StringConcatenation(); |
52 | | - _builder.append("jdbc:oracle:thin:@"); |
53 | | - String _property = p.getProperty("host"); |
54 | | - _builder.append(_property); |
55 | | - _builder.append(":"); |
56 | | - String _property_1 = p.getProperty("port"); |
57 | | - _builder.append(_property_1); |
58 | | - _builder.append("/"); |
59 | | - String _property_2 = p.getProperty("service"); |
60 | | - _builder.append(_property_2); |
61 | | - AbstractJdbcTest.dataSource.setUrl(_builder.toString()); |
62 | | - AbstractJdbcTest.dataSource.setUsername(p.getProperty("scott_username")); |
63 | | - AbstractJdbcTest.dataSource.setPassword(p.getProperty("scott_password")); |
64 | | - JdbcTemplate _jdbcTemplate = new JdbcTemplate(AbstractJdbcTest.dataSource); |
65 | | - AbstractJdbcTest.jdbcTemplate = _jdbcTemplate; |
66 | | - SingleConnectionDataSource _singleConnectionDataSource_1 = new SingleConnectionDataSource(); |
67 | | - AbstractJdbcTest.sysDataSource = _singleConnectionDataSource_1; |
68 | | - AbstractJdbcTest.sysDataSource.setDriverClassName("oracle.jdbc.OracleDriver"); |
69 | | - StringConcatenation _builder_1 = new StringConcatenation(); |
70 | | - _builder_1.append("jdbc:oracle:thin:@"); |
71 | | - String _property_3 = p.getProperty("host"); |
72 | | - _builder_1.append(_property_3); |
73 | | - _builder_1.append(":"); |
74 | | - String _property_4 = p.getProperty("port"); |
75 | | - _builder_1.append(_property_4); |
76 | | - _builder_1.append("/"); |
77 | | - String _property_5 = p.getProperty("service"); |
78 | | - _builder_1.append(_property_5); |
79 | | - AbstractJdbcTest.sysDataSource.setUrl(_builder_1.toString()); |
80 | | - AbstractJdbcTest.sysDataSource.setUsername(p.getProperty("sys_username")); |
81 | | - AbstractJdbcTest.sysDataSource.setPassword(p.getProperty("sys_password")); |
82 | | - JdbcTemplate _jdbcTemplate_1 = new JdbcTemplate(AbstractJdbcTest.sysDataSource); |
83 | | - _xblockexpression = AbstractJdbcTest.sysJdbcTemplate = _jdbcTemplate_1; |
| 33 | + protected static SingleConnectionDataSource dataSource; |
| 34 | + protected static JdbcTemplate jdbcTemplate; |
| 35 | + protected static SingleConnectionDataSource sysDataSource; |
| 36 | + protected static JdbcTemplate sysJdbcTemplate; |
| 37 | + |
| 38 | + static { |
| 39 | + final Properties p = new Properties(); |
| 40 | + try { |
| 41 | + p.load(AbstractJdbcTest.class.getClass().getResourceAsStream("/test.properties")); |
| 42 | + } catch (IOException e) { |
| 43 | + throw new GenericRuntimeException("Cannot read test.properties", e); |
84 | 44 | } |
85 | | - return _xblockexpression; |
86 | | - } catch (Throwable _e) { |
87 | | - throw Exceptions.sneakyThrow(_e); |
88 | | - } |
| 45 | + // create dataSource and jdbcTemplate |
| 46 | + dataSource = new SingleConnectionDataSource(); |
| 47 | + dataSource.setDriverClassName("oracle.jdbc.OracleDriver"); |
| 48 | + dataSource.setUrl("jdbc:oracle:thin:@" + p.getProperty("host") + ":" + p.getProperty("port") + "/" |
| 49 | + + p.getProperty("service")); |
| 50 | + dataSource.setUsername(p.getProperty("scott_username")); |
| 51 | + dataSource.setPassword(p.getProperty("scott_password")); |
| 52 | + jdbcTemplate = new JdbcTemplate(dataSource); |
| 53 | + // create dbaDataSource and dbaJdbcTemplate |
| 54 | + sysDataSource = new SingleConnectionDataSource(); |
| 55 | + sysDataSource.setDriverClassName("oracle.jdbc.OracleDriver"); |
| 56 | + sysDataSource.setUrl("jdbc:oracle:thin:@" + p.getProperty("host") + ":" + p.getProperty("port") + "/" |
| 57 | + + p.getProperty("service")); |
| 58 | + sysDataSource.setUsername(p.getProperty("sys_username")); |
| 59 | + sysDataSource.setPassword(p.getProperty("sys_password")); |
| 60 | + sysJdbcTemplate = new JdbcTemplate(sysDataSource); |
89 | 61 | } |
90 | | - }.apply(); |
91 | | - |
92 | | - public static ArrayList<String> getStatements(final String sqlplusScript) { |
93 | | - StringReader _stringReader = new StringReader(sqlplusScript); |
94 | | - SQLPlusScriptParser p = new SQLPlusScriptParser(_stringReader); |
95 | | - final ArrayList<String> stmts = new ArrayList<String>(); |
96 | | - while (p.hasNext()) { |
97 | | - { |
98 | | - final ISQLCommand stmt = p.next(); |
99 | | - if (((((stmt.getExecutable() || stmt.getRunnable()) && (!Objects.equal(stmt.getStmtType(), SQLCommand.StmtType.G_C_COMMENT))) && |
100 | | - (!Objects.equal(stmt.getStmtType(), SQLCommand.StmtType.G_C_MULTILINECOMMENT))) && (!Objects.equal(stmt.getStmtType(), SQLCommand.StmtType.G_C_SQLPLUS)))) { |
101 | | - stmts.add(stmt.getSql()); |
| 62 | + |
| 63 | + public static List<String> getStatements(final String sqlplusScript) { |
| 64 | + SQLPlusScriptParser p = new SQLPlusScriptParser(new StringReader(sqlplusScript)); |
| 65 | + final ArrayList<String> stmts = new ArrayList<>(); |
| 66 | + while (p.hasNext()) { |
| 67 | + final ISQLCommand stmt = p.next(); |
| 68 | + if ((stmt.getExecutable() || stmt.getRunnable()) && stmt.getStmtType() != SQLCommand.StmtType.G_C_COMMENT |
| 69 | + && stmt.getStmtType() != SQLCommand.StmtType.G_C_MULTILINECOMMENT |
| 70 | + && stmt.getStmtType() != SQLCommand.StmtType.G_C_SQLPLUS) { |
| 71 | + stmts.add(stmt.getSql()); |
| 72 | + } |
102 | 73 | } |
103 | | - } |
| 74 | + return stmts; |
104 | 75 | } |
105 | | - return stmts; |
106 | | - } |
107 | 76 | } |
0 commit comments