@Override public String toString() { return getName(); }
@Override public String toString() { return getName(); }
void addIndex(Index i) { this.indexes.put(i.getName(), i); }
void addIndex(Index i) { this.indexes.put(i.getName(), i); }
@Override public int hashCode() { return (this.abstractLabel.getName() + this.getName()).hashCode(); }
@Override public int hashCode() { return (this.abstractLabel.getName() + this.getName()).hashCode(); }
List<Topology.TopologyValidationError> validateTopology(DatabaseMetaData metadata) throws SQLException { List<Topology.TopologyValidationError> validationErrors = new ArrayList<>(); try (ResultSet propertyRs = metadata.getIndexInfo(null, this.abstractLabel.getSchema().getName(), this.abstractLabel.getPrefix() + this.abstractLabel.getLabel(), false, false)) { Map<String, List<String>> indexColumns = new HashMap<>(); while (propertyRs.next()) { String columnName = propertyRs.getString("COLUMN_NAME"); String indexName = propertyRs.getString("INDEX_NAME"); List<String> columnNames; if (!indexColumns.containsKey(indexName)) { columnNames = new ArrayList<>(); indexColumns.put(indexName, columnNames); } else { columnNames = indexColumns.get(indexName); } columnNames.add(columnName); } if (!indexColumns.containsKey(this.getName())) { validationErrors.add(new Topology.TopologyValidationError(this)); } } return validationErrors; }
List<Topology.TopologyValidationError> validateTopology(DatabaseMetaData metadata) throws SQLException { List<Topology.TopologyValidationError> validationErrors = new ArrayList<>(); try (ResultSet propertyRs = metadata.getIndexInfo(null, this.abstractLabel.getSchema().getName(), this.abstractLabel.getPrefix() + this.abstractLabel.getLabel(), false, false)) { Map<String, List<String>> indexColumns = new HashMap<>(); while (propertyRs.next()) { String columnName = propertyRs.getString("COLUMN_NAME"); String indexName = propertyRs.getString("INDEX_NAME"); List<String> columnNames; if (!indexColumns.containsKey(indexName)) { columnNames = new ArrayList<>(); indexColumns.put(indexName, columnNames); } else { columnNames = indexColumns.get(indexName); } columnNames.add(columnName); } if (!indexColumns.containsKey(this.getName())) { validationErrors.add(new Topology.TopologyValidationError(this)); } } return validationErrors; }
/** * delete the index from the database * * @param sqlgGraph */ void delete(SqlgGraph sqlgGraph) { StringBuilder sql = new StringBuilder("DROP INDEX IF EXISTS "); SqlDialect sqlDialect = sqlgGraph.getSqlDialect(); sql.append(sqlDialect.maybeWrapInQoutes(getParentLabel().getSchema().getName())); sql.append("."); sql.append(sqlDialect.maybeWrapInQoutes(getName())); if (sqlDialect.needsSemicolon()) { sql.append(";"); } if (logger.isDebugEnabled()) { logger.debug(sql.toString()); } Connection conn = sqlgGraph.tx().getConnection(); try (Statement stmt = conn.createStatement()) { stmt.execute(sql.toString()); } catch (SQLException e) { throw new RuntimeException(e); } }
/** * delete the index from the database * * @param sqlgGraph */ void delete(SqlgGraph sqlgGraph) { StringBuilder sql = new StringBuilder("DROP INDEX IF EXISTS "); SqlDialect sqlDialect = sqlgGraph.getSqlDialect(); sql.append(sqlDialect.maybeWrapInQoutes(getParentLabel().getSchema().getName())); sql.append("."); sql.append(sqlDialect.maybeWrapInQoutes(getName())); if (sqlDialect.needsSemicolon()) { sql.append(";"); } if (logger.isDebugEnabled()) { logger.debug(sql.toString()); } Connection conn = sqlgGraph.tx().getConnection(); try (Statement stmt = conn.createStatement()) { stmt.execute(sql.toString()); } catch (SQLException e) { throw new RuntimeException(e); } }
/** * remove a given index that was on this label * * @param idx the index * @param preserveData should we keep the SQL data */ void removeIndex(Index idx, boolean preserveData) { this.getSchema().getTopology().lock(); if (!uncommittedRemovedIndexes.contains(idx.getName())) { uncommittedRemovedIndexes.add(idx.getName()); TopologyManager.removeIndex(this.sqlgGraph, idx); if (!preserveData) { idx.delete(sqlgGraph); } this.getSchema().getTopology().fire(idx, "", TopologyChangeAction.DELETE); } }
/** * remove a given index that was on this label * * @param idx the index * @param preserveData should we keep the SQL data */ void removeIndex(Index idx, boolean preserveData) { this.getSchema().getTopology().lock(); if (!uncommittedRemovedIndexes.contains(idx.getName())) { uncommittedRemovedIndexes.add(idx.getName()); TopologyManager.removeIndex(this.sqlgGraph, idx); if (!preserveData) { idx.delete(sqlgGraph); } this.getSchema().getTopology().fire(idx, "", TopologyChangeAction.DELETE); } }
public void createIndexOnLeafPartitions(Index index) { if (this.partitionType.isNone()) { //Append the partition name to the index name. String indexName = index.getName() + "_" + this.getName(); if (indexName.length() > this.sqlgGraph.getSqlDialect().getMaximumIndexNameLength()) { indexName = Index.generateName(this.sqlgGraph.getSqlDialect()); } index.createIndex(this.sqlgGraph, SchemaTable.of(getAbstractLabel().getSchema().getName(), this.getName()), indexName); } else { for (Partition partition : this.partitions.values()) { partition.createIndexOnLeafPartitions(index); } } }
public void createIndexOnLeafPartitions(Index index) { if (this.partitionType.isNone()) { //Append the partition name to the index name. String indexName = index.getName() + "_" + this.getName(); if (indexName.length() > this.sqlgGraph.getSqlDialect().getMaximumIndexNameLength()) { indexName = Index.generateName(this.sqlgGraph.getSqlDialect()); } index.createIndex(this.sqlgGraph, SchemaTable.of(getAbstractLabel().getSchema().getName(), this.getName()), indexName); } else { for (Partition partition : this.partitions.values()) { partition.createIndexOnLeafPartitions(index); } } }
static Index createIndex(SqlgGraph sqlgGraph, AbstractLabel abstractLabel, String indexName, IndexType indexType, List<PropertyColumn> properties) { Index index = new Index(indexName, indexType, abstractLabel, properties); SchemaTable schemaTable = SchemaTable.of(abstractLabel.getSchema().getName(), abstractLabel.getLabel()); //For partitioned tables the index is on each partition. //It is created when the partition is created. if (!abstractLabel.isPartition()) { String prefix = abstractLabel instanceof VertexLabel ? VERTEX_PREFIX : EDGE_PREFIX; index.createIndex(sqlgGraph, schemaTable.withPrefix(prefix), index.getName()); } else { for (Partition partition : abstractLabel.getPartitions().values()) { partition.createIndexOnLeafPartitions(index); } } TopologyManager.addIndex(sqlgGraph, index); index.committed = false; return index; }
static Index createIndex(SqlgGraph sqlgGraph, AbstractLabel abstractLabel, String indexName, IndexType indexType, List<PropertyColumn> properties) { Index index = new Index(indexName, indexType, abstractLabel, properties); SchemaTable schemaTable = SchemaTable.of(abstractLabel.getSchema().getName(), abstractLabel.getLabel()); //For partitioned tables the index is on each partition. //It is created when the partition is created. if (!abstractLabel.isPartition()) { String prefix = abstractLabel instanceof VertexLabel ? VERTEX_PREFIX : EDGE_PREFIX; index.createIndex(sqlgGraph, schemaTable.withPrefix(prefix), index.getName()); } else { for (Partition partition : abstractLabel.getPartitions().values()) { partition.createIndexOnLeafPartitions(index); } } TopologyManager.addIndex(sqlgGraph, index); index.committed = false; return index; }
SQLG_SCHEMA_INDEX_NAME, index.getName(), SQLG_SCHEMA_INDEX_INDEX_TYPE, index.getIndexType().toString(), CREATED_ON, LocalDateTime.now()
SQLG_SCHEMA_INDEX_NAME, index.getName(), SQLG_SCHEMA_INDEX_INDEX_TYPE, index.getIndexType().toString(), CREATED_ON, LocalDateTime.now()
traversalSource.V(v.id()) .out(abstractLabel instanceof VertexLabel ? SQLG_SCHEMA_VERTEX_INDEX_EDGE : SQLG_SCHEMA_EDGE_INDEX_EDGE) .has(SQLG_SCHEMA_INDEX_NAME, index.getName()) .out(SQLG_SCHEMA_INDEX_PROPERTY_EDGE) .drop() traversalSource.V(v.id()) .out(abstractLabel instanceof VertexLabel ? SQLG_SCHEMA_VERTEX_INDEX_EDGE : SQLG_SCHEMA_EDGE_INDEX_EDGE) .has(SQLG_SCHEMA_INDEX_NAME, index.getName()) .drop() .iterate();
traversalSource.V(v.id()) .out(abstractLabel instanceof VertexLabel ? SQLG_SCHEMA_VERTEX_INDEX_EDGE : SQLG_SCHEMA_EDGE_INDEX_EDGE) .has(SQLG_SCHEMA_INDEX_NAME, index.getName()) .out(SQLG_SCHEMA_INDEX_PROPERTY_EDGE) .drop() traversalSource.V(v.id()) .out(abstractLabel instanceof VertexLabel ? SQLG_SCHEMA_VERTEX_INDEX_EDGE : SQLG_SCHEMA_EDGE_INDEX_EDGE) .has(SQLG_SCHEMA_INDEX_NAME, index.getName()) .drop() .iterate();