Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd8da220

Browse files
committed
Add custom file mapping support
1 parentb611f2d commitd8da220

File tree

7 files changed

+352
-11
lines changed

7 files changed

+352
-11
lines changed

‎src/main/java/io/github/utplsql/api/CustomTypes.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
*/
66
publicfinalclassCustomTypes {
77

8-
// Object names must be upper case.
8+
/* Object names must be upper case. */
9+
10+
publicstaticfinalStringUT_VARCHAR2_LIST ="UT_VARCHAR2_LIST";
11+
912
publicstaticfinalStringUT_REPORTERS ="UT_REPORTERS";
1013
publicstaticfinalStringUT_DOCUMENTATION_REPORTER ="UT_DOCUMENTATION_REPORTER";
1114
publicstaticfinalStringUT_COVERAGE_HTML_REPORTER ="UT_COVERAGE_HTML_REPORTER";
@@ -14,7 +17,12 @@ public final class CustomTypes {
1417
publicstaticfinalStringUT_COVERALLS_REPORTER ="UT_COVERALLS_REPORTER";
1518
publicstaticfinalStringUT_COVERAGE_SONAR_REPORTER ="UT_COVERAGE_SONAR_REPORTER";
1619
publicstaticfinalStringUT_SONAR_TEST_REPORTER ="UT_SONAR_TEST_REPORTER";
17-
publicstaticfinalStringUT_VARCHAR2_LIST ="UT_VARCHAR2_LIST";
20+
21+
publicstaticfinalStringUT_FILE_MAPPING ="UT_FILE_MAPPING";
22+
publicstaticfinalStringUT_FILE_MAPPINGS ="UT_FILE_MAPPINGS";
23+
24+
publicstaticfinalStringUT_KEY_VALUE_PAIR ="UT_KEY_VALUE_PAIR";
25+
publicstaticfinalStringUT_KEY_VALUE_PAIRS ="UT_KEY_VALUE_PAIRS";
1826

1927
privateCustomTypes() {}
2028

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
packageio.github.utplsql.api;
2+
3+
4+
importoracle.jdbc.OracleConnection;
5+
importoracle.jdbc.OracleTypes;
6+
7+
importjava.sql.Array;
8+
importjava.sql.CallableStatement;
9+
importjava.sql.Connection;
10+
importjava.sql.SQLException;
11+
importjava.util.ArrayList;
12+
importjava.util.List;
13+
importjava.util.Map;
14+
15+
publicfinalclassFileMapper {
16+
17+
privateFileMapper() {}
18+
19+
/**
20+
* Call the database api to build the custom file mappings.
21+
*/
22+
publicstaticArraybuildFileMappingArray(Connectionconn,FileMapperOptionsmapperOptions)throwsSQLException {
23+
OracleConnectionoraConn =conn.unwrap(OracleConnection.class);
24+
25+
MaptypeMap =conn.getTypeMap();
26+
typeMap.put(CustomTypes.UT_FILE_MAPPING,FileMapping.class);
27+
typeMap.put(CustomTypes.UT_KEY_VALUE_PAIR,KeyValuePair.class);
28+
conn.setTypeMap(typeMap);
29+
30+
CallableStatementcallableStatement =conn.prepareCall(
31+
"BEGIN " +
32+
"? := ut_file_mapper.build_file_mappings(" +
33+
"a_object_owner => ?, " +
34+
"a_file_paths => ?, " +
35+
"a_file_to_object_type_mapping => ?, " +
36+
"a_regex_pattern => ?, " +
37+
"a_object_owner_subexpression => ?, " +
38+
"a_object_name_subexpression => ?, " +
39+
"a_object_type_subexpression => ?); " +
40+
"END;");
41+
42+
intparamIdx =0;
43+
callableStatement.registerOutParameter(++paramIdx,OracleTypes.ARRAY,CustomTypes.UT_FILE_MAPPINGS);
44+
45+
callableStatement.setString(++paramIdx,mapperOptions.getOwner());
46+
callableStatement.setArray(
47+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST,mapperOptions.getFilePaths().toArray()));
48+
callableStatement.setArray(
49+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_KEY_VALUE_PAIRS,mapperOptions.getTypeMappings().toArray()));
50+
callableStatement.setString(++paramIdx,mapperOptions.getRegexPattern());
51+
callableStatement.setInt(++paramIdx,mapperOptions.getOwnerSubExpression());
52+
callableStatement.setInt(++paramIdx,mapperOptions.getNameSubExpression());
53+
callableStatement.setInt(++paramIdx,mapperOptions.getTypeSubExpression());
54+
55+
callableStatement.execute();
56+
returncallableStatement.getArray(1);
57+
}
58+
59+
publicstaticList<FileMapping>buildFileMappingList(Connectionconn,FileMapperOptionsmapperOptions)throwsSQLException {
60+
java.sql.ArrayfileMappings =buildFileMappingArray(conn,mapperOptions);
61+
62+
List<FileMapping>mappingList =newArrayList<>();
63+
for (Objectobj : (Object[])fileMappings.getArray()) {
64+
mappingList.add((FileMapping)obj);
65+
}
66+
67+
returnmappingList;
68+
}
69+
70+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
packageio.github.utplsql.api;
2+
3+
importjava.util.ArrayList;
4+
importjava.util.List;
5+
6+
publicclassFileMapperOptions {
7+
8+
privateStringowner;
9+
privateList<String>filePaths;
10+
privateList<KeyValuePair>typeMappings;
11+
privateStringregexPattern;
12+
privateintownerSubExpression;
13+
privateinttypeSubExpression;
14+
privateintnameSubExpression;
15+
16+
publicFileMapperOptions() {
17+
this.filePaths =newArrayList<>();
18+
this.typeMappings =newArrayList<>();
19+
}
20+
21+
publicStringgetOwner() {
22+
returnowner;
23+
}
24+
25+
publicvoidsetOwner(Stringowner) {
26+
this.owner =owner;
27+
}
28+
29+
publicList<String>getFilePaths() {
30+
returnfilePaths;
31+
}
32+
33+
publicvoidsetFilePaths(List<String>filePaths) {
34+
this.filePaths =filePaths;
35+
}
36+
37+
publicList<KeyValuePair>getTypeMappings() {
38+
returntypeMappings;
39+
}
40+
41+
publicvoidsetTypeMappings(List<KeyValuePair>typeMappings) {
42+
this.typeMappings =typeMappings;
43+
}
44+
45+
publicStringgetRegexPattern() {
46+
returnregexPattern;
47+
}
48+
49+
publicvoidsetRegexPattern(StringregexPattern) {
50+
this.regexPattern =regexPattern;
51+
}
52+
53+
publicintgetOwnerSubExpression() {
54+
returnownerSubExpression;
55+
}
56+
57+
publicvoidsetOwnerSubExpression(intownerSubExpression) {
58+
this.ownerSubExpression =ownerSubExpression;
59+
}
60+
61+
publicintgetTypeSubExpression() {
62+
returntypeSubExpression;
63+
}
64+
65+
publicvoidsetTypeSubExpression(inttypeSubExpression) {
66+
this.typeSubExpression =typeSubExpression;
67+
}
68+
69+
publicintgetNameSubExpression() {
70+
returnnameSubExpression;
71+
}
72+
73+
publicvoidsetNameSubExpression(intnameSubExpression) {
74+
this.nameSubExpression =nameSubExpression;
75+
}
76+
77+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
packageio.github.utplsql.api;
2+
3+
importjava.sql.SQLData;
4+
importjava.sql.SQLException;
5+
importjava.sql.SQLInput;
6+
importjava.sql.SQLOutput;
7+
8+
/**
9+
* Created by Vinicius on 17/07/2017.
10+
*/
11+
publicclassFileMappingimplementsSQLData {
12+
13+
privateStringfileName;
14+
privateStringobjectOwner;
15+
privateStringobjectName;
16+
privateStringobjectType;
17+
18+
publicFileMapping() {}
19+
20+
publicStringgetFileName() {
21+
returnfileName;
22+
}
23+
24+
publicvoidsetFileName(StringfileName) {
25+
this.fileName =fileName;
26+
}
27+
28+
publicStringgetObjectOwner() {
29+
returnobjectOwner;
30+
}
31+
32+
publicvoidsetObjectOwner(StringobjectOwner) {
33+
this.objectOwner =objectOwner;
34+
}
35+
36+
publicStringgetObjectName() {
37+
returnobjectName;
38+
}
39+
40+
publicvoidsetObjectName(StringobjectName) {
41+
this.objectName =objectName;
42+
}
43+
44+
publicStringgetObjectType() {
45+
returnobjectType;
46+
}
47+
48+
publicvoidsetObjectType(StringobjectType) {
49+
this.objectType =objectType;
50+
}
51+
52+
@Override
53+
publicStringgetSQLTypeName()throwsSQLException {
54+
returnCustomTypes.UT_FILE_MAPPING;
55+
}
56+
57+
@Override
58+
publicvoidreadSQL(SQLInputstream,StringtypeName)throwsSQLException {
59+
setFileName(stream.readString());
60+
setObjectOwner(stream.readString());
61+
setObjectName(stream.readString());
62+
setObjectType(stream.readString());
63+
}
64+
65+
@Override
66+
publicvoidwriteSQL(SQLOutputstream)throwsSQLException {
67+
stream.writeString(getFileName());
68+
stream.writeString(getObjectOwner());
69+
stream.writeString(getObjectName());
70+
stream.writeString(getObjectType());
71+
}
72+
73+
@Override
74+
publicStringtoString() {
75+
returnString.format("%s/%s.%s",getObjectType(),getObjectOwner(),getObjectName());
76+
}
77+
78+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
packageio.github.utplsql.api;
2+
3+
importjava.sql.SQLData;
4+
importjava.sql.SQLException;
5+
importjava.sql.SQLInput;
6+
importjava.sql.SQLOutput;
7+
8+
/**
9+
* Created by Vinicius on 22/07/2017.
10+
*/
11+
publicclassKeyValuePairimplementsSQLData {
12+
13+
privateStringkey;
14+
privateStringvalue;
15+
16+
publicKeyValuePair(Stringkey,Stringvalue) {
17+
this.key =key;
18+
this.value =value;
19+
}
20+
21+
publicStringgetKey() {
22+
returnkey;
23+
}
24+
25+
publicvoidsetKey(Stringkey) {
26+
this.key =key;
27+
}
28+
29+
publicStringgetValue() {
30+
returnvalue;
31+
}
32+
33+
publicvoidsetValue(Stringvalue) {
34+
this.value =value;
35+
}
36+
37+
@Override
38+
publicStringgetSQLTypeName()throwsSQLException {
39+
returnCustomTypes.UT_KEY_VALUE_PAIR;
40+
}
41+
42+
@Override
43+
publicvoidreadSQL(SQLInputstream,StringtypeName)throwsSQLException {
44+
setKey(stream.readString());
45+
setValue(stream.readString());
46+
}
47+
48+
@Override
49+
publicvoidwriteSQL(SQLOutputstream)throwsSQLException {
50+
stream.writeString(getKey());
51+
stream.writeString(getValue());
52+
}
53+
54+
@Override
55+
publicStringtoString() {
56+
returnString.format("%s => %s",getKey(),getValue());
57+
}
58+
59+
}

‎src/main/java/io/github/utplsql/api/TestRunner.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
100100
try {
101101
callableStatement =conn.prepareCall(
102102
"BEGIN " +
103-
"ut_runner.run(" +
103+
"ut_runner.run(" +
104104
"a_paths => ?, " +
105105
"a_reporters => ?, " +
106106
"a_color_console => " +colorConsoleStr +", " +
@@ -110,49 +110,49 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
110110
"a_include_objects => ?, " +
111111
"a_exclude_objects => ?, " +
112112
"a_fail_on_errors => " +failOnErrors +"); " +
113-
"END;");
113+
"END;");
114114

115115
intparamIdx =0;
116116

117117
callableStatement.setArray(
118-
++paramIdx,oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.pathList.toArray()));
118+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST,this.pathList.toArray()));
119119

