Switched to DataNucleus/JPA/C*
This commit is contained in:
parent
848e64dcb2
commit
866ca6abc3
13 changed files with 957 additions and 425 deletions
154
build.xml
Normal file
154
build.xml
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
<!--
|
||||||
|
===================================================================
|
||||||
|
build
|
||||||
|
===================================================================
|
||||||
|
-->
|
||||||
|
<project name="crud" default="compile">
|
||||||
|
|
||||||
|
<!-- environment -->
|
||||||
|
<property environment="env"/>
|
||||||
|
<property name="project.location" location="."/>
|
||||||
|
<property name="project.build.debug" value="on"/>
|
||||||
|
<property name="Name" value="crud"/>
|
||||||
|
<property name="name" value="${Name}"/>
|
||||||
|
<property name="version" value="4.0"/>
|
||||||
|
|
||||||
|
<!-- project workspace directories -->
|
||||||
|
<property name="java.dir" value="src/main/java"/>
|
||||||
|
<property name="resources.dir" value="src/main/resources"/>
|
||||||
|
<property name="lib.dir" value="lib"/>
|
||||||
|
<property name="classes.dir" value="target/classes"/>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
===================================================================
|
||||||
|
Classpath properties
|
||||||
|
===================================================================
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- the classpath for running -->
|
||||||
|
<path id="run.classpath">
|
||||||
|
<fileset dir="${lib.dir}">
|
||||||
|
<include name="**/*.jar"/>
|
||||||
|
</fileset>
|
||||||
|
<pathelement location="${classes.dir}"/>
|
||||||
|
<pathelement location="${basedir}"/>
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<!-- the classpath for the compile -->
|
||||||
|
<path id="compile.classpath">
|
||||||
|
<pathelement location="${classes.dir}"/>
|
||||||
|
<fileset dir="${lib.dir}">
|
||||||
|
<include name="**/*.jar"/>
|
||||||
|
</fileset>
|
||||||
|
<pathelement location="${classes.dir}"/>
|
||||||
|
<pathelement location="${basedir}"/>
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
===================================================================
|
||||||
|
TARGET : clean
|
||||||
|
===================================================================
|
||||||
|
-->
|
||||||
|
<target name="clean">
|
||||||
|
<delete includeEmptyDirs="true" quiet="true">
|
||||||
|
<fileset dir="${basedir}/target"/>
|
||||||
|
</delete>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
===================================================================
|
||||||
|
TARGET : prepare
|
||||||
|
===================================================================
|
||||||
|
-->
|
||||||
|
<target name="prepare">
|
||||||
|
<mkdir dir="${classes.dir}"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
===================================================================
|
||||||
|
TARGET : compile.java
|
||||||
|
===================================================================
|
||||||
|
-->
|
||||||
|
<target name="compile" depends="clean,prepare">
|
||||||
|
<echo message="==================================================================="/>
|
||||||
|
<echo message="Compile configuration:"/>
|
||||||
|
<echo message="java.dir = ${java.dir}"/>
|
||||||
|
<echo message="classes.dir = ${classes.dir}"/>
|
||||||
|
<echo message="==================================================================="/>
|
||||||
|
<javac srcdir="${java.dir}" destdir="${classes.dir}" debug="${project.build.debug}" classpathref="compile.classpath">
|
||||||
|
<include name="**/*.java"/>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
===================================================================
|
||||||
|
TARGET : copy metadata files
|
||||||
|
===================================================================
|
||||||
|
-->
|
||||||
|
<target name="copy.metadata">
|
||||||
|
<copy todir="${classes.dir}">
|
||||||
|
<fileset dir="${resources.dir}" includes="**/*.xml"/>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
===================================================================
|
||||||
|
TARGET : enhance
|
||||||
|
===================================================================
|
||||||
|
-->
|
||||||
|
<target name="enhance" depends="compile,copy.metadata">
|
||||||
|
|
||||||
|
<!-- define the task enhancer -->
|
||||||
|
<taskdef name="enhancer" classname="org.datanucleus.enhancer.EnhancerTask">
|
||||||
|
<classpath refid="run.classpath"/>
|
||||||
|
</taskdef>
|
||||||
|
|
||||||
|
<!-- enhance -->
|
||||||
|
<enhancer classpathref="run.classpath" dir="${classes.dir}" verbose="true" api="JPA" persistenceUnit="crud">
|
||||||
|
<sysproperty key="log4j.configuration" value="file:log4j.properties"/>
|
||||||
|
</enhancer>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- SchemaTool "create" -->
|
||||||
|
<target name="createschema">
|
||||||
|
<taskdef name="schematool" classname="org.datanucleus.store.schema.SchemaToolTask">
|
||||||
|
<classpath refid="run.classpath"/>
|
||||||
|
</taskdef>
|
||||||
|
|
||||||
|
<schematool classpathref="run.classpath" failonerror="true" verbose="true"
|
||||||
|
mode="create" api="JPA" persistenceUnit="crud">
|
||||||
|
<sysproperty key="log4j.configuration" value="file:${basedir}/log4j.properties"/>
|
||||||
|
</schematool>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- SchemaTool "delete" -->
|
||||||
|
<target name="deleteschema">
|
||||||
|
<taskdef name="schematool" classname="org.datanucleus.store.schema.SchemaToolTask">
|
||||||
|
<classpath refid="run.classpath"/>
|
||||||
|
</taskdef>
|
||||||
|
|
||||||
|
<schematool classpathref="run.classpath" failonerror="true" fork="true" verbose="true"
|
||||||
|
mode="delete" api="JPA" persistenceUnit="crud">
|
||||||
|
<sysproperty key="log4j.configuration" value="file:${basedir}/log4j.properties"/>
|
||||||
|
</schematool>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- SchemaTool "dbinfo" -->
|
||||||
|
<target name="schemainfo">
|
||||||
|
<taskdef name="schematool" classname="org.datanucleus.store.schema.SchemaToolTask">
|
||||||
|
<classpath refid="run.classpath"/>
|
||||||
|
</taskdef>
|
||||||
|
|
||||||
|
<schematool classpathref="run.classpath" failonerror="true" fork="true" verbose="true"
|
||||||
|
mode="dbinfo" api="JPA" persistenceUnit="crud">
|
||||||
|
<sysproperty key="log4j.configuration" value="file:${basedir}/log4j.properties"/>
|
||||||
|
</schematool>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- Run the application -->
|
||||||
|
<target name="run" description="Run the application">
|
||||||
|
<copy file="log4j.properties"
|
||||||
|
tofile="${classes.dir}/log4j.properties"/>
|
||||||
|
<java classname="com.example.crud.Main" classpathref="run.classpath" fork="true"/>
|
||||||
|
</target>
|
||||||
|
</project>
|
55
crud.iml
Normal file
55
crud.iml
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="jpa" name="JPA">
|
||||||
|
<configuration>
|
||||||
|
<setting name="validation-enabled" value="true" />
|
||||||
|
<setting name="provider-name" value="" />
|
||||||
|
<datasource-mapping>
|
||||||
|
<factory-entry name="crud" />
|
||||||
|
</datasource-mapping>
|
||||||
|
<deploymentDescriptor name="persistence.xml" url="file://$MODULE_DIR$/src/main/resources/META-INF/persistence.xml" />
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||||
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="Maven: org.datanucleus:datanucleus-core:5.1.0-m3" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.datanucleus:datanucleus-api-jpa:5.1.0-m3" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.datanucleus:javax.persistence:2.1.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.datanucleus:datanucleus-cassandra:5.1.0-m3" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.datastax.cassandra:cassandra-driver-core:3.2.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.0.44.Final" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.0.44.Final" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: io.netty:netty-common:4.0.44.Final" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.0.44.Final" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.0.44.Final" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.guava:guava:19.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: io.dropwizard.metrics:metrics-core:3.1.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.7" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.github.jnr:jnr-ffi:2.0.7" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.github.jnr:jffi:1.2.10" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: com.github.jnr:jffi:native:1.2.10" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.ow2.asm:asm:5.0.3" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.ow2.asm:asm-commons:5.0.3" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.ow2.asm:asm-analysis:5.0.3" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.ow2.asm:asm-tree:5.0.3" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.ow2.asm:asm-util:5.0.3" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.github.jnr:jnr-x86asm:1.0.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.github.jnr:jnr-posix:3.0.27" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.github.jnr:jnr-constants:0.9.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.16.16" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -1,117 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="jpa" name="JPA">
|
|
||||||
<configuration>
|
|
||||||
<setting name="validation-enabled" value="true" />
|
|
||||||
<setting name="provider-name" value="" />
|
|
||||||
<datasource-mapping>
|
|
||||||
<factory-entry name="cassandra_pu" />
|
|
||||||
</datasource-mapping>
|
|
||||||
<deploymentDescriptor name="persistence.xml" url="file://$MODULE_DIR$/src/main/resources/META-INF/persistence.xml" />
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
|
||||||
<output url="file://$MODULE_DIR$/target/classes" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Maven: com.impetus.kundera.client:kundera-cassandra:3.9" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.cassandra:cassandra-all:3.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.xerial.snappy:snappy-java:1.1.1.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: net.jpountz.lz4:lz4:1.3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.antlr:antlr:3.5.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.antlr:ST4:4.0.8" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.antlr:antlr-runtime:3.5.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-core-asl:1.9.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-mapper-asl:1.9.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.boundary:high-scale-lib:1.0.6" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.11" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.mindrot:jbcrypt:0.3m" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.addthis.metrics:reporter-config3:3.0.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.addthis.metrics:reporter-config-base:3.0.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.hibernate:hibernate-validator:4.3.0.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: javax.validation:validation-api:1.0.0.GA" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.1.0.CR2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.thinkaurelius.thrift:thrift-server:0.3.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.lmax:disruptor:3.0.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.clearspring.analytics:stream:2.5.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: it.unimi.dsi:fastutil:6.5.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.thrift:libthrift:0.9.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.2.5" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.2.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.cassandra:cassandra-thrift:3.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.carrotsearch:hppc:0.5.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: de.jflex:jflex:1.6.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.ant:ant:1.7.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.ant:ant-launcher:1.7.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: net.mintern:primitive:1.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.rholder:snowball-stemmer:1.3.0.581.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.googlecode.concurrent-trees:concurrent-trees:2.4.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:4.0.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.jbellis:jamm:0.3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-all:4.0.36.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: joda-time:joda-time:2.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.fusesource:sigar:1.6.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.eclipse.jdt.core.compiler:ecj:4.4.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.caffinitas.ohc:ohc-core:0.4.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.ben-manes.caffeine:caffeine:2.2.6" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.impetus.kundera.core:kundera-core:3.9" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: javax:javaee-api:7.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.sun.mail:javax.mail:1.5.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.eclipse.persistence:org.eclipse.persistence.jpa.jpql:2.5.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: javax.transaction:jta:1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.thoughtworks.xstream:xstream:1.4.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: xmlpull:xmlpull:1.1.3.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: xpp3:xpp3_min:1.1.4c" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-configuration:commons-configuration:1.9" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.vividsolutions:jts:1.11" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: net.dataforte.cassandra:cassandra-connection-pool:0.7.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.impetus.kundera.client:kundera-cassandra-ds-driver:3.9" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: cglib:cglib:3.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.ow2.asm:asm:4.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.datastax.cassandra:cassandra-driver-core:3.2.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.0.44.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.0.44.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-common:4.0.44.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.0.44.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.0.44.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.google.guava:guava:19.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.dropwizard.metrics:metrics-core:3.1.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.jnr:jnr-ffi:2.0.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.jnr:jffi:1.2.10" level="project" />
|
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.github.jnr:jffi:native:1.2.10" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.ow2.asm:asm-commons:5.0.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.ow2.asm:asm-analysis:5.0.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.ow2.asm:asm-tree:5.0.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.ow2.asm:asm-util:5.0.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.jnr:jnr-x86asm:1.0.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.jnr:jnr-posix:3.0.27" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.github.jnr:jnr-constants:0.9.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.16.16" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
322
pom.xml
322
pom.xml
|
@ -1,58 +1,274 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
<modelVersion>4.0.0</modelVersion>
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<groupId>com.impetus.kundera</groupId>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>kundera-cassandra-example</artifactId>
|
<groupId>com.example.crud</groupId>
|
||||||
<packaging>jar</packaging>
|
<artifactId>crud-jpa-tutorial</artifactId>
|
||||||
<version>1.0</version>
|
<packaging>jar</packaging>
|
||||||
<name>kundera-cassandra-example</name>
|
<version>5.0</version>
|
||||||
<url>http://maven.apache.org</url>
|
<name>CRUD JPA Application</name>
|
||||||
|
<url>http://www.example.come</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<kundera.version>3.9</kundera.version>
|
<encoding>UTF-8</encoding>
|
||||||
</properties>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.impetus.kundera.client</groupId>
|
<groupId>org.datanucleus</groupId>
|
||||||
<artifactId>kundera-cassandra</artifactId>
|
<artifactId>datanucleus-core</artifactId>
|
||||||
<version>${kundera.version}</version>
|
<version>[5.0.0-m1, 5.9)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.impetus.kundera.client</groupId>
|
<groupId>org.datanucleus</groupId>
|
||||||
<artifactId>kundera-cassandra-ds-driver</artifactId>
|
<artifactId>datanucleus-api-jpa</artifactId>
|
||||||
<version>${kundera.version}</version>
|
<version>[5.0.0-m1, 5.9)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.datastax.cassandra</groupId>
|
<groupId>org.datanucleus</groupId>
|
||||||
<artifactId>cassandra-driver-core</artifactId>
|
<artifactId>javax.persistence</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>2.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>1.16.16</version>
|
<version>[1.2, 1.3)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>4.12</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<!-- ENABLE THIS FOR H2 -->
|
||||||
<plugins>
|
<!-- <dependency>
|
||||||
<plugin>
|
<groupId>org.datanucleus</groupId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<artifactId>datanucleus-rdbms</artifactId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<version>[5.0.0-m1, 5.9)</version>
|
||||||
<version>3.5.1</version>
|
</dependency>
|
||||||
<configuration>
|
<dependency>
|
||||||
<source>1.8</source>
|
<groupId>com.h2database</groupId>
|
||||||
<target>1.8</target>
|
<artifactId>h2</artifactId>
|
||||||
</configuration>
|
<version>1.3.168</version>
|
||||||
</plugin>
|
</dependency> -->
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
|
<!-- ENABLE THIS FOR HSQLDB -->
|
||||||
|
<!--dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-rdbms</artifactId>
|
||||||
|
<version>[5.0.0-m1, 5.9)</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>hsqldb</groupId>
|
||||||
|
<artifactId>hsqldb</artifactId>
|
||||||
|
<version>2.3.3</version>
|
||||||
|
</dependency-->
|
||||||
|
|
||||||
|
<!-- ENABLE THIS FOR MYSQL -->
|
||||||
|
<!--dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-rdbms</artifactId>
|
||||||
|
<version>[5.0.0-m1, 5.9)</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>5.1.17</version>
|
||||||
|
</dependency-->
|
||||||
|
|
||||||
|
<!-- ENABLE THIS FOR ODF -->
|
||||||
|
<!--dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-odf</artifactId>
|
||||||
|
<version>[5.0.0-m1, 5.9)</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.odftoolkit</groupId>
|
||||||
|
<artifactId>odfdom-java</artifactId>
|
||||||
|
<version>0.8.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>xerces</groupId>
|
||||||
|
<artifactId>xercesImpl</artifactId>
|
||||||
|
<version>[2.8, 3.0)</version>
|
||||||
|
</dependency-->
|
||||||
|
|
||||||
|
<!-- ENABLE THIS FOR EXCEL -->
|
||||||
|
<!--dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-excel</artifactId>
|
||||||
|
<version>[5.0.0-m1, 5.9)</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi</artifactId>
|
||||||
|
<version>3.6</version>
|
||||||
|
</dependency-->
|
||||||
|
|
||||||
|
<!-- ENABLE THIS FOR MongoDB -->
|
||||||
|
<!--dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-mongodb</artifactId>
|
||||||
|
<version>[5.0.0-m1, 5.9)</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mongodb</groupId>
|
||||||
|
<artifactId>mongo-java-driver</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</dependency-->
|
||||||
|
|
||||||
|
<!-- ENABLE THIS FOR HBase -->
|
||||||
|
<!--dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-hbase</artifactId>
|
||||||
|
<version>[5.0.0-m1, 5.9)</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.hbase</groupId>
|
||||||
|
<artifactId>hbase-client</artifactId>
|
||||||
|
<version>1.1.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
</dependency-->
|
||||||
|
|
||||||
|
<!-- ENABLE THIS FOR Neo4j -->
|
||||||
|
<!--dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-neo4j</artifactId>
|
||||||
|
<version>[5.0.0-m1, 5.9)</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.neo4j</groupId>
|
||||||
|
<artifactId>neo4j</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
</dependency-->
|
||||||
|
|
||||||
|
<!-- ENABLE THIS FOR Cassandra -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-cassandra</artifactId>
|
||||||
|
<version>[5.0.0-m1, 5.9)</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.datastax.cassandra</groupId>
|
||||||
|
<artifactId>cassandra-driver-core</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-cache</artifactId>
|
||||||
|
<version>5.0.0-release</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-guava</artifactId>
|
||||||
|
<version>5.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-jodatime</artifactId>
|
||||||
|
<version>5.0.0-release</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-java8</artifactId>
|
||||||
|
<version>4.2.3</version>
|
||||||
|
</dependency>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- ... -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.datastax.cassandra</groupId>
|
||||||
|
<artifactId>cassandra-driver-core</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.16.16</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>2.5</version>
|
||||||
|
<configuration>
|
||||||
|
<filesets>
|
||||||
|
<fileset>
|
||||||
|
<directory>${basedir}</directory>
|
||||||
|
<includes>
|
||||||
|
<include>*.log</include>
|
||||||
|
<include>tutorial.xls</include>
|
||||||
|
<include>tutorial.ods</include>
|
||||||
|
<include>tutorial.ooxml</include>
|
||||||
|
<include>tutorial.xml</include>
|
||||||
|
</includes>
|
||||||
|
</fileset>
|
||||||
|
<fileset>
|
||||||
|
<directory>${basedir}/testDB</directory>
|
||||||
|
</fileset>
|
||||||
|
</filesets>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.5.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.datanucleus</groupId>
|
||||||
|
<artifactId>datanucleus-maven-plugin</artifactId>
|
||||||
|
<version>5.0.0-release</version>
|
||||||
|
<configuration>
|
||||||
|
<api>JPA</api>
|
||||||
|
<persistenceUnitName>crud</persistenceUnitName>
|
||||||
|
<log4jConfiguration>${basedir}/src/main/resources/log4j.properties</log4jConfiguration>
|
||||||
|
<verbose>true</verbose>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>enhance</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>com.example.crud.Main</mainClass>
|
||||||
|
<systemProperties>
|
||||||
|
<systemProperty>
|
||||||
|
<key>log4j.configuration</key>
|
||||||
|
<value>file:${basedir}/src/main/resources/log4j.properties</value>
|
||||||
|
</systemProperty>
|
||||||
|
</systemProperties>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
<configuration>
|
||||||
|
<descriptors>
|
||||||
|
<descriptor>${basedir}/assembly.xml</descriptor>
|
||||||
|
</descriptors>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
199
src/main/java/com/example/crud/Main.java
Normal file
199
src/main/java/com/example/crud/Main.java
Normal file
|
@ -0,0 +1,199 @@
|
||||||
|
package com.example.crud;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.EntityManagerFactory;
|
||||||
|
import javax.persistence.EntityTransaction;
|
||||||
|
import javax.persistence.EntityGraph;
|
||||||
|
import javax.persistence.Persistence;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
|
||||||
|
import com.example.crud.entities.*;
|
||||||
|
|
||||||
|
import org.datanucleus.util.NucleusLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controlling application for the DataNucleus Tutorial using JPA.
|
||||||
|
* Uses the "persistence-unit" called "Tutorial".
|
||||||
|
*/
|
||||||
|
public class Main
|
||||||
|
{
|
||||||
|
public static void main(String args[])
|
||||||
|
{
|
||||||
|
// Create an EntityManagerFactory for this "persistence-unit"
|
||||||
|
// See the file "META-INF/persistence.xml"
|
||||||
|
EntityManagerFactory emf = Persistence.createEntityManagerFactory("crud");
|
||||||
|
|
||||||
|
// Persistence of a Product and a Book.
|
||||||
|
EntityManager em = emf.createEntityManager();
|
||||||
|
EntityTransaction tx = em.getTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tx.begin();
|
||||||
|
|
||||||
|
Inventory inv = new Inventory("My Inventory");
|
||||||
|
Product product = new Product("Sony Discman", "A standard discman from Sony", 200.00);
|
||||||
|
inv.getProducts().add(product);
|
||||||
|
Book book = new Book("Lord of the Rings by Tolkien", "The classic story", 49.99, "JRR Tolkien",
|
||||||
|
"12345678", "MyBooks Factory");
|
||||||
|
inv.getProducts().add(book);
|
||||||
|
|
||||||
|
em.persist(inv);
|
||||||
|
|
||||||
|
tx.commit();
|
||||||
|
System.out.println("Product and Book have been persisted");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
NucleusLogger.GENERAL.error(">> Exception persisting data", e);
|
||||||
|
System.err.println("Error persisting data : " + e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (tx.isActive())
|
||||||
|
{
|
||||||
|
tx.rollback();
|
||||||
|
}
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
emf.getCache().evictAll();
|
||||||
|
System.out.println("");
|
||||||
|
|
||||||
|
// Perform a retrieve of the Inventory and detach it (by closing the EM)
|
||||||
|
em = emf.createEntityManager();
|
||||||
|
tx = em.getTransaction();
|
||||||
|
Inventory inv = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tx.begin();
|
||||||
|
|
||||||
|
// Do a find() of the Inventory
|
||||||
|
// Set the EntityGraph as something pulling in all Products
|
||||||
|
// Note : you could achieve the same by either
|
||||||
|
// 1). access the Inventory.products field before commit
|
||||||
|
// 2). set fetch=EAGER for the Inventory.products field
|
||||||
|
System.out.println("Executing find() on Inventory");
|
||||||
|
EntityGraph allGraph = em.getEntityGraph("allProps");
|
||||||
|
Map hints = new HashMap();
|
||||||
|
hints.put("javax.persistence.loadgraph", allGraph);
|
||||||
|
inv = em.find(Inventory.class, "My Inventory", hints);
|
||||||
|
System.out.println("Retrieved Inventory as " + inv);
|
||||||
|
|
||||||
|
tx.commit();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
NucleusLogger.GENERAL.error(">> Exception performing find() on data", e);
|
||||||
|
System.err.println("Error performing find() on data : " + e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (tx.isActive())
|
||||||
|
{
|
||||||
|
tx.rollback();
|
||||||
|
}
|
||||||
|
em.close(); // This will detach all current managed objects
|
||||||
|
}
|
||||||
|
for (Product prod : inv.getProducts())
|
||||||
|
{
|
||||||
|
System.out.println(">> After Detach : Inventory has a product=" + prod);
|
||||||
|
}
|
||||||
|
System.out.println("");
|
||||||
|
|
||||||
|
// Perform some query operations
|
||||||
|
em = emf.createEntityManager();
|
||||||
|
tx = em.getTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tx.begin();
|
||||||
|
System.out.println("Executing Query for Products with price below 150.00");
|
||||||
|
Query q = em.createQuery("SELECT p FROM Product p WHERE p.price < 150.00 ORDER BY p.price");
|
||||||
|
List results = q.getResultList();
|
||||||
|
Iterator iter = results.iterator();
|
||||||
|
while (iter.hasNext())
|
||||||
|
{
|
||||||
|
Object obj = iter.next();
|
||||||
|
System.out.println("> " + obj);
|
||||||
|
|
||||||
|
// Give an example of an update
|
||||||
|
if (obj instanceof Book)
|
||||||
|
{
|
||||||
|
Book b = (Book)obj;
|
||||||
|
b.setDescription(b.getDescription() + " REDUCED");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.commit();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
NucleusLogger.GENERAL.error(">> Exception querying data", e);
|
||||||
|
System.err.println("Error querying data : " + e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (tx.isActive())
|
||||||
|
{
|
||||||
|
tx.rollback();
|
||||||
|
}
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
System.out.println("");
|
||||||
|
|
||||||
|
// Clean out the database
|
||||||
|
em = emf.createEntityManager();
|
||||||
|
tx = em.getTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tx.begin();
|
||||||
|
|
||||||
|
System.out.println("Deleting all products from persistence");
|
||||||
|
inv = (Inventory)em.find(Inventory.class, "My Inventory");
|
||||||
|
|
||||||
|
System.out.println("Clearing out Inventory");
|
||||||
|
inv.getProducts().clear();
|
||||||
|
em.flush();
|
||||||
|
|
||||||
|
System.out.println("Deleting Inventory");
|
||||||
|
em.remove(inv);
|
||||||
|
|
||||||
|
System.out.println("Deleting all products from persistence");
|
||||||
|
Query q = em.createQuery("SELECT p FROM Product p");
|
||||||
|
List<Product> products = q.getResultList();
|
||||||
|
int numDeleted = 0;
|
||||||
|
for (Product prod : products)
|
||||||
|
{
|
||||||
|
em.remove(prod);
|
||||||
|
numDeleted++;
|
||||||
|
}
|
||||||
|
System.out.println("Deleted " + numDeleted + " products");
|
||||||
|
|
||||||
|
tx.commit();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
NucleusLogger.GENERAL.error(">> Exception in bulk delete of data", e);
|
||||||
|
System.err.println("Error in bulk delete of data : " + e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (tx.isActive())
|
||||||
|
{
|
||||||
|
tx.rollback();
|
||||||
|
}
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("End of Tutorial");
|
||||||
|
emf.close();
|
||||||
|
}
|
||||||
|
}
|
58
src/main/java/com/example/crud/entities/Book.java
Normal file
58
src/main/java/com/example/crud/entities/Book.java
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
package com.example.crud.entities;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Definition of a Book. Extends basic Product class.
|
||||||
|
**/
|
||||||
|
@Data @Entity
|
||||||
|
@EqualsAndHashCode(callSuper=false)
|
||||||
|
@ToString
|
||||||
|
public class Book extends Product
|
||||||
|
{
|
||||||
|
/** Author of the Book. */
|
||||||
|
@Basic
|
||||||
|
private String author = null;
|
||||||
|
|
||||||
|
/** ISBN number of the book. */
|
||||||
|
@Basic
|
||||||
|
private String isbn = null;
|
||||||
|
|
||||||
|
/** Publisher of the Book. */
|
||||||
|
@Basic
|
||||||
|
private String publisher = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default Constructor.
|
||||||
|
**/
|
||||||
|
protected Book() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* @param name name of product
|
||||||
|
* @param description description of product
|
||||||
|
* @param price Price
|
||||||
|
* @param author Author of the book
|
||||||
|
* @param isbn ISBN number of the book
|
||||||
|
* @param publisher Name of publisher of the book
|
||||||
|
**/
|
||||||
|
public Book(String name,
|
||||||
|
String description,
|
||||||
|
double price,
|
||||||
|
String author,
|
||||||
|
String isbn,
|
||||||
|
String publisher) {
|
||||||
|
super(name,description,price);
|
||||||
|
this.author = author;
|
||||||
|
this.isbn = isbn;
|
||||||
|
this.publisher = publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
35
src/main/java/com/example/crud/entities/Inventory.java
Normal file
35
src/main/java/com/example/crud/entities/Inventory.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package com.example.crud.entities;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.NamedEntityGraph;
|
||||||
|
import javax.persistence.NamedAttributeNode;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Definition of an Inventory of products.
|
||||||
|
*/
|
||||||
|
@Data @Entity
|
||||||
|
@ToString
|
||||||
|
@NamedEntityGraph(name="allProps",
|
||||||
|
attributeNodes={@NamedAttributeNode("name"), @NamedAttributeNode("products")})
|
||||||
|
public class Inventory
|
||||||
|
{
|
||||||
|
@Id
|
||||||
|
private String name=null;
|
||||||
|
|
||||||
|
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH})
|
||||||
|
public Set<Product> products = new HashSet<Product>();
|
||||||
|
|
||||||
|
public Inventory(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,19 +1,4 @@
|
||||||
/*******************************************************************************
|
package com.example.crud.entities;
|
||||||
* * Copyright 2016 Impetus Infotech.
|
|
||||||
* *
|
|
||||||
* * Licensed 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.
|
|
||||||
******************************************************************************/
|
|
||||||
package com.impetus.kundera.entities;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
57
src/main/java/com/example/crud/entities/Product.java
Normal file
57
src/main/java/com/example/crud/entities/Product.java
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package com.example.crud.entities;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Inheritance;
|
||||||
|
import javax.persistence.InheritanceType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Definition of a Product
|
||||||
|
* Represents a product, and contains the key aspects of the item.
|
||||||
|
**/
|
||||||
|
@Data @Entity
|
||||||
|
@ToString
|
||||||
|
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
|
||||||
|
public class Product
|
||||||
|
{
|
||||||
|
/** Id for the product. */
|
||||||
|
@Id
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
/** Name of the Product. */
|
||||||
|
@Basic
|
||||||
|
private String name=null;
|
||||||
|
|
||||||
|
/** Description of the Product. */
|
||||||
|
@Basic
|
||||||
|
private String description=null;
|
||||||
|
|
||||||
|
/** Price of the Product. */
|
||||||
|
@Basic
|
||||||
|
@Column (name="THE_PRICE")
|
||||||
|
private double price=0.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
protected Product() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* @param name name of product
|
||||||
|
* @param description description of product
|
||||||
|
* @param price Price
|
||||||
|
**/
|
||||||
|
public Product(String name, String description, double price) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
54
src/main/resources/META-INF/orm.xml
Normal file
54
src/main/resources/META-INF/orm.xml
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
|
||||||
|
version="1.0">
|
||||||
|
<description>JPA Mapping for CRUD/JPA</description>
|
||||||
|
<package>com.example.crud.entities</package>
|
||||||
|
|
||||||
|
<entity class="com.example.crud.entities.Product" name="Product">
|
||||||
|
<table name="JPA_PRODUCTS"/>
|
||||||
|
<inheritance strategy="JOINED"/>
|
||||||
|
<attributes>
|
||||||
|
<id name="id">
|
||||||
|
<generated-value strategy="AUTO"/>
|
||||||
|
</id>
|
||||||
|
<basic name="name">
|
||||||
|
<column name="PRODUCT_NAME" length="100"/>
|
||||||
|
</basic>
|
||||||
|
<basic name="description">
|
||||||
|
<column length="255"/>
|
||||||
|
</basic>
|
||||||
|
</attributes>
|
||||||
|
</entity>
|
||||||
|
|
||||||
|
<entity class="com.example.crud.entities.Book" name="Book">
|
||||||
|
<table name="JPA_BOOKS"/>
|
||||||
|
<attributes>
|
||||||
|
<basic name="isbn">
|
||||||
|
<column name="ISBN" length="20"></column>
|
||||||
|
</basic>
|
||||||
|
<basic name="author">
|
||||||
|
<column name="AUTHOR" length="40"/>
|
||||||
|
</basic>
|
||||||
|
<basic name="publisher">
|
||||||
|
<column name="PUBLISHER" length="40"/>
|
||||||
|
</basic>
|
||||||
|
</attributes>
|
||||||
|
</entity>
|
||||||
|
|
||||||
|
<entity class="com.example.crud.entities.Inventory" name="Inventory">
|
||||||
|
<table name="JPA_INVENTORY"/>
|
||||||
|
<attributes>
|
||||||
|
<id name="name">
|
||||||
|
<column name="NAME" length="40"></column>
|
||||||
|
</id>
|
||||||
|
<one-to-many name="products">
|
||||||
|
<join-table name="JPA_INVENTORY_PRODUCTS">
|
||||||
|
<join-column name="INVENTORY_ID_OID"/>
|
||||||
|
<inverse-join-column name="PRODUCT_ID_EID"/>
|
||||||
|
</join-table>
|
||||||
|
</one-to-many>
|
||||||
|
</attributes>
|
||||||
|
</entity>
|
||||||
|
</entity-mappings>
|
|
@ -1,21 +1,58 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
|
||||||
https://raw.github.com/impetus-opensource/Kundera/Kundera-2.0.4/kundera-core/src/test/resources/META-INF/persistence_2_0.xsd"
|
|
||||||
version="2.0">
|
|
||||||
|
|
||||||
<persistence-unit name="cassandra_pu">
|
<persistence-unit name="crud">
|
||||||
<provider>com.impetus.kundera.KunderaPersistence</provider>
|
<class>com.example.crud.entities.Inventory</class>
|
||||||
<properties>
|
<class>com.example.crud.entities.Product</class>
|
||||||
<property name="kundera.nodes" value="localhost" />
|
<class>com.example.crud.entities.Book</class>
|
||||||
<property name="kundera.port" value="9042" />
|
<exclude-unlisted-classes/>
|
||||||
<property name="kundera.keyspace" value="kc" />
|
|
||||||
<property name="kundera.dialect" value="cassandra" />
|
<properties>
|
||||||
<property name="kundera.client.lookup.class" value="com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory" />
|
<!-- ENABLE THESE FOR H2 -->
|
||||||
<!--
|
<!-- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:nucleus1"/>
|
||||||
<property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
|
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
|
||||||
<property name="kundera.cache.config.resource" value="/ehcache-test.xml" /> -->
|
<property name="javax.persistence.jdbc.user" value="sa"/>
|
||||||
</properties>
|
<property name="javax.persistence.jdbc.password" value=""/> -->
|
||||||
</persistence-unit>
|
|
||||||
|
<!-- ENABLE THESE FOR HSQLDB -->
|
||||||
|
<!--property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:nucleus1"/>
|
||||||
|
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
|
||||||
|
<property name="javax.persistence.jdbc.user" value="sa"/>
|
||||||
|
<property name="javax.persistence.jdbc.password" value=""/-->
|
||||||
|
|
||||||
|
<!-- ENABLE THESE FOR MySQL/MariaDB -->
|
||||||
|
<!-- Change the "nucleus" to your database name, and the user/password -->
|
||||||
|
<!--property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1/nucleus?useServerPrepStmts=false"/>
|
||||||
|
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
|
||||||
|
<property name="javax.persistence.jdbc.user" value="mysql" />
|
||||||
|
<property name="javax.persistence.jdbc.password" value=""/-->
|
||||||
|
|
||||||
|
<!-- ENABLE THESE FOR ODF -->
|
||||||
|
<!-- Change the "tutorial.ods" to include the path to your ODF file -->
|
||||||
|
<!--property name="javax.persistence.jdbc.url" value="odf:file:tutorial.ods"/-->
|
||||||
|
|
||||||
|
<!-- ENABLE THESE FOR EXCEL -->
|
||||||
|
<!-- Change the "tutorial.xls" to include the path to your Excel file -->
|
||||||
|
<!--property name="javax.persistence.jdbc.url" value="excel:file:tutorial.xls"/-->
|
||||||
|
|
||||||
|
<!-- ENABLE THESE FOR MONGODB -->
|
||||||
|
<!--property name="javax.persistence.jdbc.url" value="mongodb:/nucleus1"/-->
|
||||||
|
|
||||||
|
<!-- ENABLE THESE FOR HBASE -->
|
||||||
|
<!--property name="javax.persistence.jdbc.url" value="hbase:"/-->
|
||||||
|
|
||||||
|
<!-- ENABLE THESE FOR NEO4J -->
|
||||||
|
<!-- Change the "testDB" to the path to your Neo4j graph DB file -->
|
||||||
|
<!--property name="javax.persistence.jdbc.url" value="neo4j:testDB"/-->
|
||||||
|
|
||||||
|
<!-- ENABLE THESE FOR CASSANDRA -->
|
||||||
|
<property name="javax.persistence.jdbc.url" value="cassandra:"/>
|
||||||
|
<property name="datanucleus.mapping.Schema" value="kc"/>
|
||||||
|
|
||||||
|
<property name="datanucleus.schema.autoCreateAll" value="true"/>
|
||||||
|
</properties>
|
||||||
|
</persistence-unit>
|
||||||
|
|
||||||
</persistence>
|
</persistence>
|
||||||
|
|
21
src/main/resources/log4j.properties
Normal file
21
src/main/resources/log4j.properties
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# LOG4J Configuration
|
||||||
|
# ===================
|
||||||
|
|
||||||
|
# Basic logging goes to "crud.log"
|
||||||
|
log4j.appender.A1=org.apache.log4j.FileAppender
|
||||||
|
log4j.appender.A1.File=crud.log
|
||||||
|
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n
|
||||||
|
#log4j.appender.A1.Threshold=INFO
|
||||||
|
|
||||||
|
# Categories
|
||||||
|
# Each category can be set to a "level", and to direct to an appender
|
||||||
|
|
||||||
|
# Default to DEBUG level for all DataNucleus categories
|
||||||
|
log4j.logger.DataNucleus = DEBUG, A1
|
||||||
|
|
||||||
|
log4j.category.com.mchange.v2.c3p0=INFO, A1
|
||||||
|
log4j.category.com.mchange.v2.resourcepool=INFO, A1
|
||||||
|
log4j.category.org.logicalcobwebs.proxool=INFO,A1
|
||||||
|
|
||||||
|
log4j.category.org.apache.hadoop.conf.Configuration=ERROR
|
|
@ -1,222 +0,0 @@
|
||||||
package com.impetus.kundera;
|
|
||||||
|
|
||||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
|
||||||
import com.datastax.driver.core.querybuilder.Select;
|
|
||||||
import com.impetus.client.cassandra.common.CassandraConstants;
|
|
||||||
import com.impetus.kundera.entities.Person;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.junit.*;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Class CRUDTest.
|
|
||||||
*/
|
|
||||||
public class CRUDTest
|
|
||||||
{
|
|
||||||
private Log log = LogFactory.getLog(getClass().getName());
|
|
||||||
|
|
||||||
/** The Constant PU. */
|
|
||||||
private static final String PU = "cassandra_pu";
|
|
||||||
|
|
||||||
/** The emf. */
|
|
||||||
private static EntityManagerFactory emf;
|
|
||||||
|
|
||||||
/** The em. */
|
|
||||||
private EntityManager em;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the up before class.
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* the exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void SetUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
Map propertyMap = new HashMap();
|
|
||||||
//propertyMap.put(PersistenceProperties.KUNDERA_DDL_AUTO_PREPARE, "create");
|
|
||||||
propertyMap.put("kundera.batch.size", "5");
|
|
||||||
propertyMap.put(CassandraConstants.CQL_VERSION, CassandraConstants.CQL_VERSION_3_0);
|
|
||||||
emf = Persistence.createEntityManagerFactory(PU, propertyMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the up.
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* the exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
em = emf.createEntityManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test crud operations.
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* the exception
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testCRUDOperations() throws Exception
|
|
||||||
{
|
|
||||||
testInsert();
|
|
||||||
testMerge();
|
|
||||||
testUpdate();
|
|
||||||
testCache();
|
|
||||||
testTransaction();
|
|
||||||
testBatch();
|
|
||||||
testQueryBuilder();
|
|
||||||
testRemove();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test insert.
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* the exception
|
|
||||||
*/
|
|
||||||
private void testInsert() throws Exception
|
|
||||||
{
|
|
||||||
Person p = new Person();
|
|
||||||
p.setPersonId("101");
|
|
||||||
p.setPersonFirstName("James");
|
|
||||||
p.setPersonLastName("Bond");
|
|
||||||
p.setAge(24);
|
|
||||||
//p.addEmail("007@mi6.gov");
|
|
||||||
em.persist(p);
|
|
||||||
em.flush();
|
|
||||||
|
|
||||||
Person person = em.find(Person.class, "101");
|
|
||||||
Assert.assertNotNull(person);
|
|
||||||
Assert.assertEquals("101", person.getPersonId());
|
|
||||||
Assert.assertEquals("James Bond", person.getPersonName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test merge.
|
|
||||||
*/
|
|
||||||
private void testMerge()
|
|
||||||
{
|
|
||||||
Person person = em.find(Person.class, "101");
|
|
||||||
person.setPersonLastName("Blond");
|
|
||||||
//person.addEmail("jamesbond@gmail.com");
|
|
||||||
person = em.merge(person);
|
|
||||||
em.flush();
|
|
||||||
|
|
||||||
Person p2 = em.find(Person.class, "101");
|
|
||||||
Assert.assertEquals("Blond", p2.getPersonLastName());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testCache() {
|
|
||||||
Cache cache = emf.getCache();
|
|
||||||
cache.evictAll();
|
|
||||||
log.info("Person in Cache: " + cache.contains(Person.class, "101"));
|
|
||||||
Person person = em.find(Person.class, "101");
|
|
||||||
log.info("Person in Cache: " + cache.contains(Person.class, person.getPersonId()));
|
|
||||||
cache.evictAll();
|
|
||||||
log.info("Person in Cache: " + cache.contains(Person.class, person.getPersonId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testUpdate()
|
|
||||||
{
|
|
||||||
Person person = em.find(Person.class, "101");
|
|
||||||
/*
|
|
||||||
// In Query set Paramater.
|
|
||||||
queryString = "Update PersonCassandra p SET p.personName = 'Kuldeep' WHERE p.personId IN :idList";
|
|
||||||
|
|
||||||
List<String> id = new ArrayList<String>();
|
|
||||||
id.add("1");
|
|
||||||
id.add("2");
|
|
||||||
id.add("3");
|
|
||||||
|
|
||||||
cqlQuery = parseAndCreateUpdateQuery(kunderaQuery, emf, em, pu, PersonCassandra.class, Integer.MAX_VALUE);
|
|
||||||
KunderaQuery kunderaQuery = getQueryObject(queryString, emf);
|
|
||||||
kunderaQuery.setParameter("idList", id);
|
|
||||||
|
|
||||||
PersistenceDelegator pd = getPersistenceDelegator(em, getpd);
|
|
||||||
EntityManagerFactoryImpl.KunderaMetadata kunderaMetadata = ((EntityManagerFactoryImpl) emf).getKunderaMetadataInstance();
|
|
||||||
|
|
||||||
CassQuery query = new CassQuery(kunderaQuery, pd, kunderaMetadata);
|
|
||||||
query.setMaxResults(maxResult);
|
|
||||||
if(ttl != null)
|
|
||||||
{
|
|
||||||
query.applyTTL(ttl);
|
|
||||||
}
|
|
||||||
|
|
||||||
String cqlQuery = query.createUpdateQuery(kunderaQuery);
|
|
||||||
return cqlQuery;
|
|
||||||
*/
|
|
||||||
person.setPersonFirstName("Jim");
|
|
||||||
em.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testTransaction()
|
|
||||||
{
|
|
||||||
EntityTransaction txn = em.getTransaction();
|
|
||||||
txn.begin();
|
|
||||||
Person person = new Person();
|
|
||||||
person.setPersonFirstName("Fred");
|
|
||||||
person.setPersonLastName("Johnson");
|
|
||||||
person.setAge(22);
|
|
||||||
em.persist(person);
|
|
||||||
txn.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testBatch()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testQueryBuilder()
|
|
||||||
{
|
|
||||||
String table = em.getMetamodel().entity(Person.class).getName();
|
|
||||||
Select q = QueryBuilder.select().all().from(table);
|
|
||||||
Query query = em.createQuery(q.getQueryString());
|
|
||||||
query.getResultList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test remove.
|
|
||||||
*/
|
|
||||||
private void testRemove()
|
|
||||||
{
|
|
||||||
Person p = em.find(Person.class, "101");
|
|
||||||
em.remove(p);
|
|
||||||
|
|
||||||
Person p1 = em.find(Person.class, "101");
|
|
||||||
Assert.assertNull(p1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tear down.
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* the exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
em.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tear down after class.
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* the exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
if (emf != null)
|
|
||||||
{
|
|
||||||
emf.close();
|
|
||||||
emf = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue