fr.dyade.aaa.util
Class MySqlDBRepository

java.lang.Object
  extended by fr.dyade.aaa.util.MySqlDBRepository
All Implemented Interfaces:
Repository

final class MySqlDBRepository
extends java.lang.Object
implements Repository

This class allows to use a MySQL database as repository with the NTransaction module.

The basic setup at the code to get Database code to run is the same. The additional thing when using MySQL database is:

  1. For the a3servers.xml that will be copy to run directory, we have to add these:
       <property name="Transaction" value="fr.dyade.aaa.util.NTransaction"/>
       <property name="NTRepositoryImpl" value="fr.dyade.aaa.util.MySqlDBRepository"/>
       <property name="DBDriver" value="org.gjt.mm.mysql.Driver"/>
       <property name="ConnURL" value="jdbc:mysql://hostname:3306/instance"/>
       <property name="DBUser" value="dbUserName"/>
       <property name="DBPass" value="dbPassword"/>
     
  2. In the start script in the bin directory:
    1. We have to add the following library
       CLASSPATH=$CLASSPATH:$VIATOR_LIB/mysql-connector-java-5.0.5-bin.jar
       CLASSPATH=$CLASSPATH:$VIATOR_LIB/commons-dbcp-1.2.1.jar
       CLASSPATH=$CLASSPATH:$VIATOR_LIB/commons-pool-1.3.jar
       
    2. change the java command to add in a few -D parameter
       JAVA_ARGS=$JAVA_ARGS"
       -DNTRepositoryImpl=fr.dyade.aaa.util.MySqlDBRepository
       -DDBDriver=org.gjt.mm.mysql.Driver
       -DConnURL=jdbc:mysql://hostname:3306/instance
       -DDBUser=dbUserName
       -DDBPass=dbPassword"
       
    3. may need to up size the max memory for better performace This is what we use: JAVA_ARGS=" -Xms100M -Xmx1024M "
  3. At the MySQL database side:
    1. we have to set the max-allowed-packet to a bigger size, I think the default is 1M, if the number of messages become large, it will fail. "max_allowed_packet=16M"
    2. create the JoramDB table first (we decided that we will create it outside here instead of in the code.
       CREATE TABLE JoramDB (name VARCHAR(256), content longblob, primary key(name));
       

    See Also:
    NTransaction, Repository

    Field Summary
    private  int baddeleted
               
    (package private)  java.sql.Connection conn
               
    (package private)  java.lang.String connurl
               
    (package private)  java.sql.PreparedStatement deleteStmt
               
    (package private)  java.io.File dir
               
    (package private)  java.lang.String driver
               
    (package private)  org.apache.commons.dbcp.BasicDataSource ds
               
    (package private)  java.sql.PreparedStatement insertStmt
               
    static org.objectweb.util.monolog.api.Logger logger
               
    private  int nbdeleted
               
    private  int nbloaded
               
    private  int nbsaved
               
    (package private)  java.lang.String pass
               
    (package private)  boolean reconnectLoop
               
    (package private)  java.sql.PreparedStatement updateStmt
               
    (package private)  java.lang.String user
               
     
    Constructor Summary
    MySqlDBRepository()
               
     
    Method Summary
     void close()
              Closes the repository.
    private  void closeConnection()
               
     void commit()
              Commits all changes to the repository.
     void delete(java.lang.String dirName, java.lang.String name)
              Deletes the corresponding objects in repository.
    private  java.sql.Connection getConnection()
               
     int getNbBadDeletedObjects()
              Returns the number of useless delete operation on repository.
     int getNbDeletedObjects()
              Returns the number of delete operation on repository.
     int getNbLoadedObjects()
              Returns the number of load operation from repository.
     int getNbSavedObjects()
              Returns the number of save operation to repository.
     void init(java.io.File dir)
              Initializes the repository.
     java.lang.String[] list(java.lang.String prefix)
              Gets a list of persistent objects that name corresponds to prefix.
     byte[] load(java.lang.String dirName, java.lang.String name)
              Loads the byte array.
     java.lang.Object loadobj(java.lang.String dirName, java.lang.String name)
              Loads the object.
    private  void reconnection()
               
     void save(java.lang.String dirName, java.lang.String name, byte[] content)
              Save the corresponding bytes array.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    driver

    java.lang.String driver

    connurl

    java.lang.String connurl

    user

    java.lang.String user

    pass

    java.lang.String pass

    ds

    org.apache.commons.dbcp.BasicDataSource ds

    reconnectLoop

    boolean reconnectLoop

    logger

    public static org.objectweb.util.monolog.api.Logger logger

    dir

    java.io.File dir

    nbsaved

    private int nbsaved

    nbdeleted

    private int nbdeleted

    baddeleted

    private int baddeleted

    nbloaded

    private int nbloaded

    conn

    java.sql.Connection conn

    insertStmt

    java.sql.PreparedStatement insertStmt

    updateStmt

    java.sql.PreparedStatement updateStmt

    deleteStmt

    java.sql.PreparedStatement deleteStmt
    Constructor Detail

    MySqlDBRepository

    MySqlDBRepository()
    Method Detail

    getNbSavedObjects

    public int getNbSavedObjects()
    Returns the number of save operation to repository.

    Specified by:
    getNbSavedObjects in interface Repository
    Returns:
    The number of save operation to repository.

    getNbDeletedObjects

    public int getNbDeletedObjects()
    Returns the number of delete operation on repository.

    Specified by:
    getNbDeletedObjects in interface Repository
    Returns:
    The number of delete operation on repository.

    getNbBadDeletedObjects

    public int getNbBadDeletedObjects()
    Returns the number of useless delete operation on repository.

    Specified by:
    getNbBadDeletedObjects in interface Repository
    Returns:
    The number of useless delete operation on repository.

    getNbLoadedObjects

    public int getNbLoadedObjects()
    Returns the number of load operation from repository.

    Specified by:
    getNbLoadedObjects in interface Repository
    Returns:
    The number of load operation from repository.

    init

    public void init(java.io.File dir)
              throws java.io.IOException
    Initializes the repository. Opens the connection, evntually creates the database and tables.

    Specified by:
    init in interface Repository
    Throws:
    java.io.IOException

    list

    public java.lang.String[] list(java.lang.String prefix)
                            throws java.io.IOException
    Gets a list of persistent objects that name corresponds to prefix.

    Specified by:
    list in interface Repository
    Returns:
    The list of corresponding names.
    Throws:
    java.io.IOException

    save

    public void save(java.lang.String dirName,
                     java.lang.String name,
                     byte[] content)
              throws java.io.IOException
    Save the corresponding bytes array.

    Specified by:
    save in interface Repository
    Throws:
    java.io.IOException

    loadobj

    public java.lang.Object loadobj(java.lang.String dirName,
                                    java.lang.String name)
                             throws java.io.IOException,
                                    java.lang.ClassNotFoundException
    Loads the object.

    Returns:
    The loaded object or null if it does not exist.
    Throws:
    java.lang.ClassNotFoundException
    java.io.IOException

    load

    public byte[] load(java.lang.String dirName,
                       java.lang.String name)
                throws java.io.IOException
    Loads the byte array.

    Specified by:
    load in interface Repository
    Returns:
    The loaded bytes array.
    Throws:
    java.io.IOException

    delete

    public void delete(java.lang.String dirName,
                       java.lang.String name)
                throws java.io.IOException
    Deletes the corresponding objects in repository.

    Specified by:
    delete in interface Repository
    Throws:
    java.io.IOException

    commit

    public void commit()
                throws java.io.IOException
    Commits all changes to the repository.

    Specified by:
    commit in interface Repository
    Throws:
    java.io.IOException

    close

    public void close()
               throws java.io.IOException
    Closes the repository.

    Specified by:
    close in interface Repository
    Throws:
    java.io.IOException

    getConnection

    private java.sql.Connection getConnection()
                                       throws java.sql.SQLException
    Throws:
    java.sql.SQLException

    closeConnection

    private void closeConnection()

    reconnection

    private void reconnection()
                       throws java.io.IOException
    Throws:
    java.io.IOException


    Copyright © 2010 ScalAgent D.T.. All Rights Reserved.