120120
callableStatement.setArray(
121-
++paramIdx,oraConn.createARRAY(CustomTypes.UT_REPORTERS,this.reporterList.toArray()));
121+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_REPORTERS,this.reporterList.toArray()));
122122

123123
if (this.coverageSchemes.isEmpty()) {
124124
callableStatement.setNull(++paramIdx,Types.ARRAY,CustomTypes.UT_VARCHAR2_LIST);
125125
}else {
126126
callableStatement.setArray(
127-
++paramIdx,oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.coverageSchemes.toArray()));
127+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST,this.coverageSchemes.toArray()));
128128
}
129129

130130
if (this.sourceFiles.isEmpty()) {
131131
callableStatement.setNull(++paramIdx,Types.ARRAY,CustomTypes.UT_VARCHAR2_LIST);
132132
}else {
133133
callableStatement.setArray(
134-
++paramIdx,oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.sourceFiles.toArray()));
134+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST,this.sourceFiles.toArray()));
135135
}
136136

137137
if (this.testFiles.isEmpty()) {
138138
callableStatement.setNull(++paramIdx,Types.ARRAY,CustomTypes.UT_VARCHAR2_LIST);
139139
}else {
140140
callableStatement.setArray(
141-
++paramIdx,oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.testFiles.toArray()));
141+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST,this.testFiles.toArray()));
142142
}
143143

144144
if (this.includeObjects.isEmpty()) {
145145
callableStatement.setNull(++paramIdx,Types.ARRAY,CustomTypes.UT_VARCHAR2_LIST);
146146
}else {
147147
callableStatement.setArray(
148-
++paramIdx,oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.includeObjects.toArray()));
148+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST,this.includeObjects.toArray()));
149149
}
150150

151151
if (this.excludeObjects.isEmpty()) {
152152
callableStatement.setNull(++paramIdx,Types.ARRAY,CustomTypes.UT_VARCHAR2_LIST);
153153
}else {
154154
callableStatement.setArray(
155-
++paramIdx,oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.excludeObjects.toArray()));
155+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST,this.excludeObjects.toArray()));
156156
}
157157

158158
callableStatement.execute();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp