Skip to content

Commit b64e9b9

Browse files
authored
Java Code Snippets (#16)
* Interim commit * Updated .gitignore * Updated .gitignore * Updated .gitignore * Interim commit * Interim commit * Interim commit * Added stewardship snippets * Added README.md files in multiple directories. Added configuration/InitDefaultConfig.java Updated usage message for SnippetRunner.java
1 parent 276afb1 commit b64e9b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+6254
-0
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@
2323
"/home/ant/Work/Senzing/git/sz-sdk-python/src/senzing"
2424
],
2525
"pylint.importStrategy": "useBundled",
26+
"java.configuration.updateBuildConfiguration": "automatic",
27+
"java.project.sourcePaths": [
28+
"."
29+
],
30+
"java.project.referencedLibraries": [],
31+
"java.format.settings.url": ".vscode/java-formatter.xml",
2632
}

java/README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Java Snippets
2+
3+
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.
4+
5+
There are several ways to run the code snippets.
6+
7+
## Run Directly
8+
9+
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.
10+
11+
1. Run a snippet that takes no command-line arguments.
12+
```
13+
java -cp target/sz-sdk-snippets.jar loading.LoadRecords
14+
```
15+
16+
2. Run a snippet and override the input file using command-line arguments
17+
```
18+
java -cp target/sz-sdk-snippets.jar loading.LoadRecordsViaLoop ../../resources/data/load-500-with-errors.jsonl
19+
```
20+
21+
# Run Individually via Runner
22+
23+
The `com.senzing.runner.SnippetRunner` class will run one or more snippets for you and create a temporary Senzing repository to run
24+
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`.
25+
26+
**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).
27+
28+
1. Execute all code snippets:
29+
```
30+
java -jar target/sz-sdk-snippets.jar all
31+
```
32+
33+
2. Execute all code snippets in a Java package:
34+
```
35+
java -jar target/sz-sdk-snippets.jar loading
36+
```
37+
38+
3. Execute all code snippets from multiple packages:
39+
```
40+
java -jar target/sz-sdk-snippets.jar loading redo
41+
```
42+
4. Execute specific code snippets:
43+
```
44+
java -jar target/sz-sdk-snippets.jar loading.LoadViaLoop loading.LoadViaQueue
45+
```
46+
5. Mix and match packages with individual snippets:
47+
```
48+
java -jar target/sz-sdk-snippets.jar redo loading.LoadViaLoop
49+
```
50+
6. Generate a help message by specifying no arguments:
51+
```
52+
java -jar target/sz-sdk-snippets.jar
53+
54+
java -jar sz-sdk-snippets.jar [ all | <group> | <snippet> ]*
55+
56+
- Specifying no arguments will print this message
57+
- Specifying "all" will run all snippets
58+
- Specifying one or more groups will run all snippets in those groups
59+
- Specifying one or more snippets will run those snippet
60+
61+
Examples:
62+
63+
java -jar sz-sdk-snippets.jar all
64+
65+
java -jar sz-sdk-snippets.jar loading.LoadRecords loading.LoadViaFutures
66+
67+
java -jar sz-sdk-snippets.jar initialization deleting loading.LoadRecords
68+
69+
Snippet Group Names:
70+
- configuration
71+
- deleting
72+
- information
73+
- initialization
74+
- loading
75+
- redo
76+
- searching
77+
- stewardship
78+
79+
Snippet Names:
80+
- configuration.AddDataSources
81+
- configuration.InitDefaultConfig
82+
- deleting.DeleteViaFutures
83+
- deleting.DeleteViaLoop
84+
- deleting.DeleteWithInfoViaFutures
85+
- information.CheckDatastorePerformance
86+
- information.GetDatastoreInfo
87+
- information.GetLicense
88+
- information.GetVersion
89+
- initialization.EnginePriming
90+
- initialization.EnvironmentAndHubs
91+
- initialization.PurgeRepository
92+
- loading.LoadRecords
93+
- loading.LoadTruthSetWithInfoViaLoop
94+
- loading.LoadViaFutures
95+
- loading.LoadViaLoop
96+
- loading.LoadViaQueue
97+
- loading.LoadWithInfoViaFutures
98+
- loading.LoadWithStatsViaLoop
99+
- redo.LoadWithRedoViaLoop
100+
- redo.RedoContinuous
101+
- redo.RedoContinuousViaFutures
102+
- redo.RedoWithInfoContinuous
103+
- searching.SearchRecords
104+
- searching.SearchViaFutures
105+
- stewardship.ForceResolve
106+
- stewardship.ForceUnresolve
107+
```

java/pom.xml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.senzing</groupId>
5+
<artifactId>sz-sdk-snippets</artifactId>
6+
<packaging>jar</packaging>
7+
<version>4.0.0</version>
8+
<name>Senzing Java SDK</name>
9+
<description>The Code Snippet Examples for Senzing V4 Java SDK.</description>
10+
<url>http://github.com/Senzing/code-snippets-v4</url>
11+
<licenses>
12+
<license>
13+
<name>The Apache License, Version 2.0</name>
14+
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
15+
</license>
16+
</licenses>
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.senzing</groupId>
20+
<artifactId>sz-sdk</artifactId>
21+
<version>4.0.0</version>
22+
<scope>system</scope>
23+
<systemPath>${SENZING_DIR}/lib/sz-sdk.jar</systemPath>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.glassfish</groupId>
27+
<artifactId>javax.json</artifactId>
28+
<version>1.1.4</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.xerial</groupId>
32+
<artifactId>sqlite-jdbc</artifactId>
33+
<version>3.47.2.0</version>
34+
</dependency>
35+
</dependencies>
36+
<properties>
37+
<maven.compiler.include>17</maven.compiler.include>
38+
<maven.compiler.source>17</maven.compiler.source>
39+
<maven.compiler.target>17</maven.compiler.target>
40+
<project.build.includeEncoding>UTF-8</project.build.includeEncoding>
41+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
42+
</properties>
43+
<build>
44+
<sourceDirectory>snippets</sourceDirectory>
45+
<resources>
46+
<resource>
47+
<directory>${project.basedir}/runner/resources</directory>
48+
</resource>
49+
<resource>
50+
<directory>${project.basedir}/../resources</directory>
51+
</resource>
52+
</resources>
53+
<finalName>${project.artifactId}</finalName>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-compiler-plugin</artifactId>
58+
<version>3.13.0</version>
59+
<configuration>
60+
<compilerArgs>
61+
<arg>-Xlint:unchecked</arg>
62+
<arg>-Xlint:deprecation</arg>
63+
</compilerArgs>
64+
</configuration>
65+
</plugin>
66+
<plugin>
67+
<groupId>org.codehaus.mojo</groupId>
68+
<artifactId>build-helper-maven-plugin</artifactId>
69+
<version>3.2.0</version>
70+
<executions>
71+
<execution>
72+
<phase>generate-sources</phase>
73+
<goals>
74+
<goal>add-source</goal>
75+
</goals>
76+
<configuration>
77+
<sources>
78+
<source>${project.basedir}/runner/java</source>
79+
</sources>
80+
</configuration>
81+
</execution>
82+
</executions>
83+
</plugin>
84+
<plugin>
85+
<groupId>org.apache.maven.plugins</groupId>
86+
<artifactId>maven-shade-plugin</artifactId>
87+
<version>3.6.0</version>
88+
<configuration>
89+
<createDependencyReducedPom>false</createDependencyReducedPom>
90+
<extraJars>
91+
<include>${SENZING_DIR}/lib/sz-sdk.jar</include>
92+
</extraJars>
93+
<filters>
94+
<filter>
95+
<artifact>*:*</artifact>
96+
<excludes>
97+
<exclude>META-INF/MANIFEST.MF</exclude>
98+
<exclude>META-INF/*.SF</exclude>
99+
<exclude>META-INF/*.DSA</exclude>
100+
<exclude>META-INF/*.RSA</exclude>
101+
</excludes>
102+
</filter>
103+
</filters>
104+
</configuration>
105+
<executions>
106+
<execution>
107+
<phase>package</phase>
108+
<goals>
109+
<goal>shade</goal>
110+
</goals>
111+
<configuration>
112+
<transformers>
113+
<transformer
114+
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
115+
<transformer
116+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
117+
<manifestEntries>
118+
<!-- Main-Class>com.foo.Test</Main-Class -->
119+
<Main-Class>com.senzing.runner.SnippetRunner</Main-Class>
120+
<version>${project.version}</version>
121+
</manifestEntries>
122+
</transformer>
123+
</transformers>
124+
</configuration>
125+
</execution>
126+
</executions>
127+
</plugin>
128+
</plugins>
129+
</build>
130+
</project>

0 commit comments

Comments
 (0)