Class SQLTranslator
- Object
-
- SQLTranslator
-
public class SQLTranslator extends Object implements Function<String,String>
Converts the SQL statements from MS-Access dialect to standard SQL. Theapply(String)method is invoked when a newPreparedStatementis about to be created from a SQL string. Since the EPSG dataset is available primarily in MS-Access format, the original SQL statements are formatted using a dialect specific to that particular database software. If the actual EPSG dataset to query is hosted on another database product, then the SQL query needs to be adapted to the target database dialect before to be executed.Example SQL statements for an EPSG dataset hosted on the PostgreSQL database need to have their brackets (In addition to the file in MS-Access format, EPSG also provides the dataset as SQL files for PostgreSQL, MySQL and Oracle databases. Those SQL files are used as both Data Description Language (DDL) and Data Manipulation Language (DML). But the table names and some column names in those scripts differ from the ones used in the MS-Access database. The following table summarizes the name changes:'['and']') replaced by the quote character ('"') before to be sent to the database driver. Furthermore table names may be different. So the following MS-Access query:SELECT * FROM [Coordinate Reference System]
SELECT * FROM "Coordinate Reference System"SELECT * FROM epsg_coordinatereferencesystem(in the default schema)SELECT * FROM epsg.coordinatereferencesystem(in the"epsg"schema)SELECT * FROM epsg."Coordinate Reference System"
By default this class auto-detects the schema that contains the EPSG tables and whether the table names are the ones used by EPSG in the MS-Access version or the PostgreSQL, MySQL or Oracle version of the database. Consequently it is legal to use the MS-Access table names, which are more readable, in a PostgreSQL database.Table and column names Element Name in MS-Access database Name in SQL scripts Table Aliasepsg_aliasTable Areaepsg_areaTable Coordinate Axisepsg_coordinateaxisTable Coordinate Axis Nameepsg_coordinateaxisnameTable Coordinate_Operationepsg_coordoperationTable Coordinate_Operation Methodepsg_coordoperationmethodTable Coordinate_Operation Parameterepsg_coordoperationparamTable Coordinate_Operation Parameter Usageepsg_coordoperationparamusageTable Coordinate_Operation Parameter Valueepsg_coordoperationparamvalueTable Coordinate_Operation Pathepsg_coordoperationpathTable Coordinate Reference Systemepsg_coordinatereferencesystemTable Coordinate Systemepsg_coordinatesystemTable Datumepsg_datumTable Ellipsoidepsg_ellipsoidTable Naming Systemepsg_namingsystemTable Prime Meridianepsg_primemeridianTable Supersessionepsg_supersessionTable Unit of Measureepsg_unitofmeasureColumn ORDERcoord_axis_orderThread safetyAllSQLTranslatorinstances given to theEPSGFactoryconstructor shall be immutable and thread-safe.- Since:
- 0.7
Defined in the
sis-referencingmodule
-
-
Constructor Summary
Constructors Constructor Description SQLTranslator(DatabaseMetaData md, String catalog, String schema)Creates a new SQL translator for the database described by the given metadata.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringapply(String sql)Adapts the given SQL statement from the original MS-Access dialect to the dialect of the target database.StringgetCatalog()Returns the catalog that contains the EPSG schema.StringgetSchema()Returns the schema that contains the EPSG tables.
-
-
-
Constructor Detail
-
SQLTranslator
public SQLTranslator(DatabaseMetaData md, String catalog, String schema) throws SQLException
Creates a new SQL translator for the database described by the given metadata. This constructor detects automatically the dialect: the characters to use for quoting identifiers, and whether the table names are the ones used in the MS-Access database or in the SQL scripts.If the given catalog or schema name is non-null, then the search for EPSG tables will be restricted to the catalog or schema of that name. An empty string (
"") means to search for tables without catalog or schema. Anullvalue means that the catalog or schema should not be used to narrow the search.- Parameters:
md- information about the database.catalog- the catalog where to look for EPSG schema, ornullif any.schema- the schema where to look for EPSG tables, ornullif any.- Throws:
SQLException- if an error occurred while querying the database metadata.
-
-
Method Detail
-
getCatalog
public String getCatalog()
Returns the catalog that contains the EPSG schema. This is the catalog specified at construction time if it was non-null, or the catalog discovered by the constructor otherwise. Note that this method may still returnnullif the EPSG tables were not found or if the database does not supports catalogs.- Returns:
- the catalog that contains the EPSG schema, or
null.
-
getSchema
public String getSchema()
Returns the schema that contains the EPSG tables. This is the schema specified at construction time if it was non-null, or the schema discovered by the constructor otherwise. Note that this method may still returnnullif the EPSG tables were not found or if the database does not supports schemas.- Returns:
- the schema that contains the EPSG tables, or
null.
-
-