Sha256: 936cd4de96bb5d150d8021b3a719d90f0cb84b72b8f6a3bbd1be4a74a7caf9ec

Contents?: true

Size: 1.59 KB

Versions: 57

Compression:

Stored size: 1.59 KB

Contents

module Neo4j
  class Label
    class << self
      def indexes
        schema_query(:get_indexes)
      end

      def constraints
        schema_query(:get_constraints)
      end

      def index?(label, property)
        schema_index_operation(label, property, :indexes)
      end

      def constraint?(label, property)
        schema_index_operation(label, property, :constraints)
      end

      def drop_all_indexes
        Neo4j::Transaction.run do
          schema.get_indexes.to_a.each do |i|
            begin
              i.drop
            rescue Java::JavaLang::IllegalStateException
            end
          end
        end
      end

      def drop_all_constraints
        Neo4j::Transaction.run do
          schema.get_constraints.to_a.each(&:drop)
        end
      end

      private

      def schema_query(query_method)
        [].tap do |index_array|
          Neo4j::Transaction.run do
            schema.send(query_method).to_a.each { |i| index_array << index_hash(i) }
          end
        end
      end

      def schema_index_operation(label, property, schema_method)
        label = label.to_s
        property = property.to_s
        !send(schema_method).select { |i| matched_index(i, label, property) }.empty?
      end

      def index_hash(java_index)
        {property_keys: java_index.get_property_keys.to_a, label: java_index.get_label.name}
      end

      def matched_index(java_index, label, property)
        java_index[:property_keys].first == property && java_index[:label] == label
      end

      def schema
        Neo4j::Session.current.graph_db.schema
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
neo4j-core-7.0.7 lib/neo4j-embedded/label.rb
neo4j-core-7.0.6 lib/neo4j-embedded/label.rb
neo4j-core-7.0.5 lib/neo4j-embedded/label.rb
neo4j-core-7.0.4 lib/neo4j-embedded/label.rb
neo4j-core-7.0.3 lib/neo4j-embedded/label.rb
neo4j-core-7.0.2 lib/neo4j-embedded/label.rb
neo4j-core-7.0.1 lib/neo4j-embedded/label.rb
neo4j-core-7.0.0 lib/neo4j-embedded/label.rb
neo4j-core-6.1.6 lib/neo4j-embedded/label.rb
neo4j-core-7.0.0.rc.2 lib/neo4j-embedded/label.rb
neo4j-core-7.0.0.rc.1 lib/neo4j-embedded/label.rb
neo4j-core-7.0.0.alpha.8 lib/neo4j-embedded/label.rb
neo4j-core-7.0.0.alpha.7 lib/neo4j-embedded/label.rb
neo4j-core-6.1.5 lib/neo4j-embedded/label.rb
neo4j-core-7.0.0.alpha.6 lib/neo4j-embedded/label.rb
neo4j-core-7.0.0.alpha.5 lib/neo4j-embedded/label.rb
neo4j-core-7.0.0.alpha.4 lib/neo4j-embedded/label.rb
neo4j-core-7.0.0.alpha.3 lib/neo4j-embedded/label.rb
neo4j-core-7.0.0.alpha.2 lib/neo4j-embedded/label.rb
neo4j-core-7.0.0.alpha.1 lib/neo4j-embedded/label.rb