This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

--Use your own objects at the server

Documents for the development of and with JVx.

--Use your own objects at the server

Postby Development@SIB » Wed Sep 15, 2010 6:09 pm



This article is outdated - please use our new system at

https://doc.sibvisions.com




Developers can integrate their own objects at the client as well as at the server. Here we will illustrate the use of objects that are integrated at the server and accessed by the client.

Any Java object/library/API can be used at the server. Compatibility to server´s JVM is a basic requirement. In addition, stateless calls should be supported. Although it would generally not be a problem to use stateful objects, the scalability of the application would be affected.

All server objects that are used by JVx in lifecycle objects support stateless calls.


Example

We want to develop an object that enables database logging and will use this object in our application.

The log object could be implemented as follows:

Code: Select all
/**
 * The <code>Logger</code> class is a simple log handler for databases.
 *
 * @author René Jahn
 */
public class Logger
{
   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   // Class members
   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   /** the log statement. */
   private PreparedStatement psLog;
   
   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   // Initialization
   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   /**
    * Creates a new instance of <code>Logger</code> for a specific database.
    *
    * @param pAccess the database access
    * @throws SQLException if the log statement could not be initialized
    */
   public Logger(DBAccess pAccess) throws SQLException
   {
      psLog = pAccess.getConnection().prepareStatement("");
   }
   
   /**
    * Logs an error message to the database.
    *
    * @param pMessage the error message
    * @throws SQLException if it's not possible to log an error message
    */
   public void error(String pMessage) throws SQLException
   {
      psLog.setString(1, pMessage);
   }
   
}   // Logger


The object is used in the Lifecycle object of our MasterSession:

Code: Select all
public class Session extends Application
{
   ...
   ...

   /**
    * Gets the database logger.
    *
    * @return the logger instance
    * @throws Exception if an exception occurs during log creation
    */
   public Logger getLogger() throws Exception
   {
      Logger log = (Logger)get("logger");
      
      if (log == null)
      {
         log = new Logger(getDBAccess());
         
         put("logger", log);
      }
      
      return log;
   }
}    // Session


Now we can make a log call in our application:

Code: Select all
getConnection().call("logger", "error", "This is an error message!");

This calls the error method of the logger object.
User avatar
Development@SIB
 
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation