Skip to content

Commit 1dbeb0f

Browse files
authored
Merge pull request #3 from viniciusam/java-api
Startup Java Project Configuration
2 parents 92b3189 + 9811c23 commit 1dbeb0f

18 files changed

+711
-0
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# IntelliJ
2+
*.iml
3+
.idea/
4+
5+
# Maven
6+
target/
7+
pom.xml.tag
8+
pom.xml.releaseBackup
9+
pom.xml.versionsBackup
10+
pom.xml.next
11+
release.properties
12+
dependency-reduced-pom.xml
13+
buildNumber.properties
14+
.mvn/timing.properties
15+
16+
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
17+
!/.mvn/wrapper/maven-wrapper.jar

.travis.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
sudo: required
2+
language: java
3+
4+
services:
5+
- docker
6+
7+
jdk:
8+
# - oraclejdk7
9+
- oraclejdk8
10+
11+
env:
12+
global:
13+
- DOCKER_CFG=$HOME/.docker
14+
- DOCKER_REPO="viniciusam/oracledb"
15+
- MAVEN_HOME=/usr/local/maven
16+
- UTPLSQL_VERSION="v3.0.0-beta"
17+
- UTPLSQL_FILE="utPLSQLv3.0.0.562-beta"
18+
matrix:
19+
- ORACLE_VERSION="11g-xe-r2" CONNECTION_STR="127.0.0.1:1521/XE" DOCKER_OPTIONS="--shm-size=1g"
20+
21+
cache:
22+
directories:
23+
- $DOCKER_CFG
24+
- $HOME/.m2
25+
- $MAVEN_HOME/lib/ext # Used to cache wagon-http lib.
26+
27+
install:
28+
- bash .travis/maven_cfg.sh
29+
- bash .travis/start_db.sh
30+
- bash .travis/install_utplsql.sh
31+
32+
script:
33+
- mvn test -B

.travis/install_utplsql.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
set -ev
3+
4+
# Download the specified version of utPLSQL.
5+
curl -L -O "https://github.com/utPLSQL/utPLSQL/releases/download/$UTPLSQL_VERSION/$UTPLSQL_FILE.tar.gz"
6+
7+
# Create a temporary install script.
8+
cat > install.sh.tmp <<EOF
9+
tar -xzf $UTPLSQL_FILE.tar.gz
10+
rm $UTPLSQL_FILE.tar.gz
11+
cd /$UTPLSQL_FILE/source
12+
sqlplus -S -L sys/oracle@//$CONNECTION_STR AS SYSDBA @install_headless.sql
13+
EOF
14+
15+
# Copy utPLSQL files to the container and install it.
16+
docker cp ./$UTPLSQL_FILE.tar.gz $ORACLE_VERSION:/$UTPLSQL_FILE.tar.gz
17+
docker cp ./install.sh.tmp $ORACLE_VERSION:/install.sh
18+
19+
# Remove temporary files.
20+
rm $UTPLSQL_FILE.tar.gz
21+
rm install.sh.tmp
22+
23+
# Execute the utPLSQL installation inside the container.
24+
docker exec $ORACLE_VERSION bash install.sh

.travis/maven_cfg.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
set -ev
3+
cd $(dirname $(readlink -f $0))
4+
5+
mavenSettings=$HOME/.m2/settings.xml
6+
mavenCached=$HOME/.m2/.cached
7+
8+
if [ -f $mavenCached ]; then
9+
echo "Using cached maven user config..."
10+
exit 0
11+
fi
12+
13+
if [ "$ORACLE_OTN_USER" == "" ] || [ "$ORACLE_OTN_PASSWORD" == "" ]; then
14+
echo "Oracle OTN username/password not specified."
15+
exit 1
16+
fi
17+
18+
# Download wagon-http recommended by Oracle.
19+
# On maven latest version this is not needed, but travis doesn't have it.
20+
curl -L -O "http://central.maven.org/maven2/org/apache/maven/wagon/wagon-http/2.8/wagon-http-2.8-shaded.jar"
21+
sudo mv wagon-http-2.8-shaded.jar $MAVEN_HOME/lib/ext/
22+
23+
# Create the settings file with oracle server config.
24+
cp settings.tmpl.xml $mavenSettings
25+
sed -i -e "s|###USERNAME###|$ORACLE_OTN_USER|g" $mavenSettings
26+
sed -i -e "s|###PASSWORD###|$ORACLE_OTN_PASSWORD|g" $mavenSettings
27+
28+
touch $mavenCached

