Tutorials
   
 

The basic use of Chronus.

Once the chronus.jar has been included in your classpath you are able to use it the same as you would any other map-implementing class. Chronus functions like a persistant hashtable!.

Our first look at Chronus involves us saving a simple string to the database and recalling it.

Here is the code:

//This comes in at the beginning of your source file
Import chronus.*;

//And this goes into your method
Chronus db = new Chronus();
db.put("Key", "This is a test"); //First the key, then the parameter.
System.out.println(db.get("Key"));

The first thing we did is create a Chronus instance, calling up the constructor without any arguments informs chronus that the global database (stored in the /Database folder and called chronus) is used. Next we inserted a key-value pair into the database, the key is the identifier for the object, and the value is the actual data. The key is then given as a parameter in get("Key") in order to load the object.

This is all fine and dandy, but what if I need to store a custom object?

All custom objects stored in Chronus have to implement the Serializable interface, this does not actually involve writing any complex methods, or any code at all for that matter, but it is neccesary to tell Chronus that the object can be broken down into binary data.

So the declaration of a custom object will look a little like this:

class customObject implements java.io.Serializable {
//Fields
//Constructors/Methods
}

The saving and loading of the custom object is exactly the same as in the previous section.

That concludes the basic usage tutorial for chronus, now go have some fun with your newly aquired knowledge!

Back