de.fuberlin.wiwiss.d2rq.sql
Class ConnectedDB

java.lang.Object
  extended by de.fuberlin.wiwiss.d2rq.sql.ConnectedDB

public class ConnectedDB
extends Object

TODO Move all engine-specific code from here to Vendor and its implementations

Author:
Richard Cyganiak (richard@cyganiak.de), kurtjx (http://github.com/kurtjx)

Field Summary
static int DEFAULT_KEEP_ALIVE_INTERVAL
           
static String DEFAULT_KEEP_ALIVE_QUERY
           
static String KEEP_ALIVE_PROPERTY
           
static String KEEP_ALIVE_QUERY_PROPERTY
           
 
Constructor Summary
ConnectedDB(String jdbcURL, String username, String password)
           
ConnectedDB(String jdbcURL, String username, String password, Map<String,DataType.GenericType> columnTypes, int limit, int fetchSize, Properties connectionProperties)
           
 
Method Summary
 boolean areCompatibleFormats(Attribute column1, Attribute column2)
          Checks if two columns are formatted by the database in a compatible fashion.
 void close()
          Closes the database connection and shuts down the keep alive agent.
 DataType columnType(Attribute column)
          Returns a column's datatype.
 Connection connection()
           
 boolean equals(Object otherObject)
           
 int fetchSize()
           
protected  String getDatabaseProductType()
           
 String getJdbcURL()
           
 String getPassword()
           
 Map<String,List<String>> getUniqueKeyColumns(RelationName tableName)
           
 String getUsername()
           
static String guessJDBCDriverClass(String jdbcURL)
          Tries to guess the class name of a suitable JDBC driver from a JDBC URL.
 int hashCode()
           
 boolean isNullable(Attribute column)
           
 int limit()
           
 boolean lowerCaseTableNames()
          In some situations, MySQL stores table names using lowercase only, and then performs case-insensitive comparison.
static void registerJDBCDriver(String driverClassName)
          Registers a JDBC driver class.
static void registerJDBCDriverIfPresent(String driverClassName)
          Pre-registers a JDBC driver if its class can be found on the classpath.
 DatabaseSchemaInspector schemaInspector()
           
 void setDefaultFetchSize(int value)
           
 Vendor vendor()
           
 boolean vendorIs(Vendor vendor)
          Reports the brand of RDBMS.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEEP_ALIVE_PROPERTY

public static final String KEEP_ALIVE_PROPERTY
See Also:
Constant Field Values

DEFAULT_KEEP_ALIVE_INTERVAL

public static final int DEFAULT_KEEP_ALIVE_INTERVAL
See Also:
Constant Field Values

KEEP_ALIVE_QUERY_PROPERTY

public static final String KEEP_ALIVE_QUERY_PROPERTY
See Also:
Constant Field Values

DEFAULT_KEEP_ALIVE_QUERY

public static final String DEFAULT_KEEP_ALIVE_QUERY
See Also:
Constant Field Values
Constructor Detail

ConnectedDB

public ConnectedDB(String jdbcURL,
                   String username,
                   String password)

ConnectedDB

public ConnectedDB(String jdbcURL,
                   String username,
                   String password,
                   Map<String,DataType.GenericType> columnTypes,
                   int limit,
                   int fetchSize,
                   Properties connectionProperties)
Method Detail

getJdbcURL

public String getJdbcURL()

getUsername

public String getUsername()

getPassword

public String getPassword()

connection

public Connection connection()

limit

public int limit()

setDefaultFetchSize

public void setDefaultFetchSize(int value)

fetchSize

public int fetchSize()

schemaInspector

public DatabaseSchemaInspector schemaInspector()

columnType

public DataType columnType(Attribute column)
Returns a column's datatype. Caches the types for performance.

Parameters:
column -
Returns:
The column's datatype, or null if unknown

isNullable

public boolean isNullable(Attribute column)

vendorIs

public boolean vendorIs(Vendor vendor)
Reports the brand of RDBMS.

Returns:
true if this database is of the given brand
See Also:
TODO make private, use {@link #vendor()} and its methods instead

vendor

public Vendor vendor()
Returns:
A helper for generating SQL statements conforming to the syntax of the database engine used in this connection

getDatabaseProductType

protected String getDatabaseProductType()
                                 throws SQLException
Throws:
SQLException

areCompatibleFormats

public boolean areCompatibleFormats(Attribute column1,
                                    Attribute column2)

Checks if two columns are formatted by the database in a compatible fashion.

Assuming v1 is a value from column1, and v2 a value from column2, and v1 = v2 evaluates to true within the database, then we call the values have compatible formatting if SELECTing them results in character-for-character identical strings. As an example, a TINYINT and a BIGINT are compatible because equal values will be formatted in the same way when SELECTed, e.g. 1 = 1. But if one of them is ZEROFILL, then SELECTing will result in a different character string, e.g. 1 = 0000000001. The two columns wouldn't be compatible.

This is used by the engine when removing unnecessary joins. If two columns have compatible formatting, then we can sometimes use one in place of the other when they are known to have equal values. But not if they are incompatible, because e.g. http://example.org/id/1 is different from http://example.org/id/0000000001.

Returns:
true if both arguments have compatible formatting

getUniqueKeyColumns

public Map<String,List<String>> getUniqueKeyColumns(RelationName tableName)

lowerCaseTableNames

public boolean lowerCaseTableNames()
In some situations, MySQL stores table names using lowercase only, and then performs case-insensitive comparison. We need to account for this when comparing table names reported by MySQL and those from the mapping.

See Also:
MySQL Manual, Identifier Case Sensitivity

close

public void close()
Closes the database connection and shuts down the keep alive agent.


equals

public boolean equals(Object otherObject)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

registerJDBCDriverIfPresent

public static void registerJDBCDriverIfPresent(String driverClassName)
Pre-registers a JDBC driver if its class can be found on the classpath. If the class is not found, nothing will happen.

Parameters:
driverClassName - Fully qualified class name of a JDBC driver

guessJDBCDriverClass

public static String guessJDBCDriverClass(String jdbcURL)
Tries to guess the class name of a suitable JDBC driver from a JDBC URL. This only works in the unlikely case that the driver has been registered earlier using Class.forName(classname).

Parameters:
jdbcURL - A JDBC URL
Returns:
The corresponding JDBC driver class name, or null if not known

registerJDBCDriver

public static void registerJDBCDriver(String driverClassName)
Registers a JDBC driver class.

Parameters:
driverClassName - Fully qualified class name of a JDBC driver
Throws:
D2RQException - If the class could not be found