Skip to content

Commit 4c44e4c

Browse files
add AbstractJdbcTest.java generated by Xtend 2.20.0
1 parent c5af17e commit 4c44e4c

File tree

1 file changed

+90
-46
lines changed

1 file changed

+90
-46
lines changed
Lines changed: 90 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/**
22
* Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,51 +13,95 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.utplsql.sqldev.test
16+
package org.utplsql.sqldev.test;
1717

18-
import java.io.StringReader
19-
import java.util.ArrayList
20-
import java.util.Properties
21-
import oracle.dbtools.raptor.newscriptrunner.SQLCommand.StmtType
22-
import oracle.dbtools.worksheet.scriptparser.sqlplus.SQLPlusScriptParser
23-
import org.springframework.jdbc.core.JdbcTemplate
24-
import org.springframework.jdbc.datasource.SingleConnectionDataSource
18+
import com.google.common.base.Objects;
19+
import java.io.StringReader;
20+
import java.util.ArrayList;
21+
import java.util.Properties;
22+
import oracle.dbtools.raptor.newscriptrunner.ISQLCommand;
23+
import oracle.dbtools.raptor.newscriptrunner.SQLCommand;
24+
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;
2530

26-
abstract class AbstractJdbcTest {
27-
protected static var SingleConnectionDataSource dataSource
28-
protected static var JdbcTemplate jdbcTemplate
29-
protected static var SingleConnectionDataSource sysDataSource
30-
protected static var JdbcTemplate sysJdbcTemplate
31-
// static initializer not supported in Xtend, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=429141
32-
protected static val _staticInitializerForDataSourceAndJdbcTemplate = {
33-
val p = new Properties()
34-
p.load(AbstractJdbcTest.getClass().getResourceAsStream("/test.properties"))
35-
// create dataSource and jdbcTemplate
36-
dataSource = new SingleConnectionDataSource()
37-
dataSource.driverClassName = "oracle.jdbc.OracleDriver"
38-
dataSource.url = '''jdbc:oracle:thin:@«p.getProperty("host")»:«p.getProperty("port")»/«p.getProperty("service")»'''
39-
dataSource.username = p.getProperty("scott_username")
40-
dataSource.password = p.getProperty("scott_password")
41-
jdbcTemplate = new JdbcTemplate(dataSource)
42-
// create dbaDataSource and dbaJdbcTemplate
43-
sysDataSource = new SingleConnectionDataSource()
44-
sysDataSource.driverClassName = "oracle.jdbc.OracleDriver"
45-
sysDataSource.url = '''jdbc:oracle:thin:@«p.getProperty("host")»:«p.getProperty("port")»/«p.getProperty("service")»'''
46-
sysDataSource.username = p.getProperty("sys_username")
47-
sysDataSource.password = p.getProperty("sys_password")
48-
sysJdbcTemplate = new JdbcTemplate(AbstractJdbcTest.sysDataSource)
49-
}
50-
51-
def static getStatements(String sqlplusScript) {
52-
var SQLPlusScriptParser p = new SQLPlusScriptParser(new StringReader(sqlplusScript))
53-
val stmts = new ArrayList<String>
54-
while (p.hasNext) {
55-
val stmt = p.next
56-
if ((stmt.executable || stmt.runnable) && stmt.stmtType != StmtType.G_C_COMMENT &&
57-
stmt.stmtType != StmtType.G_C_MULTILINECOMMENT && stmt.stmtType != StmtType.G_C_SQLPLUS) {
58-
stmts.add(stmt.sql)
59-
}
60-
}
61-
return stmts;
62-
}
31+
@SuppressWarnings("all")
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;
84+
}
85+
return _xblockexpression;
86+
} catch (Throwable _e) {
87+
throw Exceptions.sneakyThrow(_e);
88+
}
89+
}
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());
102+
}
103+
}
104+
}
105+
return stmts;
106+
}
63107
}

0 commit comments

Comments
 (0)