.travis/settings.tmpl.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
25+
26+
<servers>
27+
<server>
28+
<id>maven.oracle.com</id>
29+
<username>###USERNAME###</username>
30+
<password>###PASSWORD###</password>
31+
<configuration>
32+
<basicAuthScope>
33+
<host>ANY</host>
34+
<port>ANY</port>
35+
<realm>OAM 11g</realm>
36+
</basicAuthScope>
37+
<httpConfiguration>
38+
<all>
39+
<params>
40+
<property>
41+
<name>http.protocol.allow-circular-redirects</name>
42+
<value>%b,true</value>
43+
</property>
44+
</params>
45+
</all>
46+
</httpConfiguration>
47+
</configuration>
48+
</server>
49+
</servers>
50+
51+
</settings>

.travis/settings.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
25+
26+
<servers>
27+
<server>
28+
<id>maven.oracle.com</id>
29+
<username>${env.ORACLE_OTN_USER}</username>
30+
<password>${env.ORACLE_OTN_PASSWORD}</password>
31+
<configuration>
32+
<basicAuthScope>
33+
<host>ANY</host>
34+
<port>ANY</port>
35+
<realm>OAM 11g</realm>
36+
</basicAuthScope>
37+
<httpConfiguration>
38+
<all>
39+
<params>
40+
<property>
41+
<name>http.protocol.allow-circular-redirects</name>
42+
<value>%b,true</value>
43+
</property>
44+
</params>
45+
</all>
46+
</httpConfiguration>
47+
</configuration>
48+
</server>
49+
</servers>
50+
51+
</settings>

.travis/start_db.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -ev
3+
4+
# If docker credentials are not cached, do the login.
5+
if [ ! -f $DOCKER_CFG/config.json ]; then
6+
docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
7+
else
8+
echo "Using docker login from cache..."
9+
fi
10+
11+
# Pull the specified db version from docker hub.
12+
docker pull $DOCKER_REPO:$ORACLE_VERSION
13+
docker run -d --name $ORACLE_VERSION $DOCKER_OPTIONS -p 1521:1521 $DOCKER_REPO:$ORACLE_VERSION
14+
docker logs -f $ORACLE_VERSION | grep -m 1 "DATABASE IS READY TO USE!" --line-buffered

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
##### Configuring the Oracle Maven Repository #####
3+
http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9010
4+
https://blogs.oracle.com/dev2dev/entry/how_to_get_oracle_jdbc#pom
5+
6+
##### IntelliJ IDEA Maven Module #####
7+
https://www.jetbrains.com/help/idea/2017.1/maven.html

