Package org.h2gis.utilities
Class TableLocation
- java.lang.Object
-
- org.h2gis.utilities.TableLocation
-
public class TableLocation extends Object
Just a class used to split Catalog Schema and Table. Theses components are a unique table identifier.- Author:
- Nicolas Fortin
-
-
Field Summary
Fields Modifier and Type Field Description static StringQUOTE_CHARRecognized by H2 and Postgresstatic PatternQUOTE_PATTERN
-
Constructor Summary
Constructors Constructor Description TableLocation(String table)TableLocation(String schema, String table)TableLocation(String catalog, String schema, String table)TableLocation(String catalog, String schema, String table, DBTypes dbTypes)TableLocation(String schema, String table, DBTypes dbTypes)TableLocation(String table, DBTypes dbTypes)TableLocation(ResultSet rs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringcapsIdentifier(String identifier, DBTypes dbTypes)Change case of parameters to make it more user-friendly.booleanequals(Object o)static Stringformat(String identifier, DBTypes dbTypes)Format the identifier is necessary.StringgetCatalog()StringgetCatalog(String defaultValue)DBTypesgetDbTypes()Return the dbtype used by tablelocation.StringgetSchema()StringgetSchema(String defaultValue)StringgetTable()inthashCode()static TableLocationparse(String concatenatedTableLocation)Convert catalog.schema.table, schema.table or table into a TableLocation instance.static TableLocationparse(String concatenatedTableLocation, DBTypes dbTypes)Convert catalog.schema.table, schema.table or table into a TableLocation instance.static StringquoteIdentifier(String identifier)Always Quote string for both H2 and Postgre compatibilitystatic StringquoteIdentifier(String identifier, DBTypes dbTypes)Quote identifier only if necessary.voidsetDefaultSchema(String defaultSchema)static String[]split(String tableName)Convert catalog.schema.table, schema.table or table into a String array instance.StringtoString()StringtoString(DBTypes dbTypes)String representation of Table location, for insertion in SQL statement.static StringunFormat(String identifier, DBTypes dbTypes)
-
-
-
Field Detail
-
QUOTE_CHAR
public static final String QUOTE_CHAR
Recognized by H2 and Postgres- See Also:
- Constant Field Values
-
QUOTE_PATTERN
public static final Pattern QUOTE_PATTERN
-
-
Constructor Detail
-
TableLocation
public TableLocation(ResultSet rs) throws SQLException
- Parameters:
rs- result set obtained throughDatabaseMetaData.getTables(String, String, String, String[])- Throws:
SQLException
-
TableLocation
public TableLocation(String catalog, String schema, String table, DBTypes dbTypes)
- Parameters:
catalog- Catalog name without quotesschema- Schema name without quotestable- Table name without quotesdbTypes- The database type e.g : H2GIS, POSTGIS...
-
TableLocation
public TableLocation(String catalog, String schema, String table)
- Parameters:
catalog- Catalog name without quotesschema- Schema name without quotestable- Table name without quotes
-
TableLocation
public TableLocation(String schema, String table)
- Parameters:
schema- Schema name without quotestable- Table name without quotes
-
TableLocation
public TableLocation(String schema, String table, DBTypes dbTypes)
- Parameters:
schema- Schema name without quotestable- Table name without quotesdbTypes- The database type e.g : H2GIS, POSTGIS...
-
TableLocation
public TableLocation(String table, DBTypes dbTypes)
- Parameters:
table- Table name without quotesdbTypes- The database type e.g : H2GIS, POSTGIS...
-
TableLocation
public TableLocation(String table)
- Parameters:
table- Table name without quotes
-
-
Method Detail
-
quoteIdentifier
public static String quoteIdentifier(String identifier)
Always Quote string for both H2 and Postgre compatibility- Parameters:
identifier- Catalog,Schema,Table or Field name- Returns:
- Quoted Identifier
-
format
public static String format(String identifier, DBTypes dbTypes)
Format the identifier is necessary. Require database knowledge.- Parameters:
identifier- Catalog,Schema,Table or Field name.dbTypes- Type of the database.- Returns:
- Quoted identifier.
-
quoteIdentifier
public static String quoteIdentifier(String identifier, DBTypes dbTypes)
Quote identifier only if necessary. Require database knowledge.- Parameters:
identifier- Catalog,Schema,Table or Field name.dbTypes- Type of the database.- Returns:
- Quoted identifier.
-
toString
public String toString(DBTypes dbTypes)
String representation of Table location, for insertion in SQL statement. This function try to do not quote unnecessary components; require database type.- Parameters:
dbTypes- Database type.- Returns:
- String representation of Table location
-
getCatalog
public String getCatalog()
- Returns:
- Table catalog name (database)
-
getCatalog
public String getCatalog(String defaultValue)
- Parameters:
defaultValue- Return this value if this attribute is not defined.- Returns:
- Table catalog name (database)
-
parse
public static TableLocation parse(String concatenatedTableLocation)
Convert catalog.schema.table, schema.table or table into a TableLocation instance. Non-specified schema or catalogs are converted to the empty string.- Parameters:
concatenatedTableLocation- Table location [[Catalog.]Schema.]Table- Returns:
- Java beans for table location
-
split
public static String[] split(String tableName)
Convert catalog.schema.table, schema.table or table into a String array instance. Non-specified schema or catalogs are converted to the empty string.- Parameters:
tableName- in the form [[Catalog.]Schema.]Table- Returns:
- a String array with [0] = Catalog [1] = Schema [2] = Table
-
parse
public static TableLocation parse(String concatenatedTableLocation, DBTypes dbTypes)
Convert catalog.schema.table, schema.table or table into a TableLocation instance. Non-specified schema or catalogs are converted to the empty string.- Parameters:
concatenatedTableLocation- Table location [[Catalog.]Schema.]TabledbTypes- Database type.- Returns:
- Java beans for table location
-
capsIdentifier
public static String capsIdentifier(String identifier, DBTypes dbTypes)
Change case of parameters to make it more user-friendly.- Parameters:
identifier- Table, Catalog, Schema, or column namedbTypes- Database type.- Returns:
- Upper or lower case version of identifier
-
getSchema
public String getSchema()
- Returns:
- Table schema name
-
getSchema
public String getSchema(String defaultValue)
- Parameters:
defaultValue- Return this value if this attribute is not defined.- Returns:
- Table schema name
-
getTable
public String getTable()
- Returns:
- Table name
-
setDefaultSchema
public void setDefaultSchema(String defaultSchema)
- Parameters:
defaultSchema- Default connection schema, used for table location equality test.
-
getDbTypes
public DBTypes getDbTypes()
Return the dbtype used by tablelocation. Default is H2- Returns:
-
-