Package org.qdl_lang.extensions.database
Class QDLDB
- java.lang.Object
-
- org.qdl_lang.extensions.database.QDLDB
-
- All Implemented Interfaces:
Serializable,QDLMetaModule
public class QDLDB extends Object implements QDLMetaModule
Created by Jeff Gaynor
on 5/5/22 at 7:11 AM- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classQDLDB.BatchExecuteclassQDLDB.ConnectclassQDLDB.ExecuteclassQDLDB.GetTableMetadataclassQDLDB.PreparedReadclassQDLDB.PreparedUpdateclassQDLDB.QDLCreateclassQDLDB.QDLToSQLclassQDLDB.QDLTypesclassQDLDB.QDLUpdateclassQDLDB.ShutdownclassQDLDB.SQLToQDLclassQDLDB.SQLTypes
-
Field Summary
-
Constructor Summary
Constructors Constructor Description QDLDB()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddQDLTypesBlurb(List<String> docs)protected voidcheckArg(boolean condition, String message)If the condition is true, do nothing, if false, throw and exception with the given messageprotected Map<Long,int[]>creatQDLTypeMap(QDLStem qdlTypes)Takes theQDLStemof QDL types and returns a map of int[sql_type,qdl_type], indexed by the position in the list.voiddeserializeFromJSON(org.kordamp.json.JSONObject json)protected voiddestroyConnection(edu.uiuc.ncsa.security.storage.sql.ConnectionRecord c)QDLValuedoSQLExecute(QDLValue[] qdlValues, String name, State state)Used for both create and delete.protected TreeMap<String,Integer>getColumns(QDLStem metadata)Utility to convert the columns entry in a metadata stem to usable (column, int) pairs for SQL.QDLStemgetDataTypes()protected longgetParameterCount(String rawStatement)Given the raw SQL statement, count the parameters (i.e.protected List<String>getPreparedArgStatement()protected TreeMap<String,Integer>getSQLMetadata(Connection c, String tablename)Given tablename get just the columns names and their types.protected ObjectqdlToSQL(int qdlType, int sqlType, QDLValue entry)voidreleaseConnection(edu.uiuc.ncsa.security.storage.sql.ConnectionRecord c)org.kordamp.json.JSONObjectserializeToJSON()Send back a serialization of internal state for this object.protected QDLValuesqlStringToQDLValue(String string, int qdlType, State state)protected QDLValuesqlToQDL(Object obj, int qdlType, State state)Converts a generic object to a QDL object.
-
-
-
Field Detail
-
CONNECT_COMMAND
public static String CONNECT_COMMAND
-
MYSQL_TYPE
public static final String MYSQL_TYPE
- See Also:
- Constant Field Values
-
MARIADB_TYPE
public static final String MARIADB_TYPE
- See Also:
- Constant Field Values
-
POSTGRES_TYPE
public static final String POSTGRES_TYPE
- See Also:
- Constant Field Values
-
DYNAMODB_TYPE
public static final String DYNAMODB_TYPE
- See Also:
- Constant Field Values
-
DERBY_TYPE
public static final String DERBY_TYPE
- See Also:
- Constant Field Values
-
TYPE_ARG
public static final String TYPE_ARG
- See Also:
- Constant Field Values
-
QUERY_COMMAND
public static final String QUERY_COMMAND
- See Also:
- Constant Field Values
-
QDL_TO_SQL
public static final String QDL_TO_SQL
- See Also:
- Constant Field Values
-
SQL_TO_QDL
public static final String SQL_TO_QDL
- See Also:
- Constant Field Values
-
CREATE_COMMAND
public static String CREATE_COMMAND
-
GET_TABLE_METADATA
public static String GET_TABLE_METADATA
-
MD_TABLENAME
public static String MD_TABLENAME
-
MD_CATALOG
public static String MD_CATALOG
-
MD_SCHEMA
public static String MD_SCHEMA
-
MD_PRIMARY_KEY
public static String MD_PRIMARY_KEY
-
MD_AUTO_COMMIT
public static String MD_AUTO_COMMIT
-
MD_COLUMNS
public static String MD_COLUMNS
-
MD_DB_VENDOR
public static String MD_DB_VENDOR
-
MD_DB_VERSION
public static String MD_DB_VERSION
-
MD_DB_MAJOR_RELEASE
public static String MD_DB_MAJOR_RELEASE
-
MD_DB_MINOR_RELEASE
public static String MD_DB_MINOR_RELEASE
-
QDL_TYPE_DEFAULT
public static final int QDL_TYPE_DEFAULT
- See Also:
- Constant Field Values
-
QDL_TYPE_JSON
public static final int QDL_TYPE_JSON
- See Also:
- Constant Field Values
-
QDL_TYPE_INPUT_FORM
public static final int QDL_TYPE_INPUT_FORM
- See Also:
- Constant Field Values
-
QDL_TYPE_DATE
public static final int QDL_TYPE_DATE
- See Also:
- Constant Field Values
-
QDL_TYPE_STRING
public static final int QDL_TYPE_STRING
- See Also:
- Constant Field Values
-
QDL_TYPE_JSON_SET
public static final int QDL_TYPE_JSON_SET
- See Also:
- Constant Field Values
-
QDL_TYPE_NAME_DEFAULT
public static final String QDL_TYPE_NAME_DEFAULT
- See Also:
- Constant Field Values
-
QDL_TYPE_NAME_JSON
public static final String QDL_TYPE_NAME_JSON
- See Also:
- Constant Field Values
-
QDL_TYPE_NAME_INPUT_FORM
public static final String QDL_TYPE_NAME_INPUT_FORM
- See Also:
- Constant Field Values
-
QDL_TYPE_NAME_DATE
public static final String QDL_TYPE_NAME_DATE
- See Also:
- Constant Field Values
-
QDL_TYPE_NAME_STRING
public static final String QDL_TYPE_NAME_STRING
- See Also:
- Constant Field Values
-
QDL_TYPE_NAME_JSON_SET
public static final String QDL_TYPE_NAME_JSON_SET
- See Also:
- Constant Field Values
-
QDL_TYPE_NAME_FORCE_COLUMN_CASE
public static final String QDL_TYPE_NAME_FORCE_COLUMN_CASE
- See Also:
- Constant Field Values
-
QDL_TYPE_NAME_FLATTEN_OUTPUT
public static final String QDL_TYPE_NAME_FLATTEN_OUTPUT
- See Also:
- Constant Field Values
-
UPDATE_COMMAND
public static String UPDATE_COMMAND
-
PREPARED_UPDATE_COMMAND
public static String PREPARED_UPDATE_COMMAND
-
EXECUTE_COMMAND
public static String EXECUTE_COMMAND
-
QDL_TYPES_VAR_NAME
public static String QDL_TYPES_VAR_NAME
-
SQL_TYPES_VAR_NAME
public static String SQL_TYPES_VAR_NAME
-
SHUTDOWN
public static final String SHUTDOWN
- See Also:
- Constant Field Values
-
BATCH
public static String BATCH
-
-
Method Detail
-
qdlToSQL
protected Object qdlToSQL(int qdlType, int sqlType, QDLValue entry) throws SQLException, ParseException
- Throws:
SQLExceptionParseException
-
checkArg
protected void checkArg(boolean condition, String message)If the condition is true, do nothing, if false, throw and exception with the given message- Parameters:
condition-message-
-
sqlToQDL
protected QDLValue sqlToQDL(Object obj, int qdlType, State state) throws Throwable
Converts a generic object to a QDL object. If it is a known supported type, that is just used otherwise only basic conversions are done.- Parameters:
obj-qdlType- The QDL type of the object to convert to, for in the qdl_types. stem.- Returns:
- Throws:
Throwable
-
sqlStringToQDLValue
protected QDLValue sqlStringToQDLValue(String string, int qdlType, State state) throws ParseException
- Throws:
ParseException
-
releaseConnection
public void releaseConnection(edu.uiuc.ncsa.security.storage.sql.ConnectionRecord c)
-
destroyConnection
protected void destroyConnection(edu.uiuc.ncsa.security.storage.sql.ConnectionRecord c)
-
getSQLMetadata
protected TreeMap<String,Integer> getSQLMetadata(Connection c, String tablename) throws SQLException
Given tablename get just the columns names and their types.- Parameters:
c-tablename-- Returns:
- Throws:
SQLException
-
getColumns
protected TreeMap<String,Integer> getColumns(QDLStem metadata) throws SQLException
Utility to convert the columns entry in a metadata stem to usable (column, int) pairs for SQL.- Parameters:
metadata-- Returns:
- Throws:
SQLException
-
getDataTypes
public QDLStem getDataTypes()
-
doSQLExecute
public QDLValue doSQLExecute(QDLValue[] qdlValues, String name, State state) throws Throwable
Used for both create and delete.- Parameters:
qdlValues-name-- Returns:
- Throws:
Throwable
-
creatQDLTypeMap
protected Map<Long,int[]> creatQDLTypeMap(QDLStem qdlTypes)
Takes theQDLStemof QDL types and returns a map of int[sql_type,qdl_type], indexed by the position in the list.- Parameters:
qdlTypes-- Returns:
-
serializeToJSON
public org.kordamp.json.JSONObject serializeToJSON()
Description copied from interface:QDLMetaModuleSend back a serialization of internal state for this object. This allows for the state you choose to be serialized and then reloaded.NOTE
There is no canonical form for this. Set it how you will and deserialize it accordingly.- Specified by:
serializeToJSONin interfaceQDLMetaModule- Returns:
-
deserializeFromJSON
public void deserializeFromJSON(org.kordamp.json.JSONObject json)
- Specified by:
deserializeFromJSONin interfaceQDLMetaModule
-
getParameterCount
protected long getParameterCount(String rawStatement)
Given the raw SQL statement, count the parameters (i.e. the '?' instances) in it. Not terribly clever -- just a regex -- but should work in most cases.- Parameters:
rawStatement-- Returns:
-
-