pom.xml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>io.github.utplsql</groupId>
6+
<artifactId>java-api</artifactId>
7+
<version>1.0</version>
8+
<packaging>jar</packaging>
9+
10+
<name>utPLSQL-java-api</name>
11+
<url>https://github.com/utPLSQL/utPLSQL-java-api</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<maven.compiler.target>1.8</maven.compiler.target>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>com.oracle.jdbc</groupId>
22+
<artifactId>ojdbc7</artifactId>
23+
<version>12.1.0.2</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>junit</groupId>
27+
<artifactId>junit</artifactId>
28+
<version>4.12</version>
29+
<scope>test</scope>
30+
</dependency>
31+
</dependencies>
32+
33+
<!--<build>-->
34+
<!--<plugins>-->
35+
<!--<plugin>-->
36+
<!--<groupId>net.orfjackal.retrolambda</groupId>-->
37+
<!--<artifactId>retrolambda-maven-plugin</artifactId>-->
38+
<!--<version>2.5.1</version>-->
39+
<!--<executions>-->
40+
<!--<execution>-->
41+
<!--<goals>-->
42+
<!--<goal>process-main</goal>-->
43+
<!--<goal>process-test</goal>-->
44+
<!--</goals>-->
45+
<!--</execution>-->
46+
<!--</executions>-->
47+
<!--</plugin>-->
48+
<!--</plugins>-->
49+
<!--</build>-->
50+
51+
<repositories>
52+
<repository>
53+
<id>maven.oracle.com</id>
54+
<releases>
55+
<enabled>true</enabled>
56+
</releases>
57+
<snapshots>
58+
<enabled>false</enabled>
59+
</snapshots>
60+
<url>https://maven.oracle.com</url>
61+
<layout>default</layout>
62+
</repository>
63+
</repositories>
64+
65+
<pluginRepositories>
66+
<pluginRepository>
67+
<id>maven.oracle.com</id>
68+
<url>https://maven.oracle.com</url>
69+
</pluginRepository>
70+
</pluginRepositories>
71+
72+
</project>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package io.github.utplsql;
2+
3+
import oracle.jdbc.OracleTypes;
4+
5+
import java.sql.CallableStatement;
6+
import java.sql.PreparedStatement;
7+
import java.sql.ResultSet;
8+
import java.sql.SQLException;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
/**
13+
* Created by Vinicius on 13/04/2017.
14+
*/
15+
public class OutputBuffer {
16+
17+
private String reporterId;
18+
19+
public OutputBuffer(String reporterId) {
20+
this.reporterId = reporterId;
21+
}
22+
23+
public String getReporterId() {
24+
return reporterId;
25+
}
26+
27+
public void setReporterId(String reporterId) {
28+
this.reporterId = reporterId;
29+
}
30+
31+
public List<String> getLines() throws SQLException {
32+
PreparedStatement preparedStatement = null;
33+
ResultSet resultSet = null;
34+
try {
35+
preparedStatement = UTPLSQL.getConnection()
36+
.prepareStatement("SELECT * FROM TABLE(ut_output_buffer.get_lines(?, 1))");
37+
38+
preparedStatement.setString(1, getReporterId());
39+
resultSet = preparedStatement.executeQuery();
40+
41+
List<String> outputLines = new ArrayList<>();
42+
while (resultSet.next()) {
43+
outputLines.add(resultSet.getString(1));
44+
}
45+
return outputLines;
46+
} finally {
47+
if (resultSet != null)
48+
resultSet.close();
49+
if (preparedStatement != null)
50+
preparedStatement.close();
51+
}
52+
}
53+
54+
public List<String> getAllLines() throws SQLException {
55+
CallableStatement callableStatement = null;
56+
ResultSet resultSet = null;
57+
try {
58+
callableStatement = UTPLSQL.getConnection()
59+
.prepareCall("BEGIN ? := ut_output_buffer.get_lines_cursor(?); END;");
60+
61+
callableStatement.registerOutParameter(1, OracleTypes.CURSOR);
62+
callableStatement.setString(2, getReporterId());
63+
callableStatement.execute();
64+
65+
resultSet = (ResultSet) callableStatement.getObject(1);
66+
67+
List<String> outputLines = new ArrayList<>();
68+
while (resultSet.next()) {
69+
outputLines.add(resultSet.getString("text"));
70+
}
71+
return outputLines;
72+
} finally {
73+
if (resultSet != null)
74+
resultSet.close();
75+
if (callableStatement != null)
76+
callableStatement.close();
77+
}
78+
}
79+
80+
}

0 commit comments

Comments
 (0)