Interface SqlDialect

All Known Subinterfaces:
SqlBulkDialect, SqlSchemaChangeDialect
All Known Implementing Classes:
BaseSqlDialect

public interface SqlDialect
  • Field Details

  • Method Details

    • supportsDistribution

      default boolean supportsDistribution()
    • dialectName

      String dialectName()
    • getInternalSchemas

      Set<String> 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 sql Types constant. This method is only called for array types.
      Returns:
      the TYPE_NAME for the given Types constant.
    • validateProperty

      void validateProperty(Object key, Object value)
    • 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

      default String getAutoIncrement()
    • propertyTypeToSqlDefinition

      String[] propertyTypeToSqlDefinition(PropertyType propertyType)
    • propertyTypeToJavaSqlType

      int[] propertyTypeToJavaSqlType(PropertyType propertyType)
    • getForeignKeyTypeDefinition

      String getForeignKeyTypeDefinition()
    • maybeWrapInQoutes

      default String maybeWrapInQoutes(String field)
    • 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

      default void assertTableName(String tableName)
    • putJsonObject

      default void putJsonObject(com.fasterxml.jackson.databind.node.ObjectNode obj, String columnName, int sqlType, Object o)
    • putJsonMetaObject

      default void putJsonMetaObject(com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.databind.node.ArrayNode metaNodeArray, String columnName, int sqlType, Object o)
    • getArrayDriverType

      String getArrayDriverType(PropertyType booleanArray)
    • createTableStatement

      default String createTableStatement()
    • createTemporaryTableStatement

      default String createTemporaryTableStatement()
    • createSchemaStatement

      default String createSchemaStatement(String schemaName)
      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 name
      table - table name
      column - new column name
      typeDefinition - column definition
      Returns:
      the statement to add the column
    • dropSchemaStatement

      default String dropSchemaStatement(String schema)
      Returns:
      the statement head to drop a schema
    • prepareDB

      default void prepareDB(Connection conn)
    • getPublicSchema

      default String 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

      default String indexName(SchemaTable schemaTable, String prefix, List<String> columns)
    • indexName

      default String indexName(SchemaTable schemaTable, String prefix, String postfix, List<String> columns)
    • 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

      String existIndexQuery(SchemaTable schemaTable, String prefix, String indexName)
    • 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

      default String hasContainerKeyToColumn(String key)
    • needForeignKeyIndex

      default boolean needForeignKeyIndex()
    • supportsClientInfo

      default boolean supportsClientInfo()
    • validateSchemaName

      default void validateSchemaName(String schema)
    • validateTableName

      default void validateTableName(String table)
    • validateColumnName

      default void validateColumnName(String column)
    • 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

      Set<String> getSpacialRefTable()
    • getGisSchemas

      List<String> getGisSchemas()
    • setJson

      void setJson(PreparedStatement preparedStatement, int parameterStartIndex, com.fasterxml.jackson.databind.JsonNode right)
    • setLtree

      default void setLtree(PreparedStatement preparedStatement, int parameterStartIndex, String path)
    • setLquery

      default void setLquery(PreparedStatement preparedStatement, int parameterStartIndex, String path)
    • setLtreeArray

      default void setLtreeArray(PreparedStatement preparedStatement, int parameterStartIndex, Array paths)
    • setLqueryArray

      default void setLqueryArray(PreparedStatement preparedStatement, int parameterStartIndex, Array paths)
    • handleOther

      void handleOther(Map<String,Object> properties, String columnName, Object o, PropertyType propertyType)
    • setPoint

      default void setPoint(PreparedStatement preparedStatement, int parameterStartIndex, Object point)
    • setLineString

      default void setLineString(PreparedStatement preparedStatement, int parameterStartIndex, Object lineString)
    • setPolygon

      default void setPolygon(PreparedStatement preparedStatement, int parameterStartIndex, Object point)
    • 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

      default <T> T getGis(SqlgGraph sqlgGraph)
    • lockTable

      void lockTable(SqlgGraph sqlgGraph, SchemaTable schemaTable, String prefix)
    • alterSequenceCacheSize

      void alterSequenceCacheSize(SqlgGraph sqlgGraph, SchemaTable schemaTable, String sequence, int batchSize)
    • nextSequenceVal

      long nextSequenceVal(SqlgGraph sqlgGraph, SchemaTable schemaTable, String prefix)
    • currSequenceVal

      long currSequenceVal(SqlgGraph sqlgGraph, SchemaTable schemaTable, String prefix)
    • sequenceName

      String sequenceName(SqlgGraph sqlgGraph, SchemaTable outSchemaTable, String prefix)
    • 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

      default String 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

      default List<String> 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

      default String sqlgSqlgSchemaCreationScript()
    • sqlgTopologyCreationScripts

      List<String> sqlgTopologyCreationScripts()
    • sqlgAddIndexEdgeSequenceColumn

      String sqlgAddIndexEdgeSequenceColumn()
    • getPrimaryKeyStartValue

      default Long getPrimaryKeyStartValue()
    • convertArray

      Object convertArray(PropertyType propertyType, Array array) throws SQLException
      Throws:
      SQLException
    • setArray

      void setArray(PreparedStatement statement, int index, PropertyType type, Object[] values) throws SQLException
      Throws:
      SQLException
    • getRangeClause

      default String getRangeClause(org.apache.commons.lang3.Range<Long> r)
      range condition
      Parameters:
      r - range
      Returns:
      the range clause.
    • getSkipClause

      default String getSkipClause(long skip)
    • getFullTextQueryText

      default String getFullTextQueryText(FullText fullText, String column)
      get the full text query for the given predicate and column
      Parameters:
      fullText -
      column -
      Returns:
    • getArrayContainsQueryText

      default String getArrayContainsQueryText(String column)
    • getArrayOverlapsQueryText

      default String getArrayOverlapsQueryText(String column)
    • schemaExists

      default boolean schemaExists(DatabaseMetaData metadata, String schema) throws SQLException
      Throws:
      SQLException
    • getSchemaNames

      List<String> getSchemaNames(DatabaseMetaData metaData)
      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,String>> getVertexTables(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,String>> getEdgeTables(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,String>> getTableColumns(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

      List<org.apache.commons.lang3.tuple.Triple<String,Boolean,String>> getIndexInfo(DatabaseMetaData metaData, String catalog, String schema, String table, boolean unique, boolean approximate)
    • 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

      boolean isSystemIndex(String indexName)
    • supportsFullValueExpression

      default boolean supportsFullValueExpression()
      This is needed for H2 that does not support the standard select * 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

      default String 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

      String valueToValuesString(PropertyType propertyType, Object value)
      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

      boolean supportsType(PropertyType propertyType)
      An easy way to see if a dialect supports the given type of not.
      Parameters:
      propertyType - A PropertyType 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

      default String drop(VertexLabel vertexLabel, Collection<RecordId.ID> ids)
    • drop

      default String drop(EdgeLabel edgeLabel, Collection<RecordId.ID> ids)
    • dropWithForeignKey

      default String dropWithForeignKey(boolean out, EdgeLabel edgeLabel, VertexLabel vertexLabel, Collection<RecordId.ID> ids, boolean mutatingCallbacks)
    • supportsDeferrableForeignKey

      default boolean supportsDeferrableForeignKey()
    • sqlToTurnOffReferentialConstraintCheck

      default String sqlToTurnOffReferentialConstraintCheck(String tableName)
    • sqlToTurnOnReferentialConstraintCheck

      default String sqlToTurnOnReferentialConstraintCheck(String tableName)
    • sqlToGetAllForeignKeys

      default String sqlToGetAllForeignKeys()
      This is only relevant to Postgresql for now.
      Returns:
      The sql string that will return all the foreign keys.
    • alterForeignKeyToDeferrable

      default String alterForeignKeyToDeferrable(String schema, String table, String foreignKeyName)
      Only used by Postgresql
      Parameters:
      schema -
      table -
      foreignKeyName -
      Returns:
      The sql statement to alter the foreign key to be deferrable.
    • sqlTruncate

      default List<SqlgSqlExecutor.DropQuery> sqlTruncate(SqlgGraph sqlgGraph, SchemaTable schemaTable)
    • supportsTruncateMultipleTablesTogether

      default boolean supportsTruncateMultipleTablesTogether()
    • supportsPartitioning

      default boolean supportsPartitioning()
    • getPartitions

      default List<Map<String,String>> getPartitions(Connection connection)
    • addPartitionTables

      default List<String> addPartitionTables()
    • addHashPartitionColumns

      default List<String> addHashPartitionColumns()
    • addPartitionSchemaAbstractLabelColumns

      default List<String> addPartitionSchemaAbstractLabelColumns()
    • addPropertyDefinitions

      default List<String> addPropertyDefinitions()
    • addOutEdgeDefinitions

      default List<String> addOutEdgeDefinitions()
    • addInEdgeDefinitions

      default List<String> addInEdgeDefinitions()
    • addDbVersionToGraph

      default String addDbVersionToGraph(DatabaseMetaData metadata)
    • getDefaultFetchSize

      default Integer getDefaultFetchSize()
      get the default fetch size
      Returns:
      the default fetch size, maybe null if we want to use the default from the driver
    • getShardCount

      default int getShardCount(SqlgGraph sqlgGraph, AbstractLabel label)
    • supportsSharding

      default boolean supportsSharding()
    • toRDBSStringLiteral

      default String toRDBSStringLiteral(Object value)
    • toRDBSStringLiteral

      default String toRDBSStringLiteral(PropertyType propertyType, Object value)
    • grantReadOnlyUserPrivilegesToSqlgSchemas

      default void grantReadOnlyUserPrivilegesToSqlgSchemas(SqlgGraph sqlgGraph)
    • getBlocked

      default org.apache.commons.lang3.tuple.Pair<Boolean,String> getBlocked(int pid, Connection connection)
    • getConnectionBackendPid

      default int getConnectionBackendPid(Connection connection)
    • toSelectString

      default String toSelectString(boolean partOfDuplicateQuery, ColumnList.Column column, String alias)
    • isTimestampz

      default boolean isTimestampz(String typeName)
    • dropIndex

      default String dropIndex(SqlgGraph sqlgGraph, AbstractLabel parentLabel, String name)
    • canUserCreateSchemas

      default boolean canUserCreateSchemas(SqlgGraph sqlgGraph)
      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

      default String renameColumn(String schema, String table, String column, String newName)
    • renameTable

      default String renameTable(String schema, String table, String newName)
    • toByteArray

      default byte[] toByteArray(Object object7)
    • checkConstraintName

      default String checkConstraintName(SqlgGraph sqlgGraph, String schema, String table, String column, String constraint)
    • addNotNullConstraint

      default String addNotNullConstraint(SqlgGraph sqlgGraph, String schema, String table, String column, PropertyType propertyType)