Package org.umlg.sqlg.sql.dialect
Interface SqlDialect
- All Known Subinterfaces:
SqlBulkDialect
,SqlSchemaChangeDialect
- All Known Implementing Classes:
BaseSqlDialect
public interface SqlDialect
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptiondefault String
addColumnStatement
(String schema, String table, String column, String typeDefinition) Builds an add column statement.default String
addDbVersionToGraph
(DatabaseMetaData metadata) default String
addNotNullConstraint
(SqlgGraph sqlgGraph, String schema, String table, String column, PropertyType propertyType) default String
alterForeignKeyToDeferrable
(String schema, String table, String foreignKeyName) Only used by Postgresqlvoid
alterSequenceCacheSize
(SqlgGraph sqlgGraph, SchemaTable schemaTable, String sequence, int batchSize) default void
assertTableName
(String tableName) default boolean
canUserCreateSchemas
(SqlgGraph sqlgGraph) This is only needed for Hsqldb where we are unable to check for the existence of Sqlg's schemasdefault String
checkConstraintName
(SqlgGraph sqlgGraph, String schema, String table, String column, String constraint) These are internal columns used by sqlg that must be ignored when loading elements.convertArray
(PropertyType propertyType, Array array) default String
createSchemaStatement
(String schemaName) default String
default String
long
currSequenceVal
(SqlgGraph sqlgGraph, SchemaTable schemaTable, String prefix) default List<SqlgSqlExecutor.DropQuery>
drop
(SqlgGraph sqlgGraph, String leafElementsToDelete, String edgesToDelete, LinkedList<SchemaTableTree> distinctQueryStack) if the query traverses edges then the deletion logic is non trivial.default String
drop
(EdgeLabel edgeLabel, Collection<RecordId.ID> ids) default String
drop
(VertexLabel vertexLabel, Collection<RecordId.ID> ids) default String
dropIndex
(SqlgGraph sqlgGraph, AbstractLabel parentLabel, String name) default String
dropSchemaStatement
(String schema) default String
dropWithForeignKey
(boolean out, EdgeLabel edgeLabel, VertexLabel vertexLabel, Collection<RecordId.ID> ids, boolean mutatingCallbacks) existIndexQuery
(SchemaTable schemaTable, String prefix, String indexName) extractIndices
(Connection conn, String catalog, String schema) extract all indices in one godefault String
getArrayContainsQueryText
(String column) getArrayDriverType
(PropertyType booleanArray) default String
getArrayOverlapsQueryText
(String column) default String
getBlocked
(int pid, Connection connection) default int
getConnectionBackendPid
(Connection connection) default Integer
get the default fetch sizegetEdgeTables
(DatabaseMetaData metaData) Get all the Edge tables.default String
getFullTextQueryText
(FullText fullText, String column) get the full text query for the given predicate and columndefault <T> T
getIndexInfo
(DatabaseMetaData metaData, String catalog, String schema, String table, boolean unique, boolean approximate) default int
default int
default int
default int
getPartitions
(Connection connection) getPrimaryKeys
(DatabaseMetaData metaData, String catalog, String schemaPattern, String tableNamePattern) Return the table's primary keys.default Long
default String
A getter to return the "public" schema for the database.default String
getRangeClause
(org.apache.commons.lang3.Range<Long> r) range conditiongetSchemaNames
(DatabaseMetaData metaData) Returns all schemas.default int
getShardCount
(SqlgGraph sqlgGraph, AbstractLabel label) default String
getSkipClause
(long skip) getTableColumns
(DatabaseMetaData metaData, String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) Get the columns for a table.getVertexTables
(DatabaseMetaData metaData) Get all the Vertex tables.default void
void
handleOther
(Map<String, Object> properties, String columnName, Object o, PropertyType propertyType) default String
default String
default String
indexName
(SchemaTable schemaTable, String prefix, List<String> columns) default boolean
isH2()
default boolean
isHsqldb()
default boolean
This is needed for Cockroachdb where the index needs to be specified as a part of the 'CREATE TABLE' statement.default boolean
default boolean
default boolean
isMysql()
default boolean
boolean
isSystemIndex
(String indexName) default boolean
isTimestampz
(String typeName) void
lockTable
(SqlgGraph sqlgGraph, SchemaTable schemaTable, String prefix) default String
maybeWrapInQoutes
(String field) default boolean
default boolean
This is for Cockroachdb that only allows partial transactional schema creation.default boolean
default boolean
default boolean
Mssql server identifies temporary table by prepending it wirh a '#'default boolean
For Postgresql/Hsqldb and H2 temporary tables have no schema.default boolean
long
nextSequenceVal
(SqlgGraph sqlgGraph, SchemaTable schemaTable, String prefix) default void
prepareDB
(Connection conn) int[]
propertyTypeToJavaSqlType
(PropertyType propertyType) String[]
propertyTypeToSqlDefinition
(PropertyType propertyType) default void
putJsonMetaObject
(com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.databind.node.ArrayNode metaNodeArray, String columnName, int sqlType, Object o) default void
putJsonObject
(com.fasterxml.jackson.databind.node.ObjectNode obj, String columnName, int sqlType, Object o) default String
renameColumn
(String schema, String table, String column, String newName) default String
renameTable
(String schema, String table, String newName) default boolean
MariaDb can not index the LONGTEXT type.default boolean
default boolean
schemaExists
(DatabaseMetaData metadata, String schema) sequenceName
(SqlgGraph sqlgGraph, SchemaTable outSchemaTable, String prefix) void
setArray
(PreparedStatement statement, int index, PropertyType type, Object[] values) default void
setGeographyPoint
(PreparedStatement preparedStatement, int parameterStartIndex, Object point) void
setJson
(PreparedStatement preparedStatement, int parameterStartIndex, com.fasterxml.jackson.databind.JsonNode right) default void
setLineString
(PreparedStatement preparedStatement, int parameterStartIndex, Object lineString) default void
setLquery
(PreparedStatement preparedStatement, int parameterStartIndex, String path) default void
setLqueryArray
(PreparedStatement preparedStatement, int parameterStartIndex, Array paths) default void
setLtree
(PreparedStatement preparedStatement, int parameterStartIndex, String path) default void
setLtreeArray
(PreparedStatement preparedStatement, int parameterStartIndex, Array paths) default void
setPoint
(PreparedStatement preparedStatement, int parameterStartIndex, Object point) default void
setPolygon
(PreparedStatement preparedStatement, int parameterStartIndex, Object point) sqlArrayTypeNameToPropertyType
(String typeName, SqlgGraph sqlgGraph, String schema, String table, String columnName, ListIterator<org.apache.commons.lang3.tuple.Triple<String, Integer, String>> metaDataIter) "TYPE_NAME" is column meta data returned by the jdbc driver.default String
int
Returns the number of parameters that can be passed into a sql 'IN' statement.default String
default String
This is only relevant to Postgresql for now.default String
sqlToTurnOffReferentialConstraintCheck
(String tableName) default String
sqlToTurnOnReferentialConstraintCheck
(String tableName) default List<SqlgSqlExecutor.DropQuery>
sqlTruncate
(SqlgGraph sqlgGraph, SchemaTable schemaTable) sqlTypeToPropertyType
(SqlgGraph sqlgGraph, String schema, String table, String column, int sqlType, String typeName, ListIterator<org.apache.commons.lang3.tuple.Triple<String, Integer, String>> metaDataIter) default boolean
default boolean
default boolean
default boolean
boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
This is needed for H2 that does not support the standardselect * from values((1,1),(2,2)) as tmp("field1", "field2")
Instead the columns are hardcoded as "C1", "C2"default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
If true it means a labels (tables) can be created in existing schemas.default boolean
default boolean
default boolean
default boolean
This is primarily for Postgresql's copy command.default boolean
default boolean
MariaDb does not drop the temporary table after a commit.default boolean
default boolean
boolean
supportsType
(PropertyType propertyType) An easy way to see if a dialect supports the given type of not.default boolean
default boolean
Indicates if the rdbms supports 'VALUES (x,y)" table expressions.default boolean
default String
Mssql server's # prefix for temporary tables.default byte[]
toByteArray
(Object object7) default String
toRDBSStringLiteral
(Object value) default String
toRDBSStringLiteral
(PropertyType propertyType, Object value) default String
toSelectString
(boolean partOfDuplicateQuery, ColumnList.Column column, String alias) default boolean
This indicates whether a unique index considers mull values as equal or not.default void
validateColumnName
(String column) void
validateProperty
(Object key, Object value) default void
validateSchemaName
(String schema) default void
validateTableName
(String table) valueToValuesString
(PropertyType propertyType, Object value) Convert a value to insert into the db so that it can be used in a 'values' sql clause.
-
Field Details
-
INDEX_POSTFIX
- See Also:
-
-
Method Details
-
supportsDistribution
default boolean supportsDistribution() -
dialectName
String dialectName() -
getInternalSchemas
-
sqlTypeToPropertyType
PropertyType sqlTypeToPropertyType(SqlgGraph sqlgGraph, String schema, String table, String column, int sqlType, String typeName, ListIterator<org.apache.commons.lang3.tuple.Triple<String, Integer, String>> metaDataIter) -
sqlArrayTypeNameToPropertyType
PropertyType sqlArrayTypeNameToPropertyType(String typeName, SqlgGraph sqlgGraph, String schema, String table, String columnName, ListIterator<org.apache.commons.lang3.tuple.Triple<String, Integer, String>> metaDataIter) "TYPE_NAME" is column meta data returned by the jdbc driver. This method returns the TYPE_NAME for the sqlTypes
constant. This method is only called for array types.- Returns:
- the TYPE_NAME for the given Types constant.
-
validateProperty
-
needsSemicolon
default boolean needsSemicolon() -
supportsCascade
default boolean supportsCascade() -
supportsIfExists
default boolean supportsIfExists() -
needsSchemaDropCascade
default boolean needsSchemaDropCascade() -
getColumnEscapeKey
String getColumnEscapeKey() -
getPrimaryKeyType
String getPrimaryKeyType() -
getAutoIncrementPrimaryKeyConstruct
String getAutoIncrementPrimaryKeyConstruct() -
getAutoIncrement
-
propertyTypeToSqlDefinition
-
propertyTypeToJavaSqlType
-
getForeignKeyTypeDefinition
String getForeignKeyTypeDefinition() -
maybeWrapInQoutes
-
supportsFloatValues
default boolean supportsFloatValues() -
supportsBigDecimal
default boolean supportsBigDecimal() -
supportsByteValues
default boolean supportsByteValues() -
supportsTransactionalSchema
default boolean supportsTransactionalSchema() -
supportsBooleanArrayValues
default boolean supportsBooleanArrayValues() -
supportsByteArrayValues
default boolean supportsByteArrayValues() -
supportsDoubleArrayValues
default boolean supportsDoubleArrayValues() -
supportsBigDecimalArrayValues
default boolean supportsBigDecimalArrayValues() -
supportsFloatArrayValues
default boolean supportsFloatArrayValues() -
supportsIntegerArrayValues
default boolean supportsIntegerArrayValues() -
supportsShortArrayValues
default boolean supportsShortArrayValues() -
supportsLongArrayValues
default boolean supportsLongArrayValues() -
supportsStringArrayValues
default boolean supportsStringArrayValues() -
supportsZonedDateTimeArrayValues
default boolean supportsZonedDateTimeArrayValues() -
supportsLocalTimeArrayValues
default boolean supportsLocalTimeArrayValues() -
supportsLocalDateArrayValues
default boolean supportsLocalDateArrayValues() -
supportsLocalDateTimeArrayValues
default boolean supportsLocalDateTimeArrayValues() -
supportsPeriodArrayValues
default boolean supportsPeriodArrayValues() -
supportsJsonArrayValues
default boolean supportsJsonArrayValues() -
supportsUUID
default boolean supportsUUID() -
supportsDurationArrayValues
default boolean supportsDurationArrayValues() -
assertTableName
-
putJsonObject
-
putJsonMetaObject
-
getArrayDriverType
-
createTableStatement
-
createTemporaryTableStatement
-
createSchemaStatement
- Returns:
- the statement head to create a schema
-
addColumnStatement
default String addColumnStatement(String schema, String table, String column, String typeDefinition) Builds an add column statement.- Parameters:
schema
- schema nametable
- table namecolumn
- new column nametypeDefinition
- column definition- Returns:
- the statement to add the column
-
dropSchemaStatement
- Returns:
- the statement head to drop a schema
-
prepareDB
-
getPublicSchema
A getter to return the "public" schema for the database. For postgresql it is "public" and for HSQLDB it is "PUBLIC"- Returns:
- the database's public schema.
-
requiresIndexName
default boolean requiresIndexName() -
indexName
-
indexName
-
uniqueIndexConsidersNullValuesEqual
default boolean uniqueIndexConsidersNullValuesEqual()This indicates whether a unique index considers mull values as equal or not. Mssql server is the only db so far that considers nulls equals.- Returns:
- true is multiple null values are equal and thus not allowed.
-
existIndexQuery
-
supportsSchemas
default boolean supportsSchemas() -
supportsBatchMode
default boolean supportsBatchMode() -
supportsStreamingBatchMode
default boolean supportsStreamingBatchMode()This is primarily for Postgresql's copy command.- Returns:
- true if data can be streamed in via a socket.
-
supportsJsonType
default boolean supportsJsonType() -
hasContainerKeyToColumn
-
needForeignKeyIndex
default boolean needForeignKeyIndex() -
supportsClientInfo
default boolean supportsClientInfo() -
validateSchemaName
-
validateTableName
-
validateColumnName
-
getMaximumSchemaNameLength
default int getMaximumSchemaNameLength() -
getMaximumTableNameLength
default int getMaximumTableNameLength() -
getMaximumColumnNameLength
default int getMaximumColumnNameLength() -
getMaximumIndexNameLength
default int getMaximumIndexNameLength() -
supportsILike
default boolean supportsILike() -
needsTimeZone
default boolean needsTimeZone() -
getSpacialRefTable
-
getGisSchemas
-
setJson
void setJson(PreparedStatement preparedStatement, int parameterStartIndex, com.fasterxml.jackson.databind.JsonNode right) -
setLtree
-
setLquery
-
setLtreeArray
default void setLtreeArray(PreparedStatement preparedStatement, int parameterStartIndex, Array paths) -
setLqueryArray
default void setLqueryArray(PreparedStatement preparedStatement, int parameterStartIndex, Array paths) -
handleOther
-
setPoint
-
setLineString
default void setLineString(PreparedStatement preparedStatement, int parameterStartIndex, Object lineString) -
setPolygon
-
setGeographyPoint
default void setGeographyPoint(PreparedStatement preparedStatement, int parameterStartIndex, Object point) -
isPostgresql
default boolean isPostgresql() -
isMariaDb
default boolean isMariaDb() -
isMysql
default boolean isMysql() -
isMssqlServer
default boolean isMssqlServer() -
isHsqldb
default boolean isHsqldb() -
isH2
default boolean isH2() -
getGis
-
lockTable
-
alterSequenceCacheSize
void alterSequenceCacheSize(SqlgGraph sqlgGraph, SchemaTable schemaTable, String sequence, int batchSize) -
nextSequenceVal
-
currSequenceVal
-
sequenceName
-
supportsBulkWithinOut
boolean supportsBulkWithinOut() -
afterCreateTemporaryTableStatement
String afterCreateTemporaryTableStatement() -
needsTemporaryTableSchema
default boolean needsTemporaryTableSchema()For Postgresql/Hsqldb and H2 temporary tables have no schema. For Mariadb the schema/database must be specified.- Returns:
- true is a schema/database must be specified.
-
needsTemporaryTablePrefix
default boolean needsTemporaryTablePrefix()Mssql server identifies temporary table by prepending it wirh a '#'- Returns:
- true if a prefix is needed.
-
temporaryTablePrefix
Mssql server's # prefix for temporary tables.- Returns:
- The prefix.
-
supportsTemporaryTableOnCommitDrop
default boolean supportsTemporaryTableOnCommitDrop()MariaDb does not drop the temporary table after a commit. It only drops it when the session ends. Sqlg will manually drop the temporary table for Mariadb as we need the same semantics across all dialects.- Returns:
- true if temporary tables are dropped on commit.
-
columnsToIgnore
These are internal columns used by sqlg that must be ignored when loading elements. eg. '_copy_dummy' when doing using the copy command on postgresql.- Returns:
- The columns to ignore.
-
sqlgSqlgSchemaCreationScript
-
sqlgTopologyCreationScripts
-
sqlgAddIndexEdgeSequenceColumn
String sqlgAddIndexEdgeSequenceColumn() -
getPrimaryKeyStartValue
-
convertArray
- Throws:
SQLException
-
setArray
void setArray(PreparedStatement statement, int index, PropertyType type, Object[] values) throws SQLException - Throws:
SQLException
-
getRangeClause
range condition- Parameters:
r
- range- Returns:
- the range clause.
-
getSkipClause
-
getFullTextQueryText
get the full text query for the given predicate and column- Parameters:
fullText
-column
-- Returns:
-
getArrayContainsQueryText
-
getArrayOverlapsQueryText
-
schemaExists
- Throws:
SQLException
-
getSchemaNames
Returns all schemas. For some RDBMSes, like Cockroachdb and MariaDb, this is the database/catalog.- Returns:
- The list of schema names.
-
getVertexTables
List<org.apache.commons.lang3.tuple.Triple<String,String, getVertexTablesString>> (DatabaseMetaData metaData) Get all the Vertex tables. i.e. all tables starting with 'V_'- Parameters:
metaData
- JDBC meta data.- Returns:
- A triple holding the catalog, schema and table.
-
getEdgeTables
List<org.apache.commons.lang3.tuple.Triple<String,String, getEdgeTablesString>> (DatabaseMetaData metaData) Get all the Edge tables. i.e. all tables starting with 'E_'- Parameters:
metaData
- JDBC meta data.- Returns:
- A triple holding the catalog, thea schema and the table.
-
getTableColumns
List<org.apache.commons.lang3.tuple.Triple<String,Integer, getTableColumnsString>> (DatabaseMetaData metaData, String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) Get the columns for a table.- Parameters:
metaData
- JDBC meta data.- Returns:
- The columns.
-
getPrimaryKeys
List<String> getPrimaryKeys(DatabaseMetaData metaData, String catalog, String schemaPattern, String tableNamePattern) Return the table's primary keys.- Parameters:
metaData
- JDBC meta data.catalog
- The db catalog.schemaPattern
- The schema name.tableNamePattern
- The table name.- Returns:
- A list of primary key column names.
-
getIndexInfo
-
extractIndices
default Map<String,Set<IndexRef>> extractIndices(Connection conn, String catalog, String schema) throws SQLException extract all indices in one go- Parameters:
conn
-catalog
-schema
-- Returns:
- a map of indices references by key, the key being cat+schema+table
- Throws:
SQLException
-
isSystemIndex
-
supportsFullValueExpression
default boolean supportsFullValueExpression()This is needed for H2 that does not support the standardselect * from values((1,1),(2,2)) as tmp("field1", "field2")
Instead the columns are hardcoded as "C1", "C2"- Returns:
- true if the valueExpression is similar to Postgresql. i.e.
select * from values((1,1),(2,2)) as tmp("field1", "field2")
H2 returns false and has some special code for it.
-
supportsValuesExpression
default boolean supportsValuesExpression()Indicates if the rdbms supports 'VALUES (x,y)" table expressions. This is needed because Mariadb does not.- Returns:
- true is 'VALUES' expression is supported else false.
-
isIndexPartOfCreateTable
default boolean isIndexPartOfCreateTable()This is needed for Cockroachdb where the index needs to be specified as a part of the 'CREATE TABLE' statement.- Returns:
- true if the indices must be specified together with the 'CREATE TABLE' sql, else false.
-
sqlInsertEmptyValues
-
requiresIndexLengthLimit
default boolean requiresIndexLengthLimit()MariaDb can not index the LONGTEXT type. It needs to know how many characters to index.- Returns:
- Return true is the number of characters to index needs to be specified.
-
valueToValuesString
Convert a value to insert into the db so that it can be used in a 'values' sql clause.- Parameters:
propertyType
- The type of the property.value
- The value of the property.- Returns:
- The value that can be used in a sql 'from' clause.
-
supportsType
An easy way to see if a dialect supports the given type of not.- Parameters:
propertyType
- APropertyType
representing the type of the property.- Returns:
- true if the PropertyType is supported else false.
-
sqlInParameterLimit
int sqlInParameterLimit()Returns the number of parameters that can be passed into a sql 'IN' statement.- Returns:
-
needsSchemaCreationPrecommit
default boolean needsSchemaCreationPrecommit()This is for Cockroachdb that only allows partial transactional schema creation. It to create schema elements if the transtion has already been written to.- Returns:
- false if there is no need to force a commit before schema creation.
-
supportsSchemaIfNotExists
default boolean supportsSchemaIfNotExists()If true it means a labels (tables) can be created in existing schemas.- Returns:
- true if 'CREATE SCHEMA IF NOT EXISTS' works.
-
sqlgCreateTopologyGraph
String sqlgCreateTopologyGraph() -
drop
default List<SqlgSqlExecutor.DropQuery> drop(SqlgGraph sqlgGraph, String leafElementsToDelete, String edgesToDelete, LinkedList<SchemaTableTree> distinctQueryStack) if the query traverses edges then the deletion logic is non trivial. The edges can not be deleted upfront as then we will not be able to travers to the leaf vertices anymore because the edges are no longer there to travers. In this case we need to drop foreign key constraint checking. Delete the vertices and then the edges using the same query. The edge query is the same as the vertex query with the last SchemaTableTree removed from the distinctQueryStack;- Parameters:
sqlgGraph
- The graph.leafElementsToDelete
- The leaf elements of the query. eg. g.V().out().out() The last vertices returned by the gremlin query.edgesToDelete
-distinctQueryStack
- The query's SchemaTableTree stack as constructed by parsing.- Returns:
-
drop
-
drop
-
dropWithForeignKey
default String dropWithForeignKey(boolean out, EdgeLabel edgeLabel, VertexLabel vertexLabel, Collection<RecordId.ID> ids, boolean mutatingCallbacks) -
supportsDeferrableForeignKey
default boolean supportsDeferrableForeignKey() -
sqlToTurnOffReferentialConstraintCheck
-
sqlToTurnOnReferentialConstraintCheck
-
sqlToGetAllForeignKeys
This is only relevant to Postgresql for now.- Returns:
- The sql string that will return all the foreign keys.
-
alterForeignKeyToDeferrable
Only used by Postgresql- Parameters:
schema
-table
-foreignKeyName
-- Returns:
- The sql statement to alter the foreign key to be deferrable.
-
sqlTruncate
-
supportsTruncateMultipleTablesTogether
default boolean supportsTruncateMultipleTablesTogether() -
supportsPartitioning
default boolean supportsPartitioning() -
getPartitions
-
addPartitionTables
-
addHashPartitionColumns
-
addPartitionSchemaAbstractLabelColumns
-
addPropertyDefinitions
-
addOutEdgeDefinitions
-
addInEdgeDefinitions
-
addDbVersionToGraph
-
getDefaultFetchSize
get the default fetch size- Returns:
- the default fetch size, maybe null if we want to use the default from the driver
-
getShardCount
-
supportsSharding
default boolean supportsSharding() -
toRDBSStringLiteral
-
toRDBSStringLiteral
-
grantReadOnlyUserPrivilegesToSqlgSchemas
-
getBlocked
default org.apache.commons.lang3.tuple.Pair<Boolean,String> getBlocked(int pid, Connection connection) -
getConnectionBackendPid
-
toSelectString
-
isTimestampz
-
dropIndex
-
canUserCreateSchemas
This is only needed for Hsqldb where we are unable to check for the existence of Sqlg's schemas- Returns:
- true if the user can create schemas
-
renameColumn
-
renameTable
-
toByteArray
-
checkConstraintName
-
addNotNullConstraint
-