slib.sml.smutils
Class SQLiteUtils

java.lang.Object
  extended by slib.sml.smutils.SQLiteUtils

public class SQLiteUtils
extends Object

Class used to process large SME results files through SQLlite databases Processed file must respect the following restrictions: - tab separated format - containing a header (first non-empty line which do not start with ! ). Use ! to prefix comment lines - the first two columns are dedicated to the name of the entity compared (the name of the corresponding columns will be set to "entity_A" and "entity_B") - the other columns are considered as double (decimal) results. The class can be used to : - create an SQLite database from an input file containing SME result a table will be create for each input file - merge two tables into a new database table - delete a specific table - copy a table from an SQLlite database to another - get information from a specific database or table Limits Note that SQLite implementation to not allow SELECT queries on databases containing tables with more than 500 columns. If such big table are processed a SQL_Exception will be throw.

Author:
Harispe Sébastien

Field Summary
static int BATCH_LIMIT
           
static int BATCH_LIMIT_MATRIX_LINE
           
 
Constructor Summary
SQLiteUtils()
           
 
Method Summary
 void copyTable(String db, String table, String newDB, String tableNew)
          Copy a table.
 void createTableDB(String filepath, String db, String tableName)
          Create a SQLlite database from a tabular file.
 void dropColumns(String db, String table, Set<String> columnsToDrop)
          Drop specified columns from the table
 void dropTable(String db, String table)
          Drop a table from a database
 void flushTableInFile(String sqlLiteDB, String table, String outfile)
          Flush a table in a tabular file The first two columns are considered as literal, the others as Double values The number of tuples load into memory before flushing are governed by BATCH_LIMIT_MATRIX_LINE
 int getBATCH_LIMIT_MATRIX_LINE()
           
 int getBATCH_LIMIT()
           
 void getInfo(String db)
          Return info a specified database
 void getInfo(String db, String table)
          Return info a specified table
 void mergeTables(String db_tAB, String table_A, String table_B, String db_tmerge, String table_merge)
          Merge two tables of a same database into a new table located in another database.
 void mergeTables(String db_tA, String table_A, String db_tB, String table_B, String db_tmerge, String table_merge)
          Merge two tables into a new table.
 void renameTable(String db, String table, String newTableName)
          Rename a table in a database.
 void setBATCH_LIMIT_MATRIX_LINE(int bATCH_LIMIT_MATRIX_LINE)
          Mutator of the number of values stored by line.
 void setBATCH_LIMIT(int BATCH_LIMIT)
          Setter of the number of value stored in memory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BATCH_LIMIT

public static int BATCH_LIMIT

BATCH_LIMIT_MATRIX_LINE

public static int BATCH_LIMIT_MATRIX_LINE
Constructor Detail

SQLiteUtils

public SQLiteUtils()
Method Detail

createTableDB

public void createTableDB(String filepath,
                          String db,
                          String tableName)
                   throws slib.utils.ex.SLIB_Ex_Critic
Create a SQLlite database from a tabular file. The input file must respect the following restrictions: - tab separated format - the first two columns are dedicated to the name of the entity compared (the name of the corresponding columns will be set to "entity_A" and "entity_B") - the other columns are considered as double results. Warning: note that the table will be dropped of the database if it already exists The insertion are made through a PreparedStatement object. Batch execution is governed by globla BATCH_LIMIT

Parameters:
filepath - the tabular file containing the results
db - the name of the database to consider
tableName - the name of the table where to flush the results
Throws:
slib.utils.ex.SLIB_Ex_Critic

mergeTables

public void mergeTables(String db_tAB,
                        String table_A,
                        String table_B,
                        String db_tmerge,
                        String table_merge)
                 throws slib.utils.ex.SLIB_Exception
Merge two tables of a same database into a new table located in another database. Only tuples of the two tables who share entity_A and entity_B values will be conserved in the merged table. Note that the first table is considered as reference which implied that duplicate columns between the two tables will always take the value specified in the reference table.

Parameters:
db_tAB - database of the tables to merge
table_A - first table name
table_B - second table name
db_tmerge - database in which the merge table will be created (different from db_tAB)
table_merge - the name of the new table
Throws:
slib.utils.ex.SLIB_Exception

