Search

Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

OrientDB: Java API

The following example show how to use OrientDB Java API to work with local Document Database.
Take a look to database types.

Document Database  offers a good compromise between speed and flexibility.




We show how to
  • Connect to a database and open it
  • Create a document (record) and populate fields
  • Persist the document (record) created
  • Close database


public class OrientDBTest {
   public static void main(String[] args) {
      //Connect to database
      ODatabaseDocumentTx db = new ODatabaseDocumentTx("local:/tmp/db/scratchpad");
      //Open database with user and password
      db.open("admin", "admin");
      //Create a new document (record)
      ODocument doc = db.newInstance();
      //Populate the fields
      doc.field("name", "Jay");
      doc.field("surname", "Miner");
      //Persist data
      doc.save();
      //Close database
      db.close();
   }
}

Run jar with options

Run jar
java -jar myJar.jar

Run with JVM memory options
java -Xmx300m -Xms300m -myJar.jar

Run with JVM options for remote jconsole monitoring (java 1.6)
java -Dcom.sun.management.
jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8082 -jar myJar.jar
 
-Xmx300m set maximum heam size to 300 MB (use "k" for KB)
-Xmx300m set starting heap size to 300 MB (use "k" for KB)
Note: in this example we disable authentication. Follow this link
http://docs.oracle.com/javase/6/docs/technotes/guides/management/agent.html#gdeup
to configure password and access files.
Note: in Ubuntu server we have to set the system's host name with machine ip
hostname [machineIp]

Full optional example
java -Xmx300m -Xms300m -Dcom.sun.management.
jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8082 -jar myTest.jar