Skip to content

Commit

Permalink
#22 downgrade to java 11 and fixes dependencies, upgrades documentati…
Browse files Browse the repository at this point in the history
…on for simpler installation for pl/java
  • Loading branch information
tfr42 committed Apr 6, 2022
1 parent 7314793 commit e6172a6
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 80 deletions.
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Download dictionary ("Woerterbuch") data from https://www.lbeg.niedersachsen.de/

- "Schlüssellisten mit Kürzeln und zugehörigem Klartext und Typisierungen" - "Wörterbuch" - "Juli 2021"

It's a ZIP file which contains the accdb and mdb files.
It's a ZIP file which contains the `accdb` and `mdb` files.

Convert to PostgreSQL, e.g. using [mdbtools](https://github.com/mdbtools/mdbtools):

Expand All @@ -30,7 +30,7 @@ $ mdb-schema -T Woerterbuch Woerterbuch_Austausch_Internet_accdb.accdb postgres
$ mdb-export -D %F Woerterbuch_Austausch_Internet_accdb.accdb Woerterbuch > Woerterbuch.csv
```

Create the "Schluesseltypen" and "Woerterbuch" tables in your PostgreSQL database, e.g. in their own "woerterbuch" schema:
Create the _"Schluesseltypen"_ and _"Woerterbuch"_ tables in your PostgreSQL database, e.g. in their own _"woerterbuch"_ schema:

```
sep3=# create schema woerterbuch;
Expand All @@ -42,7 +42,7 @@ sep3=# set datestyle to 'SQL,MDY';
sep3=# \copy "Woerterbuch" from '/tmp/Woerterbuch.csv' CSV HEADER
```

Test your conversion by e.g. retrieving all "Woerterbuch" table entries for the "PETRO" data field:
Test your conversion by e.g. retrieving all _"Woerterbuch"_ table entries for the _"PETRO"_ data field:

```
sep3=# select "Typ", "Langtext" as "Typbezeichnung", "Kuerzel", "Klartext" from "Woerterbuch" w join "Schluesseltypen" s on w."Typ" = s."Nebentypbez" where s."Datenfeld" = 'PETRO' order by "Typ", "Kuerzel";
Expand Down Expand Up @@ -97,16 +97,21 @@ the [PL/Java](https://tada.github.io/pljava) library to execute the parser via S
Follow the [PL/Java installation guide](https://tada.github.io/pljava/install/install.html) and install a JDK 16 on the machine running the PostgreSQL database.
The installation steps for PostgreSQL 12 with OpenJDK 16 and PL/Java v1.6.4 on Ubuntu 20.04.3 LTS in a nutshell:
The installation steps for PostgreSQL 12 with OpenJDK 11 and PL/Java v1.6.4 on Ubuntu 20.04.3 LTS in a nutshell:
```shell
apt-get update && apt-get -yq install postgresql-server-dev-12 openjdk-16-jdk git gcc libssl-dev libkrb5-dev
apt-get update && apt-get -yq install postgresql-server-dev-12 openjdk-11-jdk git gcc libssl-dev libkrb5-dev
git clone https://github.com/tada/pljava.git
cd pljava
git checkout tags/V1_6_4
mvn install
sudo java -jar pljava-packaging/target/pljava-pg12.jar
```
or install the latest PL/Java version using:
```shell
apt-get update && apt-get install postgresql-12-pljava
```
### Install SEP3-Tools in PostgreSQL
Now PL/Java is installed and the SEP3-Tools library needs to be loaded into the database. Connect to the PostgreSQL database with
Expand All @@ -118,22 +123,13 @@ CREATE EXTENSION pljava;
SELECT sqlj.install_jar('file:///<PATH_TO_SEP3-TOOLS>/target/sep3-parser-0.0.1-SNAPSHOT-jar-with-dependencies.jar', 'sep3', true);
SELECT sqlj.set_classpath('public', 'sep3');
CREATE OR REPLACE FUNCTION parseS3( \
wb pg_catalog.varchar, st pg_catalog.varchar, s3code pg_catalog.varchar) \
RETURNS pg_catalog.varchar \
LANGUAGE java VOLATILE \
AS 'java.lang.String=org.sep3tools.Launch.parseS3(java.lang.String, java.lang.String, java.lang.String)';
CREATE OR REPLACE FUNCTION parseS3( \
s3code pg_catalog.varchar) \
RETURNS pg_catalog.varchar \
LANGUAGE java VOLATILE \
AS 'java.lang.String=org.sep3tools.Launch.parseS3(java.lang.String)';
```
Verify the installation by executing the function:
Verify the installation by executing the function `parseS3()`:
```postgres-sql
#using the builtin hardcoded values
SELECT parseS3('','','^u');
#using the database tables imported from the Access Database
SELECT parseS3('woerterbuch."Woerterbuch"','woerterbuch."Schluesseltypen"','^k');
SELECT parseS3('^u');
```
67 changes: 40 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>16</java.version>
<antlr.version>4.9.2</antlr.version>
<log4j2.version>2.17.1</log4j2.version>
<java.version>11</java.version>
<pljava.version>1.6.4</pljava.version>
<antlr.version>4.9.3</antlr.version>
<log4j2.version>2.17.2</log4j2.version>
</properties>

<licenses>
Expand Down Expand Up @@ -94,7 +95,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.10.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
Expand All @@ -119,7 +120,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
Expand Down Expand Up @@ -199,36 +200,48 @@
<version>${antlr.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
<groupId>org.postgresql</groupId>
<artifactId>pljava-api</artifactId>
<version>${pljava.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>pljava-api</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.3</version>
</dependency>

</dependencies>

<profiles>
<profile>
<id>logging</id>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
6 changes: 4 additions & 2 deletions src/main/java/org/sep3tools/Launch.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.postgresql.pljava.annotation.Function;
import org.sep3tools.gen.*;

public class Launch {
Expand All @@ -25,8 +26,8 @@ else if (args.length == 1) {
sep3String = args[0];
}
else {
System.out.println("Aufruf mir folgenden Parametern:\n"
+ "JDBC-URL DB-User DB-Pass Woerterbuch-Tabelle Schlüsseltypen-Tabelle SEP3-String\n\n"
System.out.println("Aufruf mit folgenden Parametern:\n"
+ "[JDBC-URL] [DB-User] [DB-Passwort] [Woerterbuch-Tabelle] [Schlüsseltypen-Tabelle] <SEP3-String>\n\n"
+ "Beispiel für Parameter:\n" + "\"jdbc:postgresql://localhost/petroparser\" " + "\"petroDB\" "
+ "\"PetroPass\" " + "\"woerterbuch.\\\"\"Woerterbuch\\\"\" "
+ "\"woerterbuch.\\\"\"Schluesseltypen\\\"\" "
Expand All @@ -37,6 +38,7 @@ else if (args.length == 1) {
System.out.println(visit);
}

@Function
public static String parseS3(String s3String) {
CharStream input = CharStreams.fromString(s3String);
PetroGrammarLexer lexer = new PetroGrammarLexer(input);
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/org/sep3tools/PLJavaConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ public static String getS3Name(String sep3Code) throws SQLException {
+ "where (s.\"Datenfeld\" = 'PETRO' OR s.\"Datenfeld\" = 'diverse') AND \"Kuerzel\"=";

PreparedStatement stmt = conn.prepareStatement(query + "'" + sep3Code + "'");
ResultSet rs = stmt.executeQuery();
boolean validRS = rs.next();
String ret = "";
if (validRS)
ret = rs.getString(2);

stmt.close();
conn.close();

return (ret);

try (ResultSet rs = stmt.executeQuery()) {
boolean validRS = rs.next();
String result = "";
if (validRS) {
result = rs.getString(2);
}
return result;
}
}

}
50 changes: 30 additions & 20 deletions src/main/java/org/sep3tools/PetroVisitor.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.sep3tools;

//import org.slf4j.Logger;

import org.sep3tools.gen.*;

import java.sql.*;

import static java.util.Objects.isNull;
import static org.slf4j.LoggerFactory.getLogger;

public class PetroVisitor extends PetroGrammarBaseVisitor<String> {

Expand Down Expand Up @@ -54,12 +51,16 @@ public String visitBestandteil(PetroGrammarParser.BestandteilContext ctx) {
}
}

return switch (boden) {
case "^u" -> "Schluffstein";
case "^ms" -> "Mittelsandstein";
case "^gs" -> "Grobsandstein";
default -> boden;
};
switch (boden) {
case "^u":
return "Schluffstein";
case "^ms":
return "Mittelsandstein";
case "^gs":
return "Grobsandstein";
default:
return boden;
}
}

@Override
Expand All @@ -78,17 +79,26 @@ public String visitAttr(PetroGrammarParser.AttrContext ctx) {
}
}
}
return switch (attr) {
case "r2" -> "kantengerundet";
case "r3" -> "mäßig gerundet";
case "tw" -> "teilweise";
case "lw" -> "lagenweise";
case "gs" -> "grobsandig";
case "t" -> "tonig";
case "nf" -> "Nachfall";
case "bei" -> "bei";
default -> attr;
};
switch (attr) {
case "r2":
return "kantengerundet";
case "r3":
return "mäßig gerundet";
case "tw":
return "teilweise";
case "lw":
return "lagenweise";
case "gs":
return "grobsandig";
case "t":
return "tonig";
case "nf":
return "Nachfall";
case "bei":
return "bei";
default:
return attr;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
SQLActions[ ] = {
"BEGIN INSTALL
CREATE SCHEMA sep3;
BEGIN PostgreSQL SET search_path TO sep3,public END postgreSQL;
BEGIN PostgreSQL
SET search_path TO sep3,public END postgreSQL;

CREATE FUNCTION sep3.java_getSystemProperty(varchar)
RETURNS varchar
Expand All @@ -12,10 +13,11 @@ SQLActions[ ] = {
RETURNS varchar
AS 'java.lang.String=org.sep3tools.Launch.parseS3(java.lang.String, java.lang.String, java.lang.String)'
LANGUAGE java;

END PostgreSQL;
END INSTALL",

"BEGIN REMOVE
"BEGIN REMOVE
BEGIN PostgreSQL
DROP SCHEMA sep3 CASCADE;
END PostgreSQL;
END REMOVE"
}

0 comments on commit e6172a6

Please sign in to comment.