BAEL-1341 JDBC RowSet Interface (#3175)
* michael.good703@gmail.com michael.good703@gmail.com * michael.good703@gmail.com michael.good703@gmail.com * michael.good703@gmail.com michael.good703@gmail.com * update * michael.good703@gmail.com Had to add @SpringBootApplication(exclude = MySQLAutoconfiguration.class) * Updated for 3.3.0.Final BAEL-1238 * Update pom.xml * BAEL-1238 Added new module spring-boot-keycloak and removed Keycloak code from spring-boot module * Minor changes to pom.xml * Update CustomConverterTest.java * Update StringToEmployeeConverter.java * Update GenericBigDecimalConverter.java * Update MyFeatures.java * Update .gitignore * Formatting changes * "Resolving conflicts" * Updated spring-boot to remove keycloak * Updated to see * Update * Updated * Found remnant file and deleted it * Update pom.xml Added spring-boot-keycloak module * Added reference to parent-boot-5 I changed the parent from org.springframework.boot to parent-boot-5. * Update GenericBigDecimalConverter.java Copy current GenericBigDecimalConverter to resolve any conflicts * Update StringToEmployeeConverter.java Copy current version to resolve any conflicts * Update pom.xml * Update pom.xml * Delete remnant files * Updated pom.xml * Update pom.xml * BAEL-1341 JDBC RowSet Interface This commit includes the main package and test package to accompany the tutorial JDBC RowSet Interface. * Update pom.xml * Changed from MySQL to h2 Changed MySQL to embedded database for ease of use.
This commit is contained in:
parent
e9a56b20a4
commit
b7a86b1b56
|
@ -0,0 +1,95 @@
|
|||
<?xml version="1.0"?>
|
||||
<webRowSet xmlns="http://java.sun.com/xml/ns/jdbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/jdbc http://java.sun.com/xml/ns/jdbc/webrowset.xsd">
|
||||
<properties>
|
||||
<command>SELECT * FROM customers</command>
|
||||
<concurrency>1008</concurrency>
|
||||
<datasource><null/></datasource>
|
||||
<escape-processing>true</escape-processing>
|
||||
<fetch-direction>1000</fetch-direction>
|
||||
<fetch-size>0</fetch-size>
|
||||
<isolation-level>2</isolation-level>
|
||||
<key-columns>
|
||||
</key-columns>
|
||||
<map>
|
||||
</map>
|
||||
<max-field-size>0</max-field-size>
|
||||
<max-rows>0</max-rows>
|
||||
<query-timeout>0</query-timeout>
|
||||
<read-only>true</read-only>
|
||||
<rowset-type>ResultSet.TYPE_SCROLL_INSENSITIVE</rowset-type>
|
||||
<show-deleted>false</show-deleted>
|
||||
<table-name>customers</table-name>
|
||||
<url>jdbc:h2:mem:testdb</url>
|
||||
<sync-provider>
|
||||
<sync-provider-name>com.sun.rowset.providers.RIOptimisticProvider</sync-provider-name>
|
||||
<sync-provider-vendor>Oracle Corporation</sync-provider-vendor>
|
||||
<sync-provider-version>1.0</sync-provider-version>
|
||||
<sync-provider-grade>2</sync-provider-grade>
|
||||
<data-source-lock>1</data-source-lock>
|
||||
</sync-provider>
|
||||
</properties>
|
||||
<metadata>
|
||||
<column-count>2</column-count>
|
||||
<column-definition>
|
||||
<column-index>1</column-index>
|
||||
<auto-increment>false</auto-increment>
|
||||
<case-sensitive>true</case-sensitive>
|
||||
<currency>false</currency>
|
||||
<nullable>0</nullable>
|
||||
<signed>true</signed>
|
||||
<searchable>true</searchable>
|
||||
<column-display-size>11</column-display-size>
|
||||
<column-label>ID</column-label>
|
||||
<column-name>ID</column-name>
|
||||
<schema-name>PUBLIC</schema-name>
|
||||
<column-precision>10</column-precision>
|
||||
<column-scale>0</column-scale>
|
||||
<table-name>CUSTOMERS</table-name>
|
||||
<catalog-name>TESTDB</catalog-name>
|
||||
<column-type>4</column-type>
|
||||
<column-type-name>INTEGER</column-type-name>
|
||||
</column-definition>
|
||||
<column-definition>
|
||||
<column-index>2</column-index>
|
||||
<auto-increment>false</auto-increment>
|
||||
<case-sensitive>true</case-sensitive>
|
||||
<currency>false</currency>
|
||||
<nullable>0</nullable>
|
||||
<signed>true</signed>
|
||||
<searchable>true</searchable>
|
||||
<column-display-size>50</column-display-size>
|
||||
<column-label>NAME</column-label>
|
||||
<column-name>NAME</column-name>
|
||||
<schema-name>PUBLIC</schema-name>
|
||||
<column-precision>50</column-precision>
|
||||
<column-scale>0</column-scale>
|
||||
<table-name>CUSTOMERS</table-name>
|
||||
<catalog-name>TESTDB</catalog-name>
|
||||
<column-type>12</column-type>
|
||||
<column-type-name>VARCHAR</column-type-name>
|
||||
</column-definition>
|
||||
</metadata>
|
||||
<data>
|
||||
<currentRow>
|
||||
<columnValue>1</columnValue>
|
||||
<columnValue>Customer1</columnValue>
|
||||
</currentRow>
|
||||
<currentRow>
|
||||
<columnValue>2</columnValue>
|
||||
<columnValue>Customer2</columnValue>
|
||||
</currentRow>
|
||||
<currentRow>
|
||||
<columnValue>3</columnValue>
|
||||
<columnValue>Customer3</columnValue>
|
||||
</currentRow>
|
||||
<currentRow>
|
||||
<columnValue>4</columnValue>
|
||||
<columnValue>Customer4</columnValue>
|
||||
</currentRow>
|
||||
<currentRow>
|
||||
<columnValue>5</columnValue>
|
||||
<columnValue>Customer5</columnValue>
|
||||
</currentRow>
|
||||
</data>
|
||||
</webRowSet>
|
|
@ -1,479 +1,496 @@
|
|||
<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>com.baeldung</groupId>
|
||||
<artifactId>core-java</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
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>com.baeldung</groupId>
|
||||
<artifactId>core-java</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>core-java</name>
|
||||
<name>core-java</name>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.collections</groupId>
|
||||
<artifactId>collections-generic</artifactId>
|
||||
<version>${collections-generic.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>${commons-collections4.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>${commons-math3.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.decimal4j</groupId>
|
||||
<artifactId>decimal4j</artifactId>
|
||||
<version>${decimal4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>${bouncycastle.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.unix4j</groupId>
|
||||
<artifactId>unix4j-command</artifactId>
|
||||
<version>${unix4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.googlecode.grep4j</groupId>
|
||||
<artifactId>grep4j</artifactId>
|
||||
<version>${grep4j.version}</version>
|
||||
</dependency>
|
||||
<!-- web -->
|
||||
|
||||
<!-- marshalling -->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- logging -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
<!-- <scope>runtime</scope> -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>${avaitility.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.javamoney</groupId>
|
||||
<artifactId>moneta</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.owasp.esapi</groupId>
|
||||
<artifactId>esapi</artifactId>
|
||||
<version>2.1.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.codepoetics</groupId>
|
||||
<artifactId>protonpack</artifactId>
|
||||
<version>${protonpack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>one.util</groupId>
|
||||
<artifactId>streamex</artifactId>
|
||||
<version>${streamex.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vavr</groupId>
|
||||
<artifactId>vavr</artifactId>
|
||||
<version>${vavr.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>1.19</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>1.19</version>
|
||||
</dependency>
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>4.3.4.RELEASE</version>
|
||||
<groupId>net.sourceforge.collections</groupId>
|
||||
<artifactId>collections-generic</artifactId>
|
||||
<version>${collections-generic.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>core-java</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>${commons-collections4.version}</version>
|
||||
</dependency>
|
||||
|
||||
<plugins>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
</excludes>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>${commons-math3.version}</version>
|
||||
</dependency>
|
||||
|
||||
</configuration>
|
||||
</plugin>
|
||||
<dependency>
|
||||
<groupId>org.decimal4j</groupId>
|
||||
<artifactId>decimal4j</artifactId>
|
||||
<version>${decimal4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/libs</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>${bouncycastle.version}</version>
|
||||
</dependency>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>libs/</classpathPrefix>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<dependency>
|
||||
<groupId>org.unix4j</groupId>
|
||||
<artifactId>unix4j-command</artifactId>
|
||||
<version>${unix4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.grep4j</groupId>
|
||||
<artifactId>grep4j</artifactId>
|
||||
<version>${grep4j.version}</version>
|
||||
</dependency>
|
||||
<!-- web -->
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- marshalling -->
|
||||
|
||||
<plugin>
|
||||
<groupId>com.jolira</groupId>
|
||||
<artifactId>onejar-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<configuration>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
<attachToBuild>true</attachToBuild>
|
||||
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>one-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classifier>spring-boot</classifier>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- logging -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
<!-- <scope>runtime</scope> -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
|
||||
<arguments>
|
||||
<argument>-Xmx300m</argument>
|
||||
<argument>-XX:+UseParallelGC</argument>
|
||||
<argument>-classpath</argument>
|
||||
<classpath/>
|
||||
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- test scoped -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>${avaitility.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.javamoney</groupId>
|
||||
<artifactId>moneta</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.owasp.esapi</groupId>
|
||||
<artifactId>esapi</artifactId>
|
||||
<version>2.1.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.196</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.messaging.mq</groupId>
|
||||
<artifactId>fscontext</artifactId>
|
||||
<version>${fscontext.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.codepoetics</groupId>
|
||||
<artifactId>protonpack</artifactId>
|
||||
<version>${protonpack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>one.util</groupId>
|
||||
<artifactId>streamex</artifactId>
|
||||
<version>${streamex.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vavr</groupId>
|
||||
<artifactId>vavr</artifactId>
|
||||
<version>${vavr.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>1.19</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>1.19</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>4.3.4.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>1.5.8.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>core-java</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
</excludes>
|
||||
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/libs</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>libs/</classpathPrefix>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>com.jolira</groupId>
|
||||
<artifactId>onejar-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<configuration>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
<attachToBuild>true</attachToBuild>
|
||||
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>one-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classifier>spring-boot</classifier>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
|
||||
<arguments>
|
||||
<argument>-Xmx300m</argument>
|
||||
<argument>-XX:+UseParallelGC</argument>
|
||||
<argument>-classpath</argument>
|
||||
<classpath />
|
||||
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
</plugins>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>integration</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
</excludes>
|
||||
<includes>
|
||||
<include>**/*IntegrationTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<test.mime>json</test.mime>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>integration</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
</excludes>
|
||||
<includes>
|
||||
<include>**/*IntegrationTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<test.mime>json</test.mime>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-benchmarks</id>
|
||||
<!-- <phase>integration-test</phase>-->
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classpathScope>test</classpathScope>
|
||||
<executable>java</executable>
|
||||
<arguments>
|
||||
<argument>-classpath</argument>
|
||||
<classpath/>
|
||||
<argument>org.openjdk.jmh.Main</argument>
|
||||
<argument>.*</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-benchmarks</id>
|
||||
<!-- <phase>integration-test</phase> -->
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classpathScope>test</classpathScope>
|
||||
<executable>java</executable>
|
||||
<arguments>
|
||||
<argument>-classpath</argument>
|
||||
<classpath />
|
||||
<argument>org.openjdk.jmh.Main</argument>
|
||||
<argument>.*</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<!-- marshalling -->
|
||||
<jackson.version>2.8.5</jackson.version>
|
||||
<properties>
|
||||
<!-- marshalling -->
|
||||
<jackson.version>2.8.5</jackson.version>
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||
<logback.version>1.1.7</logback.version>
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||
<logback.version>1.1.7</logback.version>
|
||||
|
||||
<!-- util -->
|
||||
<guava.version>23.0</guava.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<bouncycastle.version>1.55</bouncycastle.version>
|
||||
<commons-codec.version>1.10</commons-codec.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<decimal4j.version>1.0.3</decimal4j.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<commons-collections4.version>4.1</commons-collections4.version>
|
||||
<collections-generic.version>4.01</collections-generic.version>
|
||||
<unix4j.version>0.4</unix4j.version>
|
||||
<grep4j.version>1.8.7</grep4j.version>
|
||||
<lombok.version>1.16.12</lombok.version>
|
||||
<fscontext.version>4.6-b01</fscontext.version>
|
||||
<protonpack.version>1.13</protonpack.version>
|
||||
<streamex.version>0.6.5</streamex.version>
|
||||
<vavr.version>0.9.0</vavr.version>
|
||||
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<mockito.version>2.8.9</mockito.version>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<avaitility.version>1.7.0</avaitility.version>
|
||||
<!-- util -->
|
||||
<guava.version>22.0</guava.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<bouncycastle.version>1.55</bouncycastle.version>
|
||||
<commons-codec.version>1.10</commons-codec.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<decimal4j.version>1.0.3</decimal4j.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<commons-collections4.version>4.1</commons-collections4.version>
|
||||
<collections-generic.version>4.01</collections-generic.version>
|
||||
<unix4j.version>0.4</unix4j.version>
|
||||
<grep4j.version>1.8.7</grep4j.version>
|
||||
<lombok.version>1.16.12</lombok.version>
|
||||
<fscontext.version>4.6-b01</fscontext.version>
|
||||
<protonpack.version>1.13</protonpack.version>
|
||||
<streamex.version>0.6.5</streamex.version>
|
||||
<vavr.version>0.9.0</vavr.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
</properties>
|
||||
</project>
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<mockito.version>2.8.9</mockito.version>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<avaitility.version>1.7.0</avaitility.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
</properties>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package com.baeldung.jdbcrowset;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import javax.sql.rowset.JdbcRowSet;
|
||||
import javax.sql.rowset.RowSetFactory;
|
||||
import javax.sql.rowset.RowSetProvider;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
public class DatabaseConfiguration {
|
||||
|
||||
|
||||
public static Connection geth2Connection() throws Exception {
|
||||
Class.forName("org.h2.Driver");
|
||||
System.out.println("Driver Loaded.");
|
||||
String url = "jdbc:h2:mem:testdb";
|
||||
return DriverManager.getConnection(url, "sa", "");
|
||||
}
|
||||
|
||||
public static void initDatabase(Statement stmt) throws SQLException{
|
||||
int iter = 1;
|
||||
while(iter<=5){
|
||||
String customer = "Customer"+iter;
|
||||
String sql ="INSERT INTO customers(id, name) VALUES ("+iter+ ",'"+customer+"');";
|
||||
System.out.println("here is sql statmeent for execution: " + sql);
|
||||
stmt.executeUpdate(sql);
|
||||
iter++;
|
||||
}
|
||||
|
||||
int iterb = 1;
|
||||
while(iterb<=5){
|
||||
String associate = "Associate"+iter;
|
||||
String sql = "INSERT INTO associates(id, name) VALUES("+iterb+",'"+associate+"');";
|
||||
System.out.println("here is sql statement for associate:"+ sql);
|
||||
stmt.executeUpdate(sql);
|
||||
iterb++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.jdbcrowset;
|
||||
|
||||
import javax.sql.RowSetEvent;
|
||||
import javax.sql.RowSetListener;
|
||||
|
||||
public class ExampleListener implements RowSetListener {
|
||||
|
||||
|
||||
public void cursorMoved(RowSetEvent event) {
|
||||
System.out.println("ExampleListener alerted of cursorMoved event");
|
||||
System.out.println(event.toString());
|
||||
}
|
||||
|
||||
public void rowChanged(RowSetEvent event) {
|
||||
System.out.println("ExampleListener alerted of rowChanged event");
|
||||
System.out.println(event.toString());
|
||||
}
|
||||
|
||||
public void rowSetChanged(RowSetEvent event) {
|
||||
System.out.println("ExampleListener alerted of rowSetChanged event");
|
||||
System.out.println(event.toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.baeldung.jdbcrowset;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.sql.RowSet;
|
||||
import javax.sql.rowset.Predicate;
|
||||
|
||||
public class FilterExample implements Predicate {
|
||||
|
||||
private Pattern pattern;
|
||||
|
||||
public FilterExample(String regexQuery) {
|
||||
if (regexQuery != null && !regexQuery.isEmpty()) {
|
||||
pattern = Pattern.compile(regexQuery);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean evaluate(RowSet rs) {
|
||||
try {
|
||||
if (!rs.isAfterLast()) {
|
||||
String name = rs.getString("name");
|
||||
System.out.println(String.format(
|
||||
"Searching for pattern '%s' in %s", pattern.toString(),
|
||||
name));
|
||||
Matcher matcher = pattern.matcher(name);
|
||||
return matcher.matches();
|
||||
} else
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean evaluate(Object value, int column) throws SQLException {
|
||||
throw new UnsupportedOperationException("This operation is unsupported.");
|
||||
}
|
||||
|
||||
public boolean evaluate(Object value, String columnName)
|
||||
throws SQLException {
|
||||
throw new UnsupportedOperationException("This operation is unsupported.");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
package com.baeldung.jdbcrowset;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import com.sun.rowset.*;
|
||||
|
||||
import javax.sql.rowset.CachedRowSet;
|
||||
import javax.sql.rowset.FilteredRowSet;
|
||||
import javax.sql.rowset.JdbcRowSet;
|
||||
import javax.sql.rowset.JoinRowSet;
|
||||
import javax.sql.rowset.RowSetFactory;
|
||||
import javax.sql.rowset.RowSetProvider;
|
||||
import javax.sql.rowset.WebRowSet;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class JdbcRowsetApplication {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(JdbcRowsetApplication.class, args);
|
||||
Statement stmt = null;
|
||||
try {
|
||||
Connection conn = DatabaseConfiguration.geth2Connection();
|
||||
|
||||
String drop = "DROP TABLE IF EXISTS customers, associates;";
|
||||
String schema = "CREATE TABLE customers (id INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY (id)); ";
|
||||
String schemapartb = "CREATE TABLE associates (id INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY (id));";
|
||||
|
||||
stmt = conn.createStatement();
|
||||
stmt.executeUpdate(drop);
|
||||
stmt.executeUpdate(schema);
|
||||
stmt.executeUpdate(schemapartb);
|
||||
// insert data
|
||||
DatabaseConfiguration.initDatabase(stmt);
|
||||
// JdbcRowSet Example
|
||||
String sql = "SELECT * FROM customers";
|
||||
JdbcRowSet jdbcRS;
|
||||
jdbcRS = new JdbcRowSetImpl(conn);
|
||||
jdbcRS.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
|
||||
jdbcRS.setCommand(sql);
|
||||
jdbcRS.execute();
|
||||
jdbcRS.addRowSetListener(new ExampleListener());
|
||||
|
||||
while (jdbcRS.next()) {
|
||||
// each call to next, generates a cursorMoved event
|
||||
System.out.println("id=" + jdbcRS.getString(1));
|
||||
System.out.println("name=" + jdbcRS.getString(2));
|
||||
}
|
||||
|
||||
// CachedRowSet Example
|
||||
String username = "sa";
|
||||
String password = "";
|
||||
String url = "jdbc:h2:mem:testdb";
|
||||
CachedRowSet crs = new CachedRowSetImpl();
|
||||
crs.setUsername(username);
|
||||
crs.setPassword(password);
|
||||
crs.setUrl(url);
|
||||
crs.setCommand(sql);
|
||||
crs.execute();
|
||||
crs.addRowSetListener(new ExampleListener());
|
||||
while (crs.next()) {
|
||||
if (crs.getInt("id") == 1) {
|
||||
System.out.println("CRS found customer1 and will remove the record.");
|
||||
crs.deleteRow();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// WebRowSet example
|
||||
WebRowSet wrs = new WebRowSetImpl();
|
||||
wrs.setUsername(username);
|
||||
wrs.setPassword(password);
|
||||
wrs.setUrl(url);
|
||||
wrs.setCommand(sql);
|
||||
wrs.execute();
|
||||
FileOutputStream ostream = new FileOutputStream("customers.xml");
|
||||
wrs.writeXml(ostream);
|
||||
|
||||
// JoinRowSet example
|
||||
CachedRowSetImpl customers = new CachedRowSetImpl();
|
||||
customers.setUsername(username);
|
||||
customers.setPassword(password);
|
||||
customers.setUrl(url);
|
||||
customers.setCommand(sql);
|
||||
customers.execute();
|
||||
|
||||
CachedRowSetImpl associates = new CachedRowSetImpl();
|
||||
associates.setUsername(username);
|
||||
associates.setPassword(password);
|
||||
associates.setUrl(url);
|
||||
String associatesSQL = "SELECT * FROM associates";
|
||||
associates.setCommand(associatesSQL);
|
||||
associates.execute();
|
||||
|
||||
JoinRowSet jrs = new JoinRowSetImpl();
|
||||
final String ID = "id";
|
||||
final String NAME = "name";
|
||||
jrs.addRowSet(customers, ID);
|
||||
jrs.addRowSet(associates, ID);
|
||||
jrs.last();
|
||||
System.out.println("Total rows: " + jrs.getRow());
|
||||
jrs.beforeFirst();
|
||||
while (jrs.next()) {
|
||||
|
||||
String string1 = jrs.getString(ID);
|
||||
String string2 = jrs.getString(NAME);
|
||||
System.out.println("ID: " + string1 + ", NAME: " + string2);
|
||||
}
|
||||
|
||||
// FilteredRowSet example
|
||||
RowSetFactory rsf = RowSetProvider.newFactory();
|
||||
FilteredRowSet frs = rsf.createFilteredRowSet();
|
||||
frs.setCommand("select * from customers");
|
||||
frs.execute(conn);
|
||||
frs.setFilter(new FilterExample("^[A-C].*"));
|
||||
|
||||
ResultSetMetaData rsmd = frs.getMetaData();
|
||||
int columncount = rsmd.getColumnCount();
|
||||
while (frs.next()) {
|
||||
for (int i = 1; i <= columncount; i++) {
|
||||
System.out.println(rsmd.getColumnLabel(i) + " = " + frs.getObject(i) + " ");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
package com.baeldung.jdbcrowset;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import javax.sql.rowset.CachedRowSet;
|
||||
import javax.sql.rowset.FilteredRowSet;
|
||||
import javax.sql.rowset.JdbcRowSet;
|
||||
import javax.sql.rowset.JoinRowSet;
|
||||
import javax.sql.rowset.RowSetFactory;
|
||||
import javax.sql.rowset.RowSetProvider;
|
||||
import javax.sql.rowset.WebRowSet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sun.rowset.CachedRowSetImpl;
|
||||
import com.sun.rowset.JdbcRowSetImpl;
|
||||
import com.sun.rowset.JoinRowSetImpl;
|
||||
import com.sun.rowset.WebRowSetImpl;
|
||||
|
||||
public class JdbcRowSetTest {
|
||||
Statement stmt = null;
|
||||
String username = "sa";
|
||||
String password = "";
|
||||
String url = "jdbc:h2:mem:testdb";
|
||||
String sql = "SELECT * FROM customers";
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Connection conn = DatabaseConfiguration.geth2Connection();
|
||||
|
||||
String drop = "DROP TABLE IF EXISTS customers, associates;";
|
||||
String schema = "CREATE TABLE customers (id INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY (id)); ";
|
||||
String schemapartb = "CREATE TABLE associates (id INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY (id));";
|
||||
stmt = conn.createStatement();
|
||||
stmt.executeUpdate(drop);
|
||||
stmt.executeUpdate(schema);
|
||||
stmt.executeUpdate(schemapartb);
|
||||
DatabaseConfiguration.initDatabase(stmt);
|
||||
|
||||
}
|
||||
|
||||
// JdbcRowSet Example
|
||||
@Test
|
||||
public void createJdbcRowSet_SelectCustomers_ThenCorrect() throws Exception {
|
||||
|
||||
String sql = "SELECT * FROM customers";
|
||||
JdbcRowSet jdbcRS;
|
||||
Connection conn = DatabaseConfiguration.geth2Connection();
|
||||
jdbcRS = new JdbcRowSetImpl(conn);
|
||||
jdbcRS.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
|
||||
jdbcRS.setCommand(sql);
|
||||
jdbcRS.execute();
|
||||
jdbcRS.addRowSetListener(new ExampleListener());
|
||||
|
||||
while (jdbcRS.next()) {
|
||||
// each call to next, generates a cursorMoved event
|
||||
System.out.println("id=" + jdbcRS.getString(1));
|
||||
System.out.println("name=" + jdbcRS.getString(2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// CachedRowSet Example
|
||||
@Test
|
||||
public void createCachedRowSet_DeleteRecord_ThenCorrect() throws Exception {
|
||||
|
||||
CachedRowSet crs = new CachedRowSetImpl();
|
||||
crs.setUsername(username);
|
||||
crs.setPassword(password);
|
||||
crs.setUrl(url);
|
||||
crs.setCommand(sql);
|
||||
crs.execute();
|
||||
crs.addRowSetListener(new ExampleListener());
|
||||
while (crs.next()) {
|
||||
if (crs.getInt("id") == 1) {
|
||||
System.out.println("CRS found customer1 and will remove the record.");
|
||||
crs.deleteRow();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WebRowSet example
|
||||
@Test
|
||||
public void createWebRowSet_SelectCustomers_WritetoXML_ThenCorrect() throws SQLException, IOException {
|
||||
|
||||
WebRowSet wrs = new WebRowSetImpl();
|
||||
wrs.setUsername(username);
|
||||
wrs.setPassword(password);
|
||||
wrs.setUrl(url);
|
||||
wrs.setCommand(sql);
|
||||
wrs.execute();
|
||||
FileOutputStream ostream = new FileOutputStream("customers.xml");
|
||||
wrs.writeXml(ostream);
|
||||
}
|
||||
|
||||
// JoinRowSet example
|
||||
@Test
|
||||
public void createCachedRowSets_DoJoinRowSet_ThenCorrect() throws Exception {
|
||||
|
||||
CachedRowSetImpl customers = new CachedRowSetImpl();
|
||||
customers.setUsername(username);
|
||||
customers.setPassword(password);
|
||||
customers.setUrl(url);
|
||||
customers.setCommand(sql);
|
||||
customers.execute();
|
||||
|
||||
CachedRowSetImpl associates = new CachedRowSetImpl();
|
||||
associates.setUsername(username);
|
||||
associates.setPassword(password);
|
||||
associates.setUrl(url);
|
||||
String associatesSQL = "SELECT * FROM associates";
|
||||
associates.setCommand(associatesSQL);
|
||||
associates.execute();
|
||||
|
||||
JoinRowSet jrs = new JoinRowSetImpl();
|
||||
final String ID = "id";
|
||||
final String NAME = "name";
|
||||
jrs.addRowSet(customers, ID);
|
||||
jrs.addRowSet(associates, ID);
|
||||
jrs.last();
|
||||
System.out.println("Total rows: " + jrs.getRow());
|
||||
jrs.beforeFirst();
|
||||
while (jrs.next()) {
|
||||
|
||||
String string1 = jrs.getString(ID);
|
||||
String string2 = jrs.getString(NAME);
|
||||
System.out.println("ID: " + string1 + ", NAME: " + string2);
|
||||
}
|
||||
}
|
||||
|
||||
// FilteredRowSet example
|
||||
@Test
|
||||
public void createFilteredRowSet_filterByRegexExpression_thenCorrect() throws Exception {
|
||||
RowSetFactory rsf = RowSetProvider.newFactory();
|
||||
FilteredRowSet frs = rsf.createFilteredRowSet();
|
||||
frs.setCommand("select * from customers");
|
||||
Connection conn = DatabaseConfiguration.geth2Connection();
|
||||
frs.execute(conn);
|
||||
frs.setFilter(new FilterExample("^[A-C].*"));
|
||||
|
||||
ResultSetMetaData rsmd = frs.getMetaData();
|
||||
int columncount = rsmd.getColumnCount();
|
||||
while (frs.next()) {
|
||||
for (int i = 1; i <= columncount; i++) {
|
||||
System.out.println(rsmd.getColumnLabel(i) + " = " + frs.getObject(i) + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue