Sha256: f8fca76b47d25747739d36ad156adfd3b6fafc1a993d2b2ec6e26d1ff0078400

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

module Cadet
  module BatchInserter
    class Session < Cadet::Session

      def initialize(db)
        @index_provider = CadetIndex::IndexProvider.new(db)
        super db
      end

      def close
        @index_provider.shutdown
        super
      end

      def self.open(location, config = {})
        new org.neo4j.unsafe.batchinsert.BatchInserters.inserter(location, config)
      end

      def constraint(label, property)
        @db.createDeferredConstraint(DynamicLabel.label(label))
          .assertPropertyIsUnique(property)
          .create()
      end

      def find_node(label, property, value)
        index = @index_provider.nodeIndex(label)

        (node = index.get(property.to_sym, value).first) ?
          Node.new(node, @db) : nil
      end

      def create_node(label, properties, indexing_property = nil)
        Node.new(@db.createNode(properties.inject({}){|result,(k,v)| result[k.to_java_string] = v; result}, DynamicLabel.label(label)), @db).tap do |n|
          @index_provider.nodeIndex(label).add(n.underlying, indexing_property.to_sym, properties[indexing_property]) if indexing_property
        end
      end

      def get_transaction
        Cadet::BatchInserter::Transaction.new(self)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cadet-0.0.9-java lib/cadet/batch_inserter/session.rb
cadet-0.0.8-java lib/cadet/batch_inserter/session.rb