com.nmt.mgp
Class ConnHandler

java.lang.Object
  extended by com.nmt.mgp.ConnHandler

public class ConnHandler
extends java.lang.Object

Manage a connection to an EMG server.

Connection parameters are taken from the Settings class, using the following parameters.


Constructor Summary
ConnHandler(java.lang.String theHost, java.lang.String theUser, java.lang.String thePassword, int thePort, boolean withSsl)
          Normal constructor.
 
Method Summary
 java.sql.ResultSet dbexec(java.lang.String profile, java.lang.String sql)
          Sends an SQL string to the server, to be executed by the given database profile.
 OptionHolder execute(int operation, OptionHolder options)
           
 int getAdminFlags()
           
 java.lang.String getClientConfig()
          Returns the MGP option client_config.
 java.lang.String getHost()
           
 OptionHolder getLoginOptions()
          Gets the MGP options from the current MgpSession.
 java.lang.String getPassword()
           
 int getPort()
           
 java.lang.String getRemoteIp()
          Returns the MGP option remoteip.
 java.lang.String getUser()
           
 boolean havePermission(int mask, boolean all)
          Checks the permission of the currently logged in user.
 void init(java.lang.String str)
          Sets the systemtype to be sent to the server.
 boolean isAdmin()
          Returns true if and only if the current user has full administration rights.
 boolean isSsl()
           
 void readOperation(OptionHolder oph)
          Deprecated. Use MgpSessionI.execute(int, com.nmt.mgp.OptionHolder) instead.
 int sendMess(Message msg)
          Send an MGP Message to the server.
 void sendOperation(int operand, OptionHolder oph)
          Sends an operation with parameters to the server.
 void sendOperation(int operand, OptionHolder oph, boolean doFlush)
          Deprecated. Use MgpSessionI.execute(int, com.nmt.mgp.OptionHolder) instead.
 void sessionInvalidate()
          Close the connection to the server.
 void setEmgDebug(boolean inBool)
          Sets the debug level for the MgpSession, if any.
 boolean test()
          Fetches the connection parameters from Setting, and calls test(String,int,String,String,boolean).
 boolean test(java.lang.String host, int port, java.lang.String user, java.lang.String pwd, boolean ssl)
          Close the current session, and reconnect.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnHandler

public ConnHandler(java.lang.String theHost,
                   java.lang.String theUser,
                   java.lang.String thePassword,
                   int thePort,
                   boolean withSsl)
Normal constructor.

Method Detail

init

public void init(java.lang.String str)
Sets the systemtype to be sent to the server.

Parameters:
str - the systemtype

sessionInvalidate

public void sessionInvalidate()
Close the connection to the server.


getLoginOptions

public OptionHolder getLoginOptions()
Gets the MGP options from the current MgpSession.


isAdmin

public boolean isAdmin()
                throws MgpException
Returns true if and only if the current user has full administration rights. A connection to the server is made if necessary.

Throws:
MgpException - If a connection can't be made.

getAdminFlags

public int getAdminFlags()
                  throws MgpException
Throws:
MgpException

getClientConfig

public java.lang.String getClientConfig()
                                 throws MgpException
Returns the MGP option client_config. A connection to the server is made if necessary.

Throws:
MgpException - If a connection can't be made.

getRemoteIp

public java.lang.String getRemoteIp()
                             throws MgpException
Returns the MGP option remoteip. A connection to the server is made if necessary.

Throws:
MgpException - If a connection can't be made.

sendOperation

public void sendOperation(int operand,
                          OptionHolder oph)
                   throws MgpException
Sends an operation with parameters to the server. A connection to the server is made if necessary.

Parameters:
operand - the operation number
oph - the parameters
Throws:
MgpException - If a connection can't be made.

sendOperation

public void sendOperation(int operand,
                          OptionHolder oph,
                          boolean doFlush)
                   throws MgpException
Deprecated. Use MgpSessionI.execute(int, com.nmt.mgp.OptionHolder) instead.

Sends an operation with parameters to the server. A connection to the server is made if necessary.

Parameters:
operand - the operation number
oph - the parameters
doFlush - if the data should be flushed
Throws:
MgpException - If a connection can't be made.

readOperation

public void readOperation(OptionHolder oph)
                   throws MgpException
Deprecated. Use MgpSessionI.execute(int, com.nmt.mgp.OptionHolder) instead.

Reads the reply from the EMG server from the previous operation. If readOperation() is called before sendOperation(), the application will hang waiting for the non-existent reply.

Parameters:
oph - the container to store the replies in
Throws:
MgpException - the connection fails

sendMess

public int sendMess(Message msg)
             throws MgpException
Send an MGP Message to the server. If an MgpException is caught, the connection is closed, reopened, and a second attempt is made. No third attempt is made.

Parameters:
msg - the message to send
Returns:
the message id returned from the server
Throws:
MgpException - if anything is wrong with the message or the connection can't be established.

dbexec

public java.sql.ResultSet dbexec(java.lang.String profile,
                                 java.lang.String sql)
                          throws MgpException
Sends an SQL string to the server, to be executed by the given database profile. The connection to the server is restored if necessary.

Parameters:
profile - the database profile name
sql - the sql string
Returns:
the ResultSet read by the server
Throws:
MgpException - if the connection failes, or there is something wrong with the sql statement

execute

public OptionHolder execute(int operation,
                            OptionHolder options)
                     throws MgpException
Throws:
MgpException

havePermission

public boolean havePermission(int mask,
                              boolean all)
                       throws MgpException
Checks the permission of the currently logged in user. The connection to the server is restored if necessary.

Parameters:
mask - the bitmask of permissions
all - if all bits must match
Returns:
true if and only if the user has all the required permissions
Throws:
MgpException - if the connection failes

test

public boolean test()
             throws MgpException,
                    java.io.IOException,
                    java.lang.Exception
Fetches the connection parameters from Setting, and calls test(String,int,String,String,boolean).

Throws:
MgpException
java.io.IOException
java.lang.Exception

test

public boolean test(java.lang.String host,
                    int port,
                    java.lang.String user,
                    java.lang.String pwd,
                    boolean ssl)
             throws MgpException
Close the current session, and reconnect.

Throws:
MgpException

setEmgDebug

public void setEmgDebug(boolean inBool)
Sets the debug level for the MgpSession, if any.


getHost

public final java.lang.String getHost()

getPassword

public final java.lang.String getPassword()

getPort

public final int getPort()

isSsl

public final boolean isSsl()

getUser

public final java.lang.String getUser()