Datastore Developers Guide
Working with DataStore from custom Java clients
previous :: contents :: next

Back to > Overview > Developers Guide

Working with DataStore from custom Java clients

Authors:
Szabo Csaba <crow@nolimits.ro>
Antal Attila <atech@nolimits.ro>
Table of Contents
1. Foreword
2. Libraries what you need
3. Step.1. - Import the packages
4. Step.2. - Setting variables
5. Step.3. - Creating the SEP command
6. Step.4. - Loading the driver
7. Step.5. - Creating and closing the connection
8. Step.6. - Execute SEP and receive the response


1. Foreword

The following description shows you how you can write a Java client program for connect a DataStore database using the DataStore self-driver for connection. This program is an example for store data into DataStore, using authentication and secure connection.

top

2. Libraries what you need

To write DataStore client programs you need the following libraries:

top

3. Step.1. - Import the packages


  
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader; 

import org.media.datastore.sepengine.driver.beepDriver.*;
import org.media.datastore.sepengine.driver.*;

public class Store {
    public static void main( String[] argv ) {

    }
}

      
top

4. Step.2. - Setting variables

On the first the connection con will be null. The url variable is a path for a connection, where the localhost is a hostname, the 10288 is the port number, XMLDB the symbolic name of the database. The security you don't need to use, only if you want a secure connection. The default user is guest and the password is guest

  
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader; 

import org.media.datastore.sepengine.driver.beepDriver.*;
import org.media.datastore.sepengine.driver.*;

public class Store {

    static SepStoreConnection con = null;
    static String url = "sep:beep://localhost:10288/XMLDB;security=jsse";
    static String user = "guest";
    static String passwd = "guest";

    public static void main( String[] argv ) {


    }
}

      
top

5. Step.3. - Creating the SEP command

The SEP command will be stored into the string, named sep. This command will store a small block person into the database, into the subtree named test.

import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader; 

import org.media.datastore.sepengine.driver.beepDriver.*;
import org.media.datastore.sepengine.driver.*;

public class Store {

    static SepStoreConnection con = null;
    static String url = "sep:beep://localhost:10288/XMLDB;security=jsse";
    static String user = "guest";
    static String passwd = "guest";

    static String sep = "<store action='write'>"+
	"<block name='test'>" +
	"<person>\n"+
	"   <name first='Antal' last='Attila'/>\n"+ 
	"   <occupation>developer</occupation>\n"+ 
	"   <email>atech@nolimits.ro</email>\n"+ 
	"</person>"+
	"</block>" +
	"</store>\n";
    
    public static void main( String[] argv ) {

    }
}
      
top

6. Step.4. - Loading the driver

import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader; 

import org.media.datastore.sepengine.driver.beepDriver.*;
import org.media.datastore.sepengine.driver.*;

public class Store {

    static SepStoreConnection con = null;
    static String url = "sep:beep://localhost:10288/XMLDB;security=jsse";
    static String user = "guest";
    static String passwd = "guest";

    static String sep = "<store action='write'>"+
	"<block name='test'>" +
	"<person>\n"+
	"   <name first='Antal' last='Attila'/>\n"+ 
	"   <occupation>developer</occupation>\n"+ 
	"   <email>atech@nolimits.ro</email>\n"+ 
	"</person>"+
	"</block>" +
	"</store>\n";
    
    public static void main( String[] argv ) {
	try {
	    
	    System.setProperty( "sep.drivers",
                "org.media.datastore.sepengine.driver.beepDriver.BeepDriver");

	}
	catch ( Exception e ) {
	    System.err.println( "Error: " + e.getMessage() ); 
	}
    }
}
      
top

7. Step.5. - Creating and closing the connection

import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader; 

import org.media.datastore.sepengine.driver.beepDriver.*;
import org.media.datastore.sepengine.driver.*;

public class Store {

    static SepStoreConnection con = null;
    static String url = "sep:beep://localhost:10288/XMLDB;security=jsse";
    static String user = "guest";
    static String passwd = "guest";

    static String sep = "<store action='write'>"+
	"<block name='test'>" +
	"<person>\n"+
	"   <name first='Antal' last='Attila'/>\n"+ 
	"   <occupation>developer</occupation>\n"+ 
	"   <email>atech@nolimits.ro</email>\n"+ 
	"</person>"+
	"</block>" +
	"</store>\n";
    
    public static void main( String[] argv ) {
	try {
	    System.setProperty( "sep.drivers",
                "org.media.datastore.sepengine.driver.beepDriver.BeepDriver");

	    con = SepStoreDriverManager.getConnection(url, user, passwd);

	    con.close();

	}
	catch ( Exception e ) {
	    System.err.println( "Error: " + e.getMessage() ); 
	}
    }
}
      
top

8. Step.6. - Execute SEP and receive the response

import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader; 

import org.media.datastore.sepengine.driver.beepDriver.*;
import org.media.datastore.sepengine.driver.*;

public class Store {

    static SepStoreConnection con = null;
    static String url = "sep:beep://localhost:10288/XMLDB;security=jsse";
    static String user = "guest";
    static String passwd = "guest";

    static String sep = "<store action='write'>"+
	"<block name='test'>" +
	"<person>\n"+
	"   <name first='Antal' last='Attila'/>\n"+ 
	"   <occupation>developer</occupation>\n"+ 
	"   <email>atech@nolimits.ro</email>\n"+ 
	"</person>"+
	"</block>" +
	"</store>\n";
    
    public static void main( String[] argv ) {
	try {
	    System.setProperty( "sep.drivers",
                "org.media.datastore.sepengine.driver.beepDriver.BeepDriver");

	    con = SepStoreDriverManager.getConnection(url, user, passwd);

	    InputStreamReader response = new InputStreamReader(con.executeSEP(sep));
	    BufferedReader reader = new BufferedReader( response );
	    String line = null;
	    while ( ( line = reader.readLine() ) != null )
	        System.out.println(line);

	    con.close();
	}
	catch ( Exception e ) {
	    System.err.println( "Error: " + e.getMessage() ); 
	}
    }
}
      
top


© 2001