Initial import.

This commit is contained in:
Greg Burd 2017-06-19 15:46:56 -04:00
commit e722450677
5 changed files with 387 additions and 0 deletions

23
.gitignore vendored Normal file
View file

@ -0,0 +1,23 @@
target
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

43
pom.xml Normal file
View file

@ -0,0 +1,43 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.impetus.kundera</groupId>
<artifactId>kundera-cassandra-example</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>kundera-cassandra-example</name>
<url>http://maven.apache.org</url>
<properties>
<kundera.version>3.6</kundera.version>
</properties>
<dependencies>
<dependency>
<groupId>com.impetus.kundera.client</groupId>
<artifactId>kundera-cassandra</artifactId>
<version>${kundera.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,142 @@
/*******************************************************************************
* * 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.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* The Class Person.
*/
@Entity
@Table(name = "PERSON")
public class Person
{
/** The person id. */
@Id
@Column(name = "PERSON_ID")
private String personId;
/** The person first name. */
@Column(name = "PERSON_FIRST_NAME")
private String personFirstName;
/** The person last name. */
@Column(name = "PERSON_LAST_NAME")
private String personLastName;
/** The age. */
@Column(name = "AGE")
private int age;
/**
* Gets the person id.
*
* @return the person id
*/
public String getPersonId()
{
return personId;
}
/**
* Sets the person id.
*
* @param personId
* the new person id
*/
public void setPersonId(String personId)
{
this.personId = personId;
}
/**
* Gets the person name.
*
* @return the person name
*/
public String getPersonName()
{
return personFirstName + " " + personLastName;
}
/**
* Gets the person first name.
*
* @return the person first name
*/
public String getPersonFirstName()
{
return personFirstName;
}
/**
* Sets the person first name.
*
* @param personFirstName
* the new person first name
*/
public void setPersonFirstName(String personFirstName)
{
this.personFirstName = personFirstName;
}
/**
* Gets the person last name.
*
* @return the person last name
*/
public String getPersonLastName()
{
return personLastName;
}
/**
* Sets the person last name.
*
* @param personLastName
* the new person last name
*/
public void setPersonLastName(String personLastName)
{
this.personLastName = personLastName;
}
/**
* Gets the age.
*
* @return the age
*/
public int getAge()
{
return age;
}
/**
* Sets the age.
*
* @param age
* the new age
*/
public void setAge(int age)
{
this.age = age;
}
}

View file

@ -0,0 +1,20 @@
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
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">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="9160" />
<property name="kundera.keyspace" value="KunderaExamples" />
<property name="kundera.dialect" value="cassandra" />
<property name="kundera.ddl.auto.prepare" value="update" />
<property name="kundera.client.lookup.class"
value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />
</properties>
</persistence-unit>
</persistence>

View file

@ -0,0 +1,159 @@
/*******************************************************************************
* * 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;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
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;
/**
* The Class CRUDTest.
*/
public class CRUDTest
{
/** 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
{
emf = Persistence.createEntityManagerFactory(PU);
}
/**
* 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();
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);
em.persist(p);
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.setPersonFirstName("Bill");
person.setPersonLastName("Clinton");
em.merge(person);
Person p1 = em.find(Person.class, "101");
Assert.assertEquals("Bill Clinton", p1.getPersonName());
}
/**
* 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;
}
}
}