com.tekann.codegen.pda.db
Class DBHandler

java.lang.Object
  extended by com.tekann.codegen.pda.db.DBHandler
All Implemented Interfaces:
IConnector

public class DBHandler
extends java.lang.Object
implements IConnector

Handler for tables on PDA.
This class can be used to execute a script such as the script created on the DB to PDA data exchanging that is located in: ...\MyProject\pdafiles\bin\DBToPDAScript.txt

You can use your own script if you want since it is in the same format.

Author:
Guilherme Frantz

Field Summary
static boolean CLOSE_CONNECTION
           
static java.lang.String DEFAULT_QUOTES
           
static java.lang.String FIREBIRD
           
static java.lang.String MYSQL
           
static java.lang.String ORACLE_TNSNAMES
           
static java.lang.String ORACLE10G
           
static java.lang.String pdaDBFileName
          Property file name.
static java.lang.String POSTGRESQL
           
static java.lang.String SQL_SERVER
           
 
Method Summary
 void backupAllTables(java.lang.String applicationID)
           
 void closeConnection(java.lang.String applicationID)
          Close a LitebaseConnection according to the passed applicationID
 void closeConnection(java.lang.String applicationID, boolean force)
           
 void dropAllTables(java.lang.String applicationID)
          Deletes physically all the tables by the DROP TABLE clause.
 boolean executeScript(byte[] fileContent, java.lang.String applicationID)
          Executes the SQL script from the given byte array.
 int executeScript(totalcross.io.ByteArrayStream bas, java.lang.String applicationID)
          Executes the SQL script by the given ByteArrayStream.
 int executeScript(totalcross.io.Stream file, java.lang.String applicationID)
          Executes the SQL script.
 boolean executeScript(java.lang.String fileName, java.lang.String applicationID)
          Executes the SQL script.
 litebase.LitebaseConnection getConnection(java.lang.String applicationID)
          Gets the connection.
static DBHandler getInstance()
          Gets the instance
 IDAO getTable(java.lang.String pdaTableName)
          Gets the table DAO.
 Properties getTableMaps()
          Get the table maps
 IDAO newTable(java.lang.String tableName)
          Creates a new IDAO for the given tableName.
 void recoverTable(IDAO dao)
          Try to recover the passed table.
 boolean removeTable(java.lang.String pdaTableName)
          Remove the table from the tables hash.
 litebase.LitebaseConnection setConnection(java.lang.String applicationID)
           
 void setPath(java.lang.String path)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pdaDBFileName

public static java.lang.String pdaDBFileName
Property file name. This file contains class mappings to load forms.


POSTGRESQL

public static final java.lang.String POSTGRESQL
See Also:
Constant Field Values

MYSQL

public static final java.lang.String MYSQL
See Also:
Constant Field Values

SQL_SERVER

public static final java.lang.String SQL_SERVER
See Also:
Constant Field Values

ORACLE10G

public static final java.lang.String ORACLE10G
See Also:
Constant Field Values

ORACLE_TNSNAMES

public static final java.lang.String ORACLE_TNSNAMES
See Also:
Constant Field Values

FIREBIRD

public static final java.lang.String FIREBIRD
See Also:
Constant Field Values

DEFAULT_QUOTES

public static java.lang.String DEFAULT_QUOTES

CLOSE_CONNECTION

public static boolean CLOSE_CONNECTION
Method Detail

getInstance

public static DBHandler getInstance()
Gets the instance

Returns:
The DBHandler instance

setPath

public void setPath(java.lang.String path)

executeScript

public boolean executeScript(byte[] fileContent,
                             java.lang.String applicationID)
Executes the SQL script from the given byte array. The file must have one SQL command per line:
DELETE table1
DELETE table2
INSERT INTO table1(cod, name) values (1, 'John')

Parameters:
fileContent -
applicationID -
Returns:
true if everything is ok.

executeScript

public int executeScript(totalcross.io.Stream file,
                         java.lang.String applicationID)
                  throws java.lang.Exception
Executes the SQL script.
The file must have one SQL command per line:
DELETE table1
DELETE table2
INSERT INTO table1(cod, name) values (1, 'John')

Parameters:
file -
applicationID -
Returns:
The number of rows affected
Throws:
totalcross.io.IOException
java.lang.Exception

executeScript

public boolean executeScript(java.lang.String fileName,
                             java.lang.String applicationID)
Executes the SQL script. The file must have one SQL command per line:
DELETE table1
DELETE table2
INSERT INTO table1(cod, name) values (1, 'John')

Parameters:
fileName -
applicationID -
Returns:
A boolean

executeScript

public int executeScript(totalcross.io.ByteArrayStream bas,
                         java.lang.String applicationID)
Executes the SQL script by the given ByteArrayStream.

Parameters:
bas -
applicationID -
Returns:

getConnection

public litebase.LitebaseConnection getConnection(java.lang.String applicationID)
Gets the connection.

Specified by:
getConnection in interface IConnector
Parameters:
applicationID -
Returns:
A LitebaseConnection

closeConnection

public void closeConnection(java.lang.String applicationID)
Close a LitebaseConnection according to the passed applicationID

Specified by:
closeConnection in interface IConnector
Parameters:
applicationID -

closeConnection

public void closeConnection(java.lang.String applicationID,
                            boolean force)

setConnection

public litebase.LitebaseConnection setConnection(java.lang.String applicationID)

dropAllTables

public void dropAllTables(java.lang.String applicationID)
Deletes physically all the tables by the DROP TABLE clause.

Parameters:
applicationID -

backupAllTables

public void backupAllTables(java.lang.String applicationID)
                     throws totalcross.io.IllegalArgumentIOException,
                            totalcross.io.IOException
Throws:
totalcross.io.IllegalArgumentIOException
totalcross.io.IOException

getTable

public IDAO getTable(java.lang.String pdaTableName)
Gets the table DAO.
You can use this method to get an instance of your generated IDAO, by default, in the user.dao package. If the instance wasn't created yet then the instance will be created.

Parameters:
pdaTableName -
Returns:
An IDAO for the passed pdaTableName

removeTable

public boolean removeTable(java.lang.String pdaTableName)
Remove the table from the tables hash.

Parameters:
pdaTableName - The table name.
Returns:
True if the table was removed, otherwise false.

newTable

public IDAO newTable(java.lang.String tableName)
              throws java.lang.Exception
Creates a new IDAO for the given tableName.

Parameters:
tableName -
Returns:
An IDAO for the passed tableName
Throws:
java.lang.Exception

getTableMaps

public Properties getTableMaps()
Get the table maps

Returns:
A Properties tableMaps

recoverTable

public void recoverTable(IDAO dao)
Try to recover the passed table.

Parameters:
daos -