-
Notifications
You must be signed in to change notification settings - Fork 233
Kundera Data As Object
Are you a non-JPA developer but still wish to leverage the capabilities of Kundera? Kundera always tries to make things simple for users but under the shades of JPA where a user needs to have an understanding of EntityManagerFactory
, EntityManager
and many more JPA related things.
We have tried to make things simpler with Kundera - Data As Object. Using Data As Object lightweight API, user can perform JPA operations directly on objects rather than create traditional EntityManagerFactory
, EntityManager
.
Note: This is an experimental feature. We would love to hear from you, the valuable feedback.
Kundera Normal Approach :
User user = new User();
user.setUserId("0001");
user.setFirstName("John");
user.setLastName("Smith");
user.setCity("London");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra_pu");
EntityManager em = emf.createEntityManager();
em.persist(user);
em.close();
emf.close();
Data As Object Approach :
User user = new User();
user.setUserId("0001");
user.setFirstName("John");
user.setLastName("Smith");
user.setCity("London");
user.save();
To use it, user needs to add the following dependency in pom.xml
in addition to the client dependencies:
<dependency>
<groupId>com.impetus.kundera.client</groupId>
<artifactId>data-as-object</artifactId>
<version>${kundera.version}</version>
</dependency>
Rather than creating a META-INF/persistence.xml
user needs to add a JSON properties file in the classpath.
Example: client-properties.json
:
{
"com.impetus.kundera.dataasobject.entities.Employee,com.impetus.kundera.dataasobject.entities.Department": {
"kundera.nodes": "localhost",
"kundera.port": "9160",
"kundera.client": "cassandra",
"kundera.keyspace": "DAOTest",
"kundera.ddl.auto.prepare": "update",
"cql.version": "3.0.0",
"kundera.client.lookup.class": "com.impetus.client.cassandra.thrift.ThriftClientFactory"
}
}
POJO class needs to extends DefaultKunderaEntity<EntityName, IdDatatype>
. All the remaining things are same.
Usual Kundera Entity :
@Entity
public class User
{
@Id
private String userId;
@Column
private String firstName;
@Column
private String lastName;
@Column
private String city;
// Getters & Setters
}
Data As Object Entity :
@Entity
public class User extends DefaultKunderaEntity<User, String>
{
@Id
private String userId;
@Column
private String firstName;
@Column
private String lastName;
@Column
private String city;
// Getters & Setters
}
Before performing any operation on an object, User needs to use bind()
method.
User.bind("client-properties.json", User.class);
Internally it will create EntityManagerFactory
and EntityManager
instances.
After performing all operations, in the end, user needs to use unbind()
method
User.unbind();
Internally this will close instances of EntityManagerFactory
and EntityManager
.
User.bind("client-properties.json", User.class);
User user = new User();
user.setUserId("101");
user.setFirstName("John");
user.setLastName("Smith");
user.setCity("London");
// Save
user.save();
//Find
User u = new User().find(101);
u.setFirstName("Adam");
//Update
u.update();
//Delete
u.delete();
Refer Testcase for more Details.
JPA Query:
JPA queries can be done using query()
method. Example:
List<Book> results = new Book().query("select b from Book b where b.bookId=1");
Native Query:
Native queryies (e.g. CQL queries for cassandra) can be done using query()
method with QueryType.NATIVE
. Example:
List results = new Book().query("select \"TITLE\" from \"Book\"", QueryType.NATIVE);
Refer Testcase for more Details.
If a user is using Kundera only for one datastore i.e. all the entities are having the same configuration. Then, don't need to repeat the same config for all the entity classes. This config should be used:
{
"all": {
"kundera.nodes": "localhost",
"kundera.port": "9160",
"kundera.client": "cassandra",
"kundera.keyspace": "DAOTest",
"kundera.ddl.auto.prepare": "update",
"cql.version": "3.0.0",
"kundera.client.lookup.class": "com.impetus.client.cassandra.thrift.ThriftClientFactory"
}
}
Data As Object is in experimental phase. For polyglot, user needs to add persistence.xml
(same Kundera route). Check wiki for polyglot for more details.
Additionally in JSON properties file user needs to add kundera.pu
name as shown below:
{
"com.impetus.kundera.dataasobject.entities.User": {
"kundera.pu": "twirdbms"
},
"com.impetus.kundera.dataasobject.entities.Tweets": {
"kundera.pu": "twingo"
},
"com.impetus.kundera.dataasobject.entities.Video": {
"kundera.pu": "twissandra"
}
}
Refer Testcase for more Details.
- Working fine for simple entities. Not tested for embedded entities, entities having relations(e.g. one to many).
- Transactions are not supported.
- No way to clear entity manager level cache.
-
Datastores Supported
- Releases
-
Architecture
-
Concepts
-
Getting Started in 5 minutes
-
Features
- Object Mapper
- Polyglot Persistence
- Queries Support
- JPQL (JPA Query Language)
- Native Queries
- Batch insert update
- Schema Generation
- Primary Key Auto generation
- Transaction Management
- REST Based Access
- Geospatial Persistence and Queries
- Graph Database Support
-
Composite Keys
-
No hard annotation for schema
-
Support for Mapped superclass
-
Object to NoSQL Data Mapping
-
Cassandra's User Defined Types and Indexes on Collections
-
Support for aggregation
- Scalar Queries over Cassandra
- Connection pooling using Kundera Cassandra
- Configuration
-
Kundera with Couchdb
-
Kundera with Elasticsearch
-
Kundera with HBase
-
Kundera with Kudu
-
Kundera with RethinkDB
-
Kundera with MongoDB
-
Kundera with OracleNoSQL
-
Kundera with Redis
-
Kundera with Spark
-
Extend Kundera
- Sample Codes and Examples
-
Blogs and Articles
-
Tutorials
* Kundera with Openshift
* Kundera with Play Framework
* Kundera with GWT
* Kundera with JBoss
* Kundera with Spring
-
Performance
-
Troubleshooting
-
FAQ
- Production deployments
- Feedback