neo4j 1.0.0.beta.26-java → 1.0.0.beta.27-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. data/bin/neo4j-shell +107 -0
  2. data/bin/neo4j-shell~ +108 -0
  3. data/config/locales/en.yml +5 -0
  4. data/config/neo4j/config.yml +89 -0
  5. data/lib/Gemfile~ +3 -0
  6. data/lib/config2.yml~ +86 -0
  7. data/lib/neo4j.rb +34 -8
  8. data/lib/neo4j/config.rb +41 -12
  9. data/lib/neo4j/database.rb +34 -13
  10. data/lib/neo4j/index/class_methods.rb +1 -1
  11. data/lib/neo4j/index/lucene_query.rb +4 -2
  12. data/lib/neo4j/jars/{geronimo-jta_1.1_spec-1.1.1.jar → core/geronimo-jta_1.1_spec-1.1.1.jar} +0 -0
  13. data/lib/neo4j/jars/{lucene-core-3.0.2.jar → core/lucene-core-3.0.3.jar} +0 -0
  14. data/lib/neo4j/jars/core/neo4j-graph-algo-0.8-SNAPSHOT.jar +0 -0
  15. data/lib/neo4j/jars/core/neo4j-index-1.3-SNAPSHOT.jar +0 -0
  16. data/lib/neo4j/jars/core/neo4j-kernel-1.3-SNAPSHOT.jar +0 -0
  17. data/lib/neo4j/jars/core/neo4j-lucene-index-0.5-SNAPSHOT.jar +0 -0
  18. data/lib/neo4j/jars/ha/log4j-1.2.16.jar +0 -0
  19. data/lib/neo4j/jars/ha/neo4j-ha-0.6-SNAPSHOT.jar +0 -0
  20. data/lib/neo4j/jars/ha/neo4j-management-1.3-SNAPSHOT.jar +0 -0
  21. data/lib/neo4j/jars/ha/neo4j-shell-1.3-SNAPSHOT.jar +0 -0
  22. data/lib/neo4j/jars/ha/netty-3.2.1.Final.jar +0 -0
  23. data/lib/neo4j/jars/ha/org.apache.servicemix.bundles.jline-0.9.94_1.jar +0 -0
  24. data/lib/neo4j/jars/ha/org.apache.servicemix.bundles.lucene-3.0.1_2.jar +0 -0
  25. data/lib/neo4j/jars/ha/zookeeper-3.3.2.jar +0 -0
  26. data/lib/neo4j/mapping/class_methods/relationship.rb +1 -2
  27. data/lib/neo4j/mapping/class_methods/rule.rb +35 -3
  28. data/lib/neo4j/mapping/decl_relationship_dsl.rb +1 -1
  29. data/lib/neo4j/mapping/has_n.rb +4 -1
  30. data/lib/neo4j/mapping/node_mixin.rb +1 -1
  31. data/lib/neo4j/mapping/rule.rb +9 -6
  32. data/lib/neo4j/mapping/rule_node.rb +0 -1
  33. data/lib/neo4j/migrations.rb +12 -0
  34. data/lib/neo4j/migrations/extensions.rb +57 -0
  35. data/lib/neo4j/migrations/global_migration.rb +29 -0
  36. data/lib/neo4j/migrations/lazy_migration_mixin.rb +47 -0
  37. data/lib/neo4j/migrations/migration.rb +109 -0
  38. data/lib/neo4j/migrations/migration_mixin.rb +78 -0
  39. data/lib/neo4j/migrations/migrations.rb +100 -0
  40. data/lib/neo4j/neo4j.rb +33 -9
  41. data/lib/neo4j/node_relationship.rb +2 -4
  42. data/lib/neo4j/node_traverser.rb +5 -0
  43. data/lib/neo4j/rails/finders.rb +10 -3
  44. data/lib/neo4j/rails/lucene_connection_closer.rb +1 -2
  45. data/lib/neo4j/rails/mapping/property.rb +1 -1
  46. data/lib/neo4j/rails/model.rb +1 -1
  47. data/lib/neo4j/rails/persistence.rb +1 -5
  48. data/lib/neo4j/rails/relationships/relationships.rb +13 -10
  49. data/lib/neo4j/version.rb +1 -1
  50. data/lib/perf.rb~ +36 -0
  51. data/neo4j.gemspec +4 -2
  52. metadata +40 -78
  53. data/lib/neo4j/jars/neo4j-graph-algo-0.7-1.2.jar +0 -0
  54. data/lib/neo4j/jars/neo4j-index-1.2-1.2.jar +0 -0
  55. data/lib/neo4j/jars/neo4j-kernel-1.2-1.2.jar +0 -0
  56. data/lib/neo4j/jars/neo4j-lucene-index-0.2-1.2.jar +0 -0
  57. data/lib/tmp/neo4j/active_tx_log +0 -1
  58. data/lib/tmp/neo4j/index.db +0 -0
  59. data/lib/tmp/neo4j/index/lucene-store.db +0 -0
  60. data/lib/tmp/neo4j/index/lucene.log.active +0 -0
  61. data/lib/tmp/neo4j/index/lucene/node/Network-exact/_0.cfs +0 -0
  62. data/lib/tmp/neo4j/index/lucene/node/Network-exact/segments.gen +0 -0
  63. data/lib/tmp/neo4j/index/lucene/node/Network-exact/segments_2 +0 -0
  64. data/lib/tmp/neo4j/lucene-fulltext/lucene-store.db +0 -0
  65. data/lib/tmp/neo4j/lucene-fulltext/lucene.log.active +0 -0
  66. data/lib/tmp/neo4j/lucene/lucene-store.db +0 -0
  67. data/lib/tmp/neo4j/lucene/lucene.log.active +0 -0
  68. data/lib/tmp/neo4j/messages.log +0 -85
  69. data/lib/tmp/neo4j/neostore +0 -0
  70. data/lib/tmp/neo4j/neostore.id +0 -0
  71. data/lib/tmp/neo4j/neostore.nodestore.db +0 -0
  72. data/lib/tmp/neo4j/neostore.nodestore.db.id +0 -0
  73. data/lib/tmp/neo4j/neostore.propertystore.db +0 -0
  74. data/lib/tmp/neo4j/neostore.propertystore.db.arrays +0 -0
  75. data/lib/tmp/neo4j/neostore.propertystore.db.arrays.id +0 -0
  76. data/lib/tmp/neo4j/neostore.propertystore.db.id +0 -0
  77. data/lib/tmp/neo4j/neostore.propertystore.db.index +0 -0
  78. data/lib/tmp/neo4j/neostore.propertystore.db.index.id +0 -0
  79. data/lib/tmp/neo4j/neostore.propertystore.db.index.keys +0 -0
  80. data/lib/tmp/neo4j/neostore.propertystore.db.index.keys.id +0 -0
  81. data/lib/tmp/neo4j/neostore.propertystore.db.strings +0 -0
  82. data/lib/tmp/neo4j/neostore.propertystore.db.strings.id +0 -0
  83. data/lib/tmp/neo4j/neostore.relationshipstore.db +0 -0
  84. data/lib/tmp/neo4j/neostore.relationshipstore.db.id +0 -0
  85. data/lib/tmp/neo4j/neostore.relationshiptypestore.db +0 -0
  86. data/lib/tmp/neo4j/neostore.relationshiptypestore.db.id +0 -0
  87. data/lib/tmp/neo4j/neostore.relationshiptypestore.db.names +0 -0
  88. data/lib/tmp/neo4j/neostore.relationshiptypestore.db.names.id +0 -0
  89. data/lib/tmp/neo4j/nioneo_logical.log.active +0 -0
  90. data/lib/tmp/neo4j/tm_tx_log.1 +0 -0
@@ -0,0 +1,29 @@
1
+ module Neo4j
2
+
3
+ # This node stores the migrations for Neo4j.migrations
4
+ # Uses the Neo4j.ref_node for keeping the current version of the db.
5
+ # When the database starts it will check if it needs to run a migration.
6
+ class GlobalMigration
7
+ extend Neo4j::Migrations
8
+
9
+ class << self
10
+ def migrate!(version=nil)
11
+ _migrate!(self, Neo4j.ref_node, version)
12
+ end
13
+
14
+ def db_version
15
+ Neo4j.ref_node[:_db_version] || 0
16
+ end
17
+
18
+ # Remote all migration and set migrate_to = nil and set the current version to nil
19
+ def reset_migrations!
20
+ @migrations = nil
21
+ @migrate_to = nil
22
+ Neo4j::Transaction.run do
23
+ Neo4j.ref_node[:_db_version] = nil
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,47 @@
1
+ module Neo4j
2
+
3
+ # Overrides the init_on_load method so that it will check if any migration is needed.
4
+ # The init_on_create method is also overriden so that it sets the version to the latest migration number
5
+ # when a new node is created.
6
+ #
7
+ # Migration will take place if needed when the node is loaded.
8
+ #
9
+ module LazyMigrationMixin
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ extend Neo4j::Migrations
14
+ end
15
+
16
+ module ClassMethods
17
+ # Remote all migration and set migrate_to = nil
18
+ # Does not change the version of nodes.
19
+ def reset_migrations!
20
+ @migrations = nil
21
+ @migrate_to = nil
22
+ end
23
+ end
24
+
25
+ def migrate!
26
+ self.class._migrate!(self._java_node, self)
27
+ end
28
+
29
+ def init_on_create(*)
30
+ super
31
+ # set the db version to the current
32
+ self[:_db_version] = self.class.migrate_to
33
+ end
34
+
35
+ def init_on_load(*) # :nodoc:
36
+ super
37
+ migrate!
38
+ # this if for Neo4j::Rails::Model which keeps the properties in this variable
39
+ @properties.clear if instance_variable_defined? :@properties
40
+ end
41
+
42
+ def db_version
43
+ self[:_db_version]
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,109 @@
1
+ module Neo4j
2
+
3
+ # This is the context in which the Migrations DSL are evaluated in.
4
+ # This class is also responsible for running the migrations.
5
+ class Migration
6
+ attr_reader :up_block, :down_block, :up_migrator, :down_migrator, :version, :name
7
+
8
+ def initialize(version, name)
9
+ @auto_transaction = true
10
+ @version = version
11
+ @name = name
12
+ end
13
+
14
+ # Specifies a code block which is run when the migration is upgraded.
15
+ #
16
+ def up(&block)
17
+ @up_block = block
18
+ end
19
+
20
+ # Specifies a code block which is run when the migration is upgraded.
21
+ #
22
+ def down(&block)
23
+ @down_block = block
24
+ end
25
+
26
+ # Specifies if transaction should automatically be created (default)
27
+ def auto_transaction(run_with_auto_tx)
28
+ @auto_transaction = run_with_auto_tx
29
+ end
30
+
31
+
32
+ # Specifies which fields should be indexed
33
+ def add_index(*fields)
34
+ @add_indexed_field = fields
35
+ end
36
+
37
+ # Specifies which fields indexed should be removed
38
+ def rm_index(*fields)
39
+ @rm_indexed_field = fields
40
+ end
41
+
42
+ # Runs the up migration. If successful it will set the property
43
+ # ':_db_version' on the given context.
44
+ #
45
+ # === Parameters
46
+ # context:: the context on which the block is evaluated in
47
+ # meta_node:: the node on which to set the 'db_version' property
48
+ #
49
+ def execute_up(context, meta_node)
50
+
51
+ if @auto_transaction
52
+ Neo4j::Transaction.run do
53
+ context.instance_eval &@up_block if @up_block
54
+ add_index_on(context, @add_indexed_field) if @add_indexed_field
55
+ rm_index_on(context, @rm_indexed_field) if @rm_indexed_field
56
+ meta_node._java_node[:_db_version] = version # use the raw java node since Neo4j::Rails::Mode wraps it
57
+ end
58
+ else
59
+ context.instance_eval &@up_block if @up_block
60
+ add_index_on(context, @add_indexed_field) if @add_indexed_field
61
+ Neo4j::Transaction.run do
62
+ rm_index_on(context, @rm_indexed_field) if @rm_indexed_field
63
+ meta_node._java_node[:_db_version] = version # use the raw java node since Neo4j::Rails::Mode wraps it
64
+ end
65
+ end
66
+ end
67
+
68
+ # Same as #execute_up but executes the down_block instead
69
+ def execute_down(context, meta_node)
70
+ if @auto_transaction
71
+ Neo4j::Transaction.run do
72
+ context.instance_eval &@down_block if @down_block
73
+ add_index_on(context, @rm_indexed_field) if @rm_indexed_field
74
+ rm_index_on(context, @add_indexed_field) if @add_indexed_field
75
+ meta_node._java_node[:_db_version] = version - 1
76
+ end
77
+ else
78
+ context.instance_eval &@down_block if @down_block
79
+ add_index_on(context, @rm_indexed_field) if @rm_indexed_field
80
+ Neo4j::Transaction.run do
81
+ rm_index_on(context, @add_indexed_field) if @add_indexed_field
82
+ meta_node._java_node[:_db_version] = version - 1
83
+ end
84
+ end
85
+ end
86
+
87
+ def add_index_on(context, fields) #:nodoc:
88
+ context.all.each do |node|
89
+ fields.each do |field|
90
+ node.add_index(field)
91
+ end
92
+ end
93
+ end
94
+
95
+ def rm_index_on(context, fields) #:nodoc:
96
+ context.all.each do |node|
97
+ fields.each do |field|
98
+ node.rm_index(field)
99
+ end
100
+ end
101
+ end
102
+
103
+
104
+ def to_s
105
+ "Migration version: #{version}, name: #{name}"
106
+ end
107
+ end
108
+
109
+ end
@@ -0,0 +1,78 @@
1
+ module Neo4j
2
+
3
+
4
+ # By including this mixing on a node class one can add migrations to it.
5
+ # Each class has a unique db version.
6
+ #
7
+ # ==== Example
8
+ #
9
+ # class Person
10
+ # include Neo4j::NodeMixin
11
+ # include MigrationMixin
12
+ # rule :all # adding the method all to make it possible to find all nodes of this class
13
+ # end
14
+ #
15
+ # Person.migration 1, :split_property do
16
+ # up do
17
+ # all.each_raw do |node|
18
+ # node[:given_name] = node[:name].split[0]
19
+ # node[:surname] = node[:name].split[1]
20
+ # node[:name] = nil
21
+ # end
22
+ # end
23
+ #
24
+ # down do
25
+ # all.each_raw do |node|
26
+ # node[:name] = "#{node[:given_name]} #{node[:surname]}"
27
+ # node[:surename] = nil
28
+ # node[:given_name] = nil
29
+ # end
30
+ # end
31
+ # end
32
+ #
33
+ # Notice that the up and down methods are evaluated in the context of the class (where the all method is defined
34
+ # if using the rule :all).
35
+ #
36
+ module MigrationMixin
37
+ extend ActiveSupport::Concern
38
+
39
+ included do
40
+ extend Neo4j::Migrations
41
+ end
42
+
43
+ module ClassMethods
44
+ def migrate!(version=nil)
45
+ _migrate!(self, migration_meta_node, version)
46
+ end
47
+
48
+ # The node that holds the db version property
49
+ def migration_meta_node
50
+ Neo4j::Mapping::Rule.rule_node_for(self).rule_node
51
+ end
52
+
53
+ # Remote all migration and set migrate_to = nil and set the current version to nil
54
+ def reset_migrations!
55
+ @migrations = nil
56
+ @migrate_to = nil
57
+ Neo4j::Transaction.run do
58
+ migration_meta_node[:_db_version] = nil
59
+ end
60
+ end
61
+
62
+ # sets the migration db version for this class on a 'meta' node.
63
+ def db_version=(version)
64
+ Neo4j::Transaction.run do
65
+ migration_meta_node[:_db_version] = version
66
+ end
67
+ end
68
+
69
+ # returns the current version of the database for this class.
70
+ def db_version
71
+ migration_meta_node[:_db_version]
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+
78
+ end
@@ -0,0 +1,100 @@
1
+ module Neo4j
2
+ module Migrations
3
+
4
+ # Sets the the version we request to migrate to
5
+ # If not set will migrate to the highest possible migration
6
+ def migrate_to=(version)
7
+ @migrate_to = version
8
+ end
9
+
10
+ def migrate_to
11
+ @migrate_to
12
+ end
13
+
14
+ def latest_migration
15
+ migrations.keys.sort.reverse[0]
16
+ end
17
+
18
+ # contains all the migrations defined with the #migration DSL method
19
+ def migrations
20
+ @migrations ||= {}
21
+ end
22
+
23
+ # Specifies a migration to be performed.
24
+ # Updates the migrate_to variable so that it will migrate to the latest migration.
25
+ #
26
+ # === Example
27
+ #
28
+ # In the following example the up and down method will be evaluated in the context of a Person node.
29
+ #
30
+ # Person.migration 1, :my_first_migration do
31
+ # up { ... }
32
+ # down { ... }
33
+ # end
34
+ #
35
+ # See the Neo4j::MigrationMixin::Migration which the DSL is evaluated in.
36
+ #
37
+ def migration(version, name, &block)
38
+ migration = Migration.new(version, name)
39
+ migration.instance_eval(&block)
40
+ migrations[version] = migration
41
+ self.migrate_to = latest_migration
42
+ end
43
+
44
+
45
+ def _migrate!(context, meta_node, version=nil) #:nodoc:
46
+ # set the version we want to migrate to if provided
47
+ self.migrate_to = version if version
48
+
49
+ # requested to migrate to a version ?
50
+ return if self.migrate_to.nil?
51
+
52
+ # which version are we on now ?
53
+ current_version = meta_node[:_db_version] || 0
54
+
55
+ # do we need to migrate ?
56
+ return if current_version == self.migrate_to
57
+
58
+ # ok, so we are running some migrations
59
+ if Neo4j::Config['migration_thread']
60
+ Thread.new{ _upgrade_or_downgrade(current_version, context, meta_node)}
61
+ else
62
+ _upgrade_or_downgrade(current_version, context, meta_node)
63
+ end
64
+ end
65
+
66
+ def _upgrade_or_downgrade(current_version, context, meta_node) #:nodoc:
67
+ if (current_version < self.migrate_to)
68
+ upgrade((current_version+1).upto(self.migrate_to).collect { |ver| migrations[ver] }, context, meta_node)
69
+ else
70
+ downgrade(current_version.downto(self.migrate_to+1).collect { |ver| migrations[ver] }, context, meta_node)
71
+ end
72
+
73
+ end
74
+
75
+
76
+ # Running the up method on the given migrations.
77
+ #
78
+ # === Parameters
79
+ # migrations :: an enumerable of Migration objects
80
+ def upgrade(migrations, context, meta_node)
81
+ migrations.each do |m|
82
+ Neo4j.logger.info "Running upgrade: #{m}"
83
+ m.execute_up(context, meta_node)
84
+ end
85
+ end
86
+
87
+ # Running the down method on the given migrations.
88
+ #
89
+ # === Parameters
90
+ # migrations:: an enumerable of Migration objects
91
+ def downgrade(migrations, context, meta_node)
92
+ migrations.each do |m|
93
+ Neo4j.logger.info "Running downgrade: #{m}"
94
+ m.execute_down(context, meta_node)
95
+ end
96
+ end
97
+
98
+ end
99
+ end
100
+
data/lib/neo4j/neo4j.rb CHANGED
@@ -10,23 +10,27 @@
10
10
  module Neo4j
