org.h2gis.utilities
Class JDBCUtilities

java.lang.Object
  extended by org.h2gis.utilities.JDBCUtilities

public class JDBCUtilities
extends Object

DBMS should follow standard but it is not always the case, this class do some common operations. Compatible with H2 and PostgreSQL.

Author:
Nicolas Fortin, Erwan Bocher, Adam Gouge

Nested Class Summary
static class JDBCUtilities.FUNCTION_TYPE
           
 
Field Summary
static String H2_DRIVER_NAME
           
 
Method Summary
static PropertyChangeListener attachCancelResultSet(Statement st, ProgressVisitor progressVisitor)
           
static int getFieldIndex(ResultSetMetaData resultSetMetaData, String fieldName)
          Fetch the metadata, and check field name
static String getFieldName(DatabaseMetaData meta, String table, int fieldIndex)
           
static int getIntegerPrimaryKey(Connection connection, String tableReference)
           
static int getRowCount(Connection connection, String tableReference)
          Fetch the row count of a table.
static boolean hasField(Connection connection, String tableName, String fieldName)
          Return true if table tableName contains field fieldName.
static boolean isH2DataBase(DatabaseMetaData metaData)
           
static boolean isTemporaryTable(Connection connection, String tableReference)
          Read INFORMATION_SCHEMA.TABLES in order to see if the provided table reference is a temporary table.
static boolean tableExists(Connection connection, String tableName)
          Return true if the table exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

H2_DRIVER_NAME

public static final String H2_DRIVER_NAME
See Also:
Constant Field Values
Method Detail

hasField

public static boolean hasField(Connection connection,
                               String tableName,
                               String fieldName)
                        throws SQLException
Return true if table tableName contains field fieldName.

Parameters:
connection - Connection
tableName - Table name
fieldName - Field name
Returns:
True if the table contains the field
Throws:
SQLException

getFieldIndex

public static int getFieldIndex(ResultSetMetaData resultSetMetaData,
                                String fieldName)
                         throws SQLException
Fetch the metadata, and check field name

Parameters:
resultSetMetaData - Active result set meta data.
fieldName - Field name, ignore case
Returns:
The field index [1-n]; -1 if the field is not found
Throws:
SQLException

getFieldName

public static String getFieldName(DatabaseMetaData meta,
                                  String table,
                                  int fieldIndex)
                           throws SQLException
Parameters:
meta - DataBase meta data
table - Table identifier [[catalog.]schema.]table
fieldIndex - Field ordinal position [1-n]
Returns:
The field name, empty if the field position or table is not found
Throws:
SQLException - If jdbc throws an error

getRowCount

public static int getRowCount(Connection connection,
                              String tableReference)
                       throws SQLException
Fetch the row count of a table.

Parameters:
connection - Active connection.
tableReference - Table reference
Returns:
Row count
Throws:
SQLException - If the table does not exists, or sql request fail.

isTemporaryTable

public static boolean isTemporaryTable(Connection connection,
                                       String tableReference)
                                throws SQLException
Read INFORMATION_SCHEMA.TABLES in order to see if the provided table reference is a temporary table.

Parameters:
connection - Active connection not closed by this method
tableReference - Table reference
Returns:
True if the provided table is temporary.
Throws:
SQLException - If the table does not exists.

isH2DataBase

public static boolean isH2DataBase(DatabaseMetaData metaData)
                            throws SQLException
Parameters:
metaData - Database meta data
Returns:
True if the provided metadata is a h2 database connection.
Throws:
SQLException

getIntegerPrimaryKey

public static int getIntegerPrimaryKey(Connection connection,
                                       String tableReference)
                                throws SQLException
Parameters:
connection - Connection
tableReference - table identifier
Returns:
The integer primary key used for edition[1-n]; 0 if the source is closed or if the table has no primary key or more than one column as primary key
Throws:
SQLException

tableExists

public static boolean tableExists(Connection connection,
                                  String tableName)
                           throws SQLException
Return true if the table exists.

Parameters:
connection - Connection
tableName - Table name
Returns:
true if the table exists
Throws:
SQLException

attachCancelResultSet

public static PropertyChangeListener attachCancelResultSet(Statement st,
                                                           ProgressVisitor progressVisitor)
Parameters:
st - Statement to cancel
progressVisitor - Progress to link with
Returns:
call ProgressVisitor.removePropertyChangeListener(java.beans.PropertyChangeListener) with this object as argument


Copyright © 2015 IRSTV CNRS-FR-2488. All Rights Reserved.