Skip to content

Startup Java Project Configuration #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# IntelliJ
*.iml
.idea/

# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
sudo: required
language: java

services:
- docker

jdk:
# - oraclejdk7
- oraclejdk8

env:
global:
- DOCKER_CFG=$HOME/.docker
- DOCKER_REPO="viniciusam/oracledb"
- MAVEN_HOME=/usr/local/maven
- UTPLSQL_VERSION="v3.0.0-beta"
- UTPLSQL_FILE="utPLSQLv3.0.0.562-beta"
matrix:
- ORACLE_VERSION="11g-xe-r2" CONNECTION_STR="127.0.0.1:1521/XE" DOCKER_OPTIONS="--shm-size=1g"

cache:
directories:
- $DOCKER_CFG
- $HOME/.m2
- $MAVEN_HOME/lib/ext # Used to cache wagon-http lib.

install:
- bash .travis/maven_cfg.sh
- bash .travis/start_db.sh
- bash .travis/install_utplsql.sh

script:
- mvn test -B
24 changes: 24 additions & 0 deletions .travis/install_utplsql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -ev

# Download the specified version of utPLSQL.
curl -L -O "https://github.com/utPLSQL/utPLSQL/releases/download/$UTPLSQL_VERSION/$UTPLSQL_FILE.tar.gz"

# Create a temporary install script.
cat > install.sh.tmp <<EOF
tar -xzf $UTPLSQL_FILE.tar.gz
rm $UTPLSQL_FILE.tar.gz
cd /$UTPLSQL_FILE/source
sqlplus -S -L sys/oracle@//$CONNECTION_STR AS SYSDBA @install_headless.sql
EOF

# Copy utPLSQL files to the container and install it.
docker cp ./$UTPLSQL_FILE.tar.gz $ORACLE_VERSION:/$UTPLSQL_FILE.tar.gz
docker cp ./install.sh.tmp $ORACLE_VERSION:/install.sh

# Remove temporary files.
rm $UTPLSQL_FILE.tar.gz
rm install.sh.tmp

# Execute the utPLSQL installation inside the container.
docker exec $ORACLE_VERSION bash install.sh
28 changes: 28 additions & 0 deletions .travis/maven_cfg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -ev
cd $(dirname $(readlink -f $0))

mavenSettings=$HOME/.m2/settings.xml
mavenCached=$HOME/.m2/.cached

if [ -f $mavenCached ]; then
echo "Using cached maven user config..."
exit 0
fi

if [ "$ORACLE_OTN_USER" == "" ] || [ "$ORACLE_OTN_PASSWORD" == "" ]; then
echo "Oracle OTN username/password not specified."
exit 1
fi

# Download wagon-http recommended by Oracle.
# On maven latest version this is not needed, but travis doesn't have it.
curl -L -O "http://central.maven.org/maven2/org/apache/maven/wagon/wagon-http/2.8/wagon-http-2.8-shaded.jar"
sudo mv wagon-http-2.8-shaded.jar $MAVEN_HOME/lib/ext/

# Create the settings file with oracle server config.
cp settings.tmpl.xml $mavenSettings
sed -i -e "s|###USERNAME###|$ORACLE_OTN_USER|g" $mavenSettings
sed -i -e "s|###PASSWORD###|$ORACLE_OTN_PASSWORD|g" $mavenSettings

touch $mavenCached
51 changes: 51 additions & 0 deletions .travis/settings.tmpl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<servers>
<server>
<id>maven.oracle.com</id>
<username>###USERNAME###</username>
<password>###PASSWORD###</password>
<configuration>
<basicAuthScope>
<host>ANY</host>
<port>ANY</port>
<realm>OAM 11g</realm>
</basicAuthScope>
<httpConfiguration>
<all>
<params>
<property>
<name>http.protocol.allow-circular-redirects</name>
<value>%b,true</value>
</property>
</params>
</all>
</httpConfiguration>
</configuration>
</server>
</servers>

</settings>
51 changes: 51 additions & 0 deletions .travis/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<servers>
<server>
<id>maven.oracle.com</id>
<username>${env.ORACLE_OTN_USER}</username>
<password>${env.ORACLE_OTN_PASSWORD}</password>
<configuration>
<basicAuthScope>
<host>ANY</host>
<port>ANY</port>
<realm>OAM 11g</realm>
</basicAuthScope>
<httpConfiguration>
<all>
<params>
<property>
<name>http.protocol.allow-circular-redirects</name>
<value>%b,true</value>
</property>
</params>
</all>
</httpConfiguration>
</configuration>
</server>
</servers>

