-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Apollo is an ORM (Object Relational Mapping) tool for Cassandra. Apollo is high-level Cassandra client API which bridges the gap among no-sql (or denormalised data), agile development in java and interfacing with Cassandra database. Because we believe that having "no-sql" (or having denormalised information) and interfacing with Cassandra does not mean having to write more codes. Apollo is able to simplify from simple mainstream to advanced application activities when it comes to reading and writing to Cassandra database as well as add more features which Cassanddra is not able to offer.
Apollo can free you tremendous amount of code clutter as well as classes specific to any high-level Cassandra API.
In just a few lines of codes, Apollo will allow you to get up to speed and running building Cassandra powered applications.
Ex:
/* -- Start of Configuration (apollo.conf) -- */
cluster.host = 192.168.65.221:9160
cluster.name = Test Cluster
keyspace = TestKeySpace
cluster.maxActive = 20
cluster.maxIdle = 10
cluster.cassandraThriftSocketTimeout = 3000
cluster.maxWaitTimeWhenExhausted = 4000
cassandra.cluster.keyspace.build_columnfamily_structures = true
/* -- Start of Configuration (apollo.conf) -- */
/* -- Start of Code -- */
Properties conf = new Properties();
conf.load(ClassLoader.getSystemResourceAsStream("apollo.conf"));
Configurator configrator = new Configurator(conf);
configurator.addClassConfiguration("com/mydomin/app/MyBean.hbm.xml");
configurator.addClassConfiguration("com/mydomin/app/MyBean2.hbm.xml");
SessionFactory factory = configurator.configure();
Session session = factory.openSession();
MyBean myBean = session.find(MyBean.class, "myBeanId");
if (myBean == null) {
myBean = new MyBean();
myBean.setId("myBeanId");
myBean.setText("Hello Apollo!");
MyBean2 bean2 = new MyBean2();
bean2.id = "this is bean 2 id";
bean2.anotherProperty = "hello!";
myBean.bean2 = bean2; // note that in the mapping below, null bean2 value will cause an exception to be thrown
session.save(myBean);
}
System.out.println("myBean: " + myBean);
session.close();
factory.shutdown();
/* -- End of Code -- */
/* -- Start of Code -- */
class MyBean {
private String id;
private String text;
private MyBean2 bean2;
public void setId(String id) { this.id = id; }
public String getId() { return id; }
public void setText(String text) { this.text = text; }
public String getText() { return text; }
public MyBean2 getBean2() { return bean2; }
public void setBean2(MyBean2 bean2) { this.bean2 = bean2; }
}
class MyBean2 {
private String id;
private String anotherProperty;
public void setId(String id) { this.id = id; }
public String getId() { return id; }
public void setAnotherProperty(String anotherProperty) { this.anotherProperty = anotherProperty; }
public String getAnotherProperty() { return anotherProperty; }
}
/* -- End of Code -- */
/* -- Start of Mapping (MyBean.hbm.xml) -- */
<?xml version="1.0"?>
<hibernate-mapping>
<class name="com.mydomin.app.MyBean" table="MyBean">
<id name="id" unsaved-value="null" >
<column name="id" not-null="true"/>
<generator class="native"/>
</id>
<property name="text" />
<property name="bean2" cascade-save="true" not-null="true" />
</class>
</hibernate-mapping>
/* -- End of Mapping (MyBean.hbm.xml) -- */
/* -- Start of Mapping (MyBean2.hbm.xml) -- */
<?xml version="1.0"?>
<hibernate-mapping>
<class name="com.mydomin.app.MyBean2" table="MyBean2">
<id name="id" unsaved-value="null" >
<column name="id" not-null="true"/>
<generator class="native"/>
</id>
<property name="anotherProperty" />
</class>
</hibernate-mapping>
/* -- End of Mapping (MyBean2.hbm.xml) -- */
If you have prior experience with Hibernate framework, nothing of the above should be stranger. As a matter of fact, in order to really get you started quickly, as in really really quickly, Apollo can take your existing hibernate mapping files without any changes at all! (note that the current API may not have covered all the permutations and combinations of Hibernate configuration per se).