mergeTables

public void mergeTables(String db_tA,
                        String table_A,
                        String db_tB,
                        String table_B,
                        String db_tmerge,
                        String table_merge)
                 throws slib.utils.ex.SLIB_Ex_Critic
Merge two tables into a new table. Only tuples of the two tables who share entity_A and entity_B values will be conserved in the merged table. Note that the first table is considered as reference which implied that duplicate columns between the two tables will always take the value specified in the reference table.

Parameters:
db_tA - database of the first table to merge
table_A - first table name
db_tB - database of the second table to merge
table_B - second table name
db_tmerge - database in which the merge table will be created
table_merge - the name of the new table
Throws:
slib.utils.ex.SLIB_Ex_Critic

flushTableInFile

public void flushTableInFile(String sqlLiteDB,
                             String table,
                             String outfile)
                      throws slib.utils.ex.SLIB_Ex_Critic
Flush a table in a tabular file The first two columns are considered as literal, the others as Double values The number of tuples load into memory before flushing are governed by BATCH_LIMIT_MATRIX_LINE

Parameters:
sqlLiteDB - the database containing the table to consider
table - the name of the table
outfile - the file in which the table will be flush
Throws:
slib.utils.ex.SLIB_Ex_Critic

copyTable

public void copyTable(String db,
                      String table,
                      String newDB,
                      String tableNew)
               throws slib.utils.ex.SLIB_Ex_Critic
Copy a table. If the destination database do not exits it will be created if the already exists in the new database it will be dropped

Parameters:
db - the database containing the table to copy
table - the name of the table
newDB - the name of the database where the new table will be created
tableNew -
Throws:
slib.utils.ex.SLIB_Ex_Critic

dropColumns

public void dropColumns(String db,
                        String table,
                        Set<String> columnsToDrop)
                 throws slib.utils.ex.SLIB_Ex_Critic
Drop specified columns from the table

Parameters:
db - the database containing the table to process
table - the table to process
columnsToDrop - a list of strings corresponding to the columns to delete SQLlite do not support ALTER column, a temporal copy of the table is performed during the process
Throws:
slib.utils.ex.SLIB_Ex_Critic

dropTable

public void dropTable(String db,
                      String table)
               throws slib.utils.ex.SLIB_Ex_Critic
Drop a table from a database

Parameters:
db - the database
table - the name of table to drop
Throws:
slib.utils.ex.SLIB_Ex_Critic

getInfo

public void getInfo(String db)
             throws slib.utils.ex.SLIB_Ex_Critic
Return info a specified database

Parameters:
db - the database
Throws:
slib.utils.ex.SLIB_Ex_Critic

getInfo

public void getInfo(String db,
                    String table)
             throws slib.utils.ex.SLIB_Ex_Critic
Return info a specified table

Parameters:
db - the database
table - the table
Throws:
slib.utils.ex.SLIB_Ex_Critic

renameTable

public void renameTable(String db,
                        String table,
                        String newTableName)
                 throws slib.utils.ex.SLIB_Ex_Critic
Rename a table in a database. Throw an exception if the table name already exists

Parameters:
db -
table -
newTableName -
Throws:
slib.utils.ex.SLIB_Ex_Critic

getBATCH_LIMIT

public int getBATCH_LIMIT()
Returns:
the value associated to the batch limit, the number of value stored in memory.

setBATCH_LIMIT

public void setBATCH_LIMIT(int BATCH_LIMIT)
Setter of the number of value stored in memory.

Parameters:
BATCH_LIMIT -

getBATCH_LIMIT_MATRIX_LINE

public int getBATCH_LIMIT_MATRIX_LINE()
Returns:
the number of values stored by line.

setBATCH_LIMIT_MATRIX_LINE

public void setBATCH_LIMIT_MATRIX_LINE(int bATCH_LIMIT_MATRIX_LINE)
Mutator of the number of values stored by line.

Parameters:
bATCH_LIMIT_MATRIX_LINE -


Copyright © 2013. All Rights Reserved.