</settings>
14 changes: 14 additions & 0 deletions .travis/start_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -ev

# If docker credentials are not cached, do the login.
if [ ! -f $DOCKER_CFG/config.json ]; then
docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
else
echo "Using docker login from cache..."
fi

# Pull the specified db version from docker hub.
docker pull $DOCKER_REPO:$ORACLE_VERSION
docker run -d --name $ORACLE_VERSION $DOCKER_OPTIONS -p 1521:1521 $DOCKER_REPO:$ORACLE_VERSION
docker logs -f $ORACLE_VERSION | grep -m 1 "DATABASE IS READY TO USE!" --line-buffered
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

##### Configuring the Oracle Maven Repository #####
http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9010
https://blogs.oracle.com/dev2dev/entry/how_to_get_oracle_jdbc#pom

##### IntelliJ IDEA Maven Module #####
https://www.jetbrains.com/help/idea/2017.1/maven.html
72 changes: 72 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.github.utplsql</groupId>
<artifactId>java-api</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>utPLSQL-java-api</name>
<url>https://github.com/utPLSQL/utPLSQL-java-api</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc7</artifactId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use java7 driver or go ahead with java8?
Maybe entire project should be build on java7?
Or do we want 2 separate builds with java7 and java8?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use Java 8 because of lambda expressions and try with resources. But if we want to support both drivers, we can't use those new features anyways.

We could start with the Java 7 and add support to the newest later.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me.
Probably for Java8 we will need a separate branch/project then :(

<version>12.1.0.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<!--<build>-->
<!--<plugins>-->
<!--<plugin>-->
<!--<groupId>net.orfjackal.retrolambda</groupId>-->
<!--<artifactId>retrolambda-maven-plugin</artifactId>-->
<!--<version>2.5.1</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<goals>-->
<!--<goal>process-main</goal>-->
<!--<goal>process-test</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
<!--</plugins>-->
<!--</build>-->

<repositories>
<repository>
<id>maven.oracle.com</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://maven.oracle.com</url>
<layout>default</layout>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>maven.oracle.com</id>
<url>https://maven.oracle.com</url>
</pluginRepository>
</pluginRepositories>

</project>
80 changes: 80 additions & 0 deletions src/main/java/io/github/utplsql/OutputBuffer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.github.utplsql;

import oracle.jdbc.OracleTypes;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
* Created by Vinicius on 13/04/2017.
*/
public class OutputBuffer {

private String reporterId;

public OutputBuffer(String reporterId) {
this.reporterId = reporterId;
}

public String getReporterId() {
return reporterId;
}

public void setReporterId(String reporterId) {
this.reporterId = reporterId;
}

public List<String> getLines() throws SQLException {
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
preparedStatement = UTPLSQL.getConnection()
.prepareStatement("SELECT * FROM TABLE(ut_output_buffer.get_lines(?, 1))");

preparedStatement.setString(1, getReporterId());
resultSet = preparedStatement.executeQuery();

List<String> outputLines = new ArrayList<>();
while (resultSet.next()) {
outputLines.add(resultSet.getString(1));
}
return outputLines;
} finally {
if (resultSet != null)
resultSet.close();
if (preparedStatement != null)
preparedStatement.close();
}
}

public List<String> getAllLines() throws SQLException {
CallableStatement callableStatement = null;
ResultSet resultSet = null;
try {
callableStatement = UTPLSQL.getConnection()
.prepareCall("BEGIN ? := ut_output_buffer.get_lines_cursor(?); END;");

callableStatement.registerOutParameter(1, OracleTypes.CURSOR);
callableStatement.setString(2, getReporterId());
callableStatement.execute();

resultSet = (ResultSet) callableStatement.getObject(1);

List<String> outputLines = new ArrayList<>();
while (resultSet.next()) {
outputLines.add(resultSet.getString("text"));
}
return outputLines;
} finally {
if (resultSet != null)
resultSet.close();
if (callableStatement != null)
callableStatement.close();
}
}

}
Loading