11
11
 
12
12
  class << self
13
-
14
13
  # Start Neo4j using the default database.
15
14
  # This is usally not required since the database will be started automatically when it is used.
16
15
  #
17
- def start
18
- db = default_db
16
+ # ==== Parameters
17
+ # config_file :: (optionally) if this is nil or not given use the Neo4j::Config, otherwise setup the Neo4j::Config file using the provided YAML configuration file.
18
+ #
19
+ def start(config_file=nil)
20
+ Neo4j.config.default_file = config_file if config_file
19
21
  db.start unless db.running?
20
22
  end
21
23
 
22
24
 
23
- # sets the default database to use
24
- def default_db=(my_db)
25
+ # Sets the Neo4j::Database instance to use
26
+ # An Neo4j::Database instance wraps both the Neo4j Database and Lucene Database.
27
+ def db=(my_db)
25
28
  @db = my_db
26
29
  end
27
30
 
28
- # Returns default database. Creates a new one if it does not exist, but does not start it.
29
- def default_db
31
+ # Returns the database holding references to both the Neo4j Graph Database and the Lucene Database.
32
+ # Creates a new one if it does not exist, but does not start it.
33
+ def db
30
34
  @db ||= Database.new
31
35
  end
32
36
 
@@ -36,11 +40,31 @@ module Neo4j
36
40
 
