Moving forward, last with Kundera/JPA.
This commit is contained in:
parent
e722450677
commit
848e64dcb2
5 changed files with 265 additions and 47 deletions
117
kundera-cassandra-example.iml
Normal file
117
kundera-cassandra-example.iml
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
<?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>
|
17
pom.xml
17
pom.xml
|
@ -9,7 +9,7 @@
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<kundera.version>3.6</kundera.version>
|
<kundera.version>3.9</kundera.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -18,6 +18,21 @@
|
||||||
<artifactId>kundera-cassandra</artifactId>
|
<artifactId>kundera-cassandra</artifactId>
|
||||||
<version>${kundera.version}</version>
|
<version>${kundera.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.impetus.kundera.client</groupId>
|
||||||
|
<artifactId>kundera-cassandra-ds-driver</artifactId>
|
||||||
|
<version>${kundera.version}</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>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
|
|
@ -15,21 +15,24 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package com.impetus.kundera.entities;
|
package com.impetus.kundera.entities;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Entity;
|
import java.util.Date;
|
||||||
import javax.persistence.Id;
|
import java.util.HashSet;
|
||||||
import javax.persistence.Table;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class Person.
|
* The Class Person.
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "PERSON")
|
@Cacheable
|
||||||
|
@Table( name = "PERSON",
|
||||||
|
indexes = {
|
||||||
|
@Index(name = "last_name_idx", columnList="PERSON_LAST_NAME", unique = true),
|
||||||
|
@Index(name = "email_idx", columnList="EMAIL", unique = false)})
|
||||||
public class Person
|
public class Person
|
||||||
{
|
{
|
||||||
|
|
||||||
/** The person id. */
|
/** The person id. */
|
||||||
@Id
|
@Id @GeneratedValue(strategy=GenerationType.AUTO)
|
||||||
@Column(name = "PERSON_ID")
|
@Column(name = "PERSON_ID")
|
||||||
private String personId;
|
private String personId;
|
||||||
|
|
||||||
|
@ -38,13 +41,30 @@ public class Person
|
||||||
private String personFirstName;
|
private String personFirstName;
|
||||||
|
|
||||||
/** The person last name. */
|
/** The person last name. */
|
||||||
@Column(name = "PERSON_LAST_NAME")
|
@Column(name = "PERSON_LAST_NAME", nullable = false)
|
||||||
private String personLastName;
|
private String personLastName;
|
||||||
|
|
||||||
/** The age. */
|
/** The age. */
|
||||||
@Column(name = "AGE")
|
@Column(name = "AGE")
|
||||||
private int age;
|
private int age;
|
||||||
|
|
||||||
|
/** Email addresses.
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "EMAIL")
|
||||||
|
@Transient
|
||||||
|
private Set<String> email = new HashSet<>();
|
||||||
|
|
||||||
|
@Column(name = "UPDATED")
|
||||||
|
@Temporal(TemporalType.DATE)
|
||||||
|
private Date updated;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@Column(name = "VERSION")
|
||||||
|
@Version
|
||||||
|
private long version;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the person id.
|
* Gets the person id.
|
||||||
*
|
*
|
||||||
|
@ -139,4 +159,6 @@ public class Person
|
||||||
this.age = age;
|
this.age = age;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public void addEmail(String email) { this.email.add(email); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,13 @@
|
||||||
<provider>com.impetus.kundera.KunderaPersistence</provider>
|
<provider>com.impetus.kundera.KunderaPersistence</provider>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="kundera.nodes" value="localhost" />
|
<property name="kundera.nodes" value="localhost" />
|
||||||
<property name="kundera.port" value="9160" />
|
<property name="kundera.port" value="9042" />
|
||||||
<property name="kundera.keyspace" value="KunderaExamples" />
|
<property name="kundera.keyspace" value="kc" />
|
||||||
<property name="kundera.dialect" value="cassandra" />
|
<property name="kundera.dialect" value="cassandra" />
|
||||||
<property name="kundera.ddl.auto.prepare" value="update" />
|
<property name="kundera.client.lookup.class" value="com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory" />
|
||||||
<property name="kundera.client.lookup.class"
|
<!--
|
||||||
value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />
|
<property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
|
||||||
|
<property name="kundera.cache.config.resource" value="/ehcache-test.xml" /> -->
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
|
|
@ -1,38 +1,23 @@
|
||||||
/*******************************************************************************
|
|
||||||
* * 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;
|
package com.impetus.kundera;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import com.datastax.driver.core.querybuilder.Select;
|
||||||
import javax.persistence.Persistence;
|
import com.impetus.client.cassandra.common.CassandraConstants;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.impetus.kundera.entities.Person;
|
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.
|
* The Class CRUDTest.
|
||||||
*/
|
*/
|
||||||
public class CRUDTest
|
public class CRUDTest
|
||||||
{
|
{
|
||||||
|
private Log log = LogFactory.getLog(getClass().getName());
|
||||||
|
|
||||||
/** The Constant PU. */
|
/** The Constant PU. */
|
||||||
private static final String PU = "cassandra_pu";
|
private static final String PU = "cassandra_pu";
|
||||||
|
@ -52,7 +37,11 @@ public class CRUDTest
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void SetUpBeforeClass() throws Exception
|
public static void SetUpBeforeClass() throws Exception
|
||||||
{
|
{
|
||||||
emf = Persistence.createEntityManagerFactory(PU);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,6 +67,11 @@ public class CRUDTest
|
||||||
{
|
{
|
||||||
testInsert();
|
testInsert();
|
||||||
testMerge();
|
testMerge();
|
||||||
|
testUpdate();
|
||||||
|
testCache();
|
||||||
|
testTransaction();
|
||||||
|
testBatch();
|
||||||
|
testQueryBuilder();
|
||||||
testRemove();
|
testRemove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,13 +88,14 @@ public class CRUDTest
|
||||||
p.setPersonFirstName("James");
|
p.setPersonFirstName("James");
|
||||||
p.setPersonLastName("Bond");
|
p.setPersonLastName("Bond");
|
||||||
p.setAge(24);
|
p.setAge(24);
|
||||||
|
//p.addEmail("007@mi6.gov");
|
||||||
em.persist(p);
|
em.persist(p);
|
||||||
|
em.flush();
|
||||||
|
|
||||||
Person person = em.find(Person.class, "101");
|
Person person = em.find(Person.class, "101");
|
||||||
Assert.assertNotNull(person);
|
Assert.assertNotNull(person);
|
||||||
Assert.assertEquals("101", person.getPersonId());
|
Assert.assertEquals("101", person.getPersonId());
|
||||||
Assert.assertEquals("James Bond", person.getPersonName());
|
Assert.assertEquals("James Bond", person.getPersonName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,12 +104,80 @@ public class CRUDTest
|
||||||
private void testMerge()
|
private void testMerge()
|
||||||
{
|
{
|
||||||
Person person = em.find(Person.class, "101");
|
Person person = em.find(Person.class, "101");
|
||||||
person.setPersonFirstName("Bill");
|
person.setPersonLastName("Blond");
|
||||||
person.setPersonLastName("Clinton");
|
//person.addEmail("jamesbond@gmail.com");
|
||||||
em.merge(person);
|
person = em.merge(person);
|
||||||
|
em.flush();
|
||||||
|
|
||||||
Person p1 = em.find(Person.class, "101");
|
Person p2 = em.find(Person.class, "101");
|
||||||
Assert.assertEquals("Bill Clinton", p1.getPersonName());
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue