Package oracle.spatial.util
Class Util
- java.lang.Object
-
- oracle.spatial.util.Util
-
public class Util extends java.lang.Objectsome useful utility routines used by SDOVIS. These are not clearly documented so use at your own risk!! This is internal.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUtil.CheckType
-
Field Summary
Fields Modifier and Type Field Description protected static java.sql.Connectionm_conn
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcenter(java.awt.Component c)Centers an awt component w.r.t.static java.sql.BlobchangePcBlockPtIds(java.sql.Blob originalBlob, int numDims, int newBlkId, int newPtIdStartCounter)static java.lang.StringcheckSQLName(java.lang.String string, int maxStringLength)Checks for any illegal characters in a SQL name.static java.lang.StringcheckSQLName(java.lang.String string, int maxStringLength, Util.CheckType checkType)Checks: - for any illegal characters in a SQL name.static java.sql.Connectionconnect(java.lang.String host, java.lang.String sid, java.lang.String port, java.lang.String user, java.lang.String passwd, java.lang.String mode, int rowPref)Establishes an Oracle JDBC connection to the specified database.static double[]convert(java.lang.String str)Converts a string of coordinates into a double array.static java.lang.StringenquoteColumnName(java.sql.Connection conn, java.lang.String columnName)Enquotes a column name.static java.lang.StringenquoteNameSQLName(java.lang.String name)Returns the ENQUOTE_NAME formatted String for the SQL name If the Oracle JDBC is present, use the new OracleStatement.enquoteIdentifier API in the JDK8 JDBC.static java.lang.StringenquoteNameSQLName(java.lang.String name, boolean capitalize)Returns the ENQUOTE_NAME formatted String for the SQL name.static java.lang.StringenquoteNameSQLName(java.sql.Connection conn, java.lang.String name)Returns the ENQUOTE_NAME formatted String for the SQL name If the Oracle JDBC is present, use the new OracleStatement.enquoteIdentifier API in the JDK8 JDBC.static java.lang.StringenquoteNameSQLName(java.sql.Connection conn, java.lang.String name, boolean capitalize)Returns the ENQUOTE_NAME formatted String for the SQL name.static java.lang.StringenquoteTableName(java.sql.Connection conn, java.lang.String tableName)Enquotes a table name with or without schema name which is separated by ".".static java.lang.StringgetConnStr(java.lang.String mode, java.lang.String host, java.lang.String port, java.lang.String sid)connects to the database using supplied information.static java.lang.StringgetDBVersion(java.sql.Connection conn)Gets the version of the database connected.static java.lang.StringgetJDBCDriverVersion(java.sql.Connection conn)Gets the oracle JDBC driver version string.static java.awt.ShapegetShape(double[] coords, boolean close)converts the coordinate array into a GeneralPath shape.static booleanisGeodetic(int srid)Using an Oracle convention to determin if a srid is geodetic.static booleanisPre9i(java.sql.Connection conn)Determin if a database is pre-9i version.static voidmain(java.lang.String[] args)static java.awt.geom.Rectangle2D.Doublembr(double[] coords)static java.lang.StringqualifiedSQLName(java.sql.Connection conn, java.lang.String name)Checks if the specified name is a qualified SQL name.static byte[]readFile(java.lang.String f)static java.util.ArrayListsplitBy(java.lang.String str, java.lang.String delim)gets an array list of strings that are separated by delimiters such as commas
-
-
-
Method Detail
-
convert
public static double[] convert(java.lang.String str)
Converts a string of coordinates into a double array. The delimiter between the numbers can be white space, comma, semicolon, or CR.
-
splitBy
public static java.util.ArrayList splitBy(java.lang.String str, java.lang.String delim)gets an array list of strings that are separated by delimiters such as commas- Parameters:
str- the input string to be tokenizeddelim- the delimiter to be used in tokenizing the string- Returns:
- ArrayList of all the tokens
-
getShape
public static java.awt.Shape getShape(double[] coords, boolean close)converts the coordinate array into a GeneralPath shape.
-
mbr
public static java.awt.geom.Rectangle2D.Double mbr(double[] coords)
-
readFile
public static byte[] readFile(java.lang.String f) throws java.io.IOException- Throws:
java.io.IOException
-
connect
public static java.sql.Connection connect(java.lang.String host, java.lang.String sid, java.lang.String port, java.lang.String user, java.lang.String passwd, java.lang.String mode, int rowPref)Establishes an Oracle JDBC connection to the specified database. If a OCI mode connection is requested but failed, then a "thin" JDBC connection is automatically attempted.- Parameters:
host- name of the host machine where the database runssid- instance id of the databaseport- which port the database is listening atuser- the database user to connect topasswd- the database user's passwordmode- the connection mode; possible values are "thin", "oci" or "oci8". If null value is supplied the default "oci8" mode is attempted.rowPref- the row prefetch to be set with the connection. If a value less than or equal to zero is supplied, the defualt value of 32 will be used for this connection.- Returns:
- an Oracle JDBC connection if successful, otherwise null.
-
getJDBCDriverVersion
public static java.lang.String getJDBCDriverVersion(java.sql.Connection conn)
Gets the oracle JDBC driver version string.
-
getDBVersion
public static java.lang.String getDBVersion(java.sql.Connection conn)
Gets the version of the database connected.
-
isPre9i
public static boolean isPre9i(java.sql.Connection conn)
Determin if a database is pre-9i version. This is internal.
-
isGeodetic
public static boolean isGeodetic(int srid)
Using an Oracle convention to determin if a srid is geodetic. This is internal.
-
getConnStr
public static java.lang.String getConnStr(java.lang.String mode, java.lang.String host, java.lang.String port, java.lang.String sid)connects to the database using supplied information. If any one of the following parameters are null, then the connection will be made to a (default) local database instance.
If user requires OCI-mode connection but failed, then a "Thin" mode connection is automatically attempted.mode,host,port,sid- Parameters:
mode- the mode of connection. It could either be a THIN or an OCI connection. THIN is slower but pure java, while OCI is faster but requires Oracle OCI library.host- the host where the database is located.port- the port where the database instance listens (default is 1521)sid- the instance id of the database.- Returns:
- a JDBC connection to specified Oracle Database. This is internal.
-
center
public static void center(java.awt.Component c)
Centers an awt component w.r.t. the screen.
-
main
public static void main(java.lang.String[] args) throws java.io.IOException, java.lang.Exception, java.sql.SQLException- Throws:
java.io.IOExceptionjava.lang.Exceptionjava.sql.SQLException
-
checkSQLName
public static java.lang.String checkSQLName(java.lang.String string, int maxStringLength) throws java.sql.SQLExceptionChecks for any illegal characters in a SQL name. Only alpha-numeric characters and ".", "_","$","#" are allowed.- Parameters:
string- input stringmaxStringLength- maximum length for input string- Returns:
- string Retruns the string if passes the check
- Throws:
java.sql.SQLException- An exception is thrown if the input string contains any illegal characters or exceeds the maximum length
-
checkSQLName
public static java.lang.String checkSQLName(java.lang.String string, int maxStringLength, Util.CheckType checkType) throws java.sql.SQLExceptionChecks: - for any illegal characters in a SQL name. Only alpha-numeric characters and ".", "_","$","#" are allowed. - for any illegal characters in a SQL Column Data Type name. Only alpha-numeric characters and ".", "_","$","#","(",")","-",":"," " are allowed; but "--" not allowed. - for any illegal characters in a URL. Rules are from java.net.URL.- Parameters:
string- input stringmaxStringLength- maximum length for input stringcheckType- sqlName, URL or SQLType- Returns:
- string Retruns the string if passes the check
- Throws:
java.sql.SQLException- An exception is thrown if the input string contains any illegal characters or exceeds the maximum length
-
qualifiedSQLName
public static java.lang.String qualifiedSQLName(java.sql.Connection conn, java.lang.String name) throws java.sql.SQLExceptionChecks if the specified name is a qualified SQL name. It calls SYS.DBMS_ASSERT.qualified_sql_name function.- Parameters:
conn- the database connectionname- the input name- Returns:
- string Retruns the string if passes the check
- Throws:
java.sql.SQLException- A SQLexception is thrown if the dbms_assert.qualified_sql_name failed
-
enquoteNameSQLName
public static java.lang.String enquoteNameSQLName(java.sql.Connection conn, java.lang.String name) throws java.sql.SQLExceptionReturns the ENQUOTE_NAME formatted String for the SQL name If the Oracle JDBC is present, use the new OracleStatement.enquoteIdentifier API in the JDK8 JDBC. Otherwise, regex-based logic is used to check for a valid SQL name and do the enquoting. The input name is capitalized before being enquoted. This method is added due to avoid SQL Injection issues. Note: the Connection argument is not used, but this signature is kept for backward compatibility with the previous version.- Parameters:
conn- the database connectionname- the input name- Throws:
java.sql.SQLException
-
enquoteNameSQLName
public static java.lang.String enquoteNameSQLName(java.lang.String name) throws java.sql.SQLExceptionReturns the ENQUOTE_NAME formatted String for the SQL name If the Oracle JDBC is present, use the new OracleStatement.enquoteIdentifier API in the JDK8 JDBC. Otherwise, regex-based logic is used to check for a valid SQL name and do the enquoting. The input name is capitalized before being enquoted. This method is added to avoid SQL Injection issues.- Parameters:
name- the input name- Throws:
java.sql.SQLException
-
enquoteNameSQLName
public static java.lang.String enquoteNameSQLName(java.sql.Connection conn, java.lang.String name, boolean capitalize) throws java.sql.SQLExceptionReturns the ENQUOTE_NAME formatted String for the SQL name. Regex-based logic is used to check for a valid SQL name and do the enquoting. This method is added due to avoid SQL Injection issues. Note: the Connection argument is not used, but this signature is kept for backward compatibility with the previous version.- Parameters:
conn- the database connectionname- the input namecapitalize- If TRUE, alphabetic characters of str which was not in quotes are translated to upper case- Throws:
java.sql.SQLException
-
enquoteNameSQLName
public static java.lang.String enquoteNameSQLName(java.lang.String name, boolean capitalize) throws java.sql.SQLExceptionReturns the ENQUOTE_NAME formatted String for the SQL name. Regex-based logic is used to check for a valid SQL name and do the enquoting. This method is added due to avoid SQL Injection issues.- Parameters:
name- the input namecapitalize- If TRUE, alphabetic characters of str which was not in quotes are translated to upper case- Throws:
java.sql.SQLException
-
enquoteTableName
public static java.lang.String enquoteTableName(java.sql.Connection conn, java.lang.String tableName) throws java.sql.SQLExceptionEnquotes a table name with or without schema name which is separated by ".". This method also can be used to enquote all column names, including object column names like col.attr1.attr2.attr3 == "COL"."ATTR1"."ATTR2"."ATTR3" and "col".attr1."attr2".attr3 == "col"."ATTR1"."attr2"."ATTR3"- Parameters:
conn-tableName-- Returns:
- String
- Throws:
java.sql.SQLException
-
enquoteColumnName
public static java.lang.String enquoteColumnName(java.sql.Connection conn, java.lang.String columnName) throws java.sql.SQLExceptionEnquotes a column name.- Parameters:
conn-columnName-- Returns:
- String
- Throws:
java.sql.SQLException
-
changePcBlockPtIds
public static java.sql.Blob changePcBlockPtIds(java.sql.Blob originalBlob, int numDims, int newBlkId, int newPtIdStartCounter) throws java.io.IOException, java.sql.SQLException- Throws:
java.io.IOExceptionjava.sql.SQLException
-
-