37
41
  # Returns a started db instance. Starts it's not running.
38
42
  def started_db
39
- db = default_db
40
43
  db.start unless db.running?
41
44
  db
42
45
  end
43
46
 
47
+ # Returns the Neo4j::Config class
48
+ # Same as typing; Neo4j::Config
49
+ def config
50
+ Neo4j::Config
51
+ end
52
+
53
+ def logger
54
+ @logger ||= Neo4j::Config[:logger] || default_logger
55
+ end
56
+
57
+ def logger=(logger)
58
+ @logger = logger
59
+ end
60
+
61
+ def default_logger #:nodoc:
62
+ require 'logger'
63
+ logger = Logger.new(STDOUT)
64
+ logger.sev_threshold = Neo4j::Config[:logger_level] || Logger::INFO
65
+ logger
66
+ end
67
+
44
68
 
45
69
  # Returns an unstarted db instance
46
70
  #
@@ -87,7 +111,7 @@ module Neo4j
87
111
 
88
112
  # Returns the Neo4j::EventHandler
89
113
  #
90
- def event_handler(this_db = default_db)
114
+ def event_handler(this_db = db)
91
115
  this_db.event_handler
92
116
  end
93
117
 
@@ -53,8 +53,7 @@ module Neo4j
53
53
  if type
54
54
  NodeTraverser.new(self).outgoing(type)
55
55
  else
56
- raise "not implemented yet"
57
- NodeTraverser.new(self)
56
+ raise "Not implemented getting all types of outgoing relationship. Specify a relationship type"
58
57
  end
59
58
  end
60
59
 
@@ -67,8 +66,7 @@ module Neo4j
67
66
  if type
68
67
  NodeTraverser.new(self).incoming(type)
69
68
  else
70
- raise "not implemented yet"
71
- NodeTraverser.new(self)
69
+ raise "Not implemented getting all types of incoming relationship. Specify a relationship type"
72
70
  end
73
71
  end
74
72