Skip to content
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
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@
"/home/ant/Work/Senzing/git/sz-sdk-python/src/senzing"
],
"pylint.importStrategy": "useBundled",
"java.configuration.updateBuildConfiguration": "automatic",
"java.project.sourcePaths": [
"."
],
"java.project.referencedLibraries": [],
"java.format.settings.url": ".vscode/java-formatter.xml",
}
107 changes: 107 additions & 0 deletions java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Java Snippets

The Java snippets are contained in the `snippets` directory under various Java package directories. They can built using the `pom.xml` in this directory using `mvn package`. The result will be the `sz-sdk-snippets.jar` file ni the `target` directory.

There are several ways to run the code snippets.

## Run Directly

You may run any individual Snippet class directly providing you have a Senzing repository to run it with and the `SENZING_ENGINE_CONFIGURATION_JSON` environment variable set for connecting to that repository. Many of the snippets will find a default data file to run with if run from this directory, but also allow the caller to use a different data file if given by the first command-line arguemnt.

1. Run a snippet that takes no command-line arguments.
```
java -cp target/sz-sdk-snippets.jar loading.LoadRecords
```

2. Run a snippet and override the input file using command-line arguments
```
java -cp target/sz-sdk-snippets.jar loading.LoadRecordsViaLoop ../../resources/data/load-500-with-errors.jsonl
```

# Run Individually via Runner

The `com.senzing.runner.SnippetRunner` class will run one or more snippets for you and create a temporary Senzing repository to run
then against. This is the `Main-Class` of the `sz-sdk-snippets.jar` file so it can be executed using `java -jar target/sz-sdk-snippets.jar`.

**NOTE:** When code snippets are run this way you cannot specify command-line arguments for individual snippets, nor can you respond to command-line input requests (they will be automatically be responded by the runner -- including forced termination of a snippet that is intended to run indefinitely).

1. Execute all code snippets:
```
java -jar target/sz-sdk-snippets.jar all
```

2. Execute all code snippets in a Java package:
```
java -jar target/sz-sdk-snippets.jar loading
```

3. Execute all code snippets from multiple packages:
```
java -jar target/sz-sdk-snippets.jar loading redo
```
4. Execute specific code snippets:
```
java -jar target/sz-sdk-snippets.jar loading.LoadViaLoop loading.LoadViaQueue
```
5. Mix and match packages with individual snippets:
```
java -jar target/sz-sdk-snippets.jar redo loading.LoadViaLoop
```
6. Generate a help message by specifying no arguments:
```
java -jar target/sz-sdk-snippets.jar

java -jar sz-sdk-snippets.jar [ all | <group> | <snippet> ]*

- Specifying no arguments will print this message
- Specifying "all" will run all snippets
- Specifying one or more groups will run all snippets in those groups
- Specifying one or more snippets will run those snippet

Examples:

java -jar sz-sdk-snippets.jar all

java -jar sz-sdk-snippets.jar loading.LoadRecords loading.LoadViaFutures

java -jar sz-sdk-snippets.jar initialization deleting loading.LoadRecords

Snippet Group Names:
- configuration
- deleting
- information
- initialization
- loading
- redo
- searching
- stewardship

Snippet Names:
- configuration.AddDataSources
- configuration.InitDefaultConfig
- deleting.DeleteViaFutures
- deleting.DeleteViaLoop
- deleting.DeleteWithInfoViaFutures
- information.CheckDatastorePerformance
- information.GetDatastoreInfo
- information.GetLicense
- information.GetVersion
- initialization.EnginePriming
- initialization.EnvironmentAndHubs
- initialization.PurgeRepository
- loading.LoadRecords
- loading.LoadTruthSetWithInfoViaLoop
- loading.LoadViaFutures
- loading.LoadViaLoop
- loading.LoadViaQueue
- loading.LoadWithInfoViaFutures
- loading.LoadWithStatsViaLoop
- redo.LoadWithRedoViaLoop
- redo.RedoContinuous
- redo.RedoContinuousViaFutures
- redo.RedoWithInfoContinuous
- searching.SearchRecords
- searching.SearchViaFutures
- stewardship.ForceResolve
- stewardship.ForceUnresolve
```
130 changes: 130 additions & 0 deletions java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.senzing</groupId>
<artifactId>sz-sdk-snippets</artifactId>
<packaging>jar</packaging>
<version>4.0.0</version>
<name>Senzing Java SDK</name>
<description>The Code Snippet Examples for Senzing V4 Java SDK.</description>
<url>http://github.com/Senzing/code-snippets-v4</url>
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>com.senzing</groupId>
<artifactId>sz-sdk</artifactId>
<version>4.0.0</version>
<scope>system</scope>
<systemPath>${SENZING_DIR}/lib/sz-sdk.jar</systemPath>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.47.2.0</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.include>17</maven.compiler.include>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.includeEncoding>UTF-8</project.build.includeEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<sourceDirectory>snippets</sourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/runner/resources</directory>
</resource>
<resource>
<directory>${project.basedir}/../resources</directory>
</resource>
</resources>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<compilerArgs>
<arg>-Xlint:unchecked</arg>
<arg>-Xlint:deprecation</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/runner/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<extraJars>
<include>${SENZING_DIR}/lib/sz-sdk.jar</include>
</extraJars>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<!-- Main-Class>com.foo.Test</Main-Class -->
<Main-Class>com.senzing.runner.SnippetRunner</Main-Class>
<version>${project.version}</version>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading
Loading