maglevrecord 0.0.3 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +35 -0
- data/.travis.yml +19 -0
- data/Gemfile +13 -0
- data/README.md +89 -0
- data/Rakefile +22 -0
- data/install.sh +238 -0
- data/lib/maglev_record/base.rb +10 -62
- data/lib/maglev_record/enumerable.rb +13 -24
- data/lib/maglev_record/errors.rb +10 -0
- data/lib/maglev_record/integration.rb +7 -0
- data/lib/maglev_record/maglev_record.rb +13 -0
- data/lib/maglev_record/maglev_support/active_support_patch.rb +31 -0
- data/lib/maglev_record/maglev_support/concern.rb +19 -0
- data/lib/maglev_record/maglev_support/maglev_support.rb +15 -0
- data/lib/maglev_record/maglev_support/secure_password.rb +39 -0
- data/lib/maglev_record/migration/loader.rb +38 -0
- data/lib/maglev_record/migration/migration.rb +142 -0
- data/lib/maglev_record/migration/migrator.rb +40 -0
- data/lib/maglev_record/migration/operations.rb +92 -0
- data/lib/maglev_record/migration.rb +5 -0
- data/lib/maglev_record/persistence.rb +23 -48
- data/lib/maglev_record/raketasks.rb +9 -0
- data/lib/maglev_record/read_write.rb +20 -10
- data/lib/maglev_record/rooted_base.rb +8 -0
- data/lib/maglev_record/rooted_enumerable.rb +25 -0
- data/lib/maglev_record/rooted_persistence.rb +36 -0
- data/lib/maglev_record/sensible.rb +28 -0
- data/lib/maglev_record/snapshot/change.rb +53 -0
- data/lib/maglev_record/snapshot/snapshot.rb +67 -0
- data/lib/maglev_record/snapshot/snapshotable.rb +58 -0
- data/lib/maglev_record/snapshot.rb +5 -0
- data/lib/maglev_record/tools/object_reference.rb +189 -0
- data/lib/maglev_record/tools/submodule_finder.rb +42 -0
- data/lib/maglev_record/tools.rb +2 -0
- data/lib/maglev_record.rb +60 -4
- data/lib/tasks/database.rake +38 -0
- data/maglevrecord.gemspec +17 -0
- data/rails/init.rb +1 -0
- data/test/_test_object_reference.rb +70 -0
- data/test/example_model.rb +26 -13
- data/test/migration/dummy_migrations/migration_1.rb +8 -0
- data/test/migration/dummy_migrations/migration_2.rb +8 -0
- data/test/migration/dummy_migrations/migration_3.rb +8 -0
- data/test/migration/migrations/migration_1.rb +12 -0
- data/test/migration/migrations/migration_2.rb +12 -0
- data/test/migration/migrations/migration_3.rb +12 -0
- data/test/migration/operation_setup.rb +91 -0
- data/test/migration/projects/project1/.gitignore +15 -0
- data/test/migration/projects/project1/Gemfile +43 -0
- data/test/migration/projects/project1/Gemfile.lock +114 -0
- data/test/migration/projects/project1/README.rdoc +261 -0
- data/test/migration/projects/project1/Rakefile +17 -0
- data/test/migration/projects/project1/app/assets/images/rails.png +0 -0
- data/test/migration/projects/project1/app/assets/javascripts/application.js +15 -0
- data/test/migration/projects/project1/app/assets/stylesheets/application.css +13 -0
- data/test/migration/projects/project1/app/controllers/application_controller.rb +3 -0
- data/test/migration/projects/project1/app/helpers/application_helper.rb +2 -0
- data/test/migration/projects/project1/app/mailers/.gitkeep +0 -0
- data/test/migration/projects/project1/app/models/.gitkeep +0 -0
- data/test/migration/projects/project1/app/views/layouts/application.html.erb +14 -0
- data/test/migration/projects/project1/config/application.rb +62 -0
- data/test/migration/projects/project1/config/boot.rb +6 -0
- data/test/migration/projects/project1/config/database.yml +25 -0
- data/test/migration/projects/project1/config/environment.rb +5 -0
- data/test/migration/projects/project1/config/environments/development.rb +37 -0
- data/test/migration/projects/project1/config/environments/production.rb +67 -0
- data/test/migration/projects/project1/config/initializers/backtrace_silencers.rb +7 -0
- data/test/migration/projects/project1/config/initializers/inflections.rb +15 -0
- data/test/migration/projects/project1/config/initializers/mime_types.rb +5 -0
- data/test/migration/projects/project1/config/initializers/secret_token.rb +7 -0
- data/test/migration/projects/project1/config/initializers/session_store.rb +8 -0
- data/test/migration/projects/project1/config/initializers/wrap_parameters.rb +14 -0
- data/test/migration/projects/project1/config/locales/en.yml +5 -0
- data/test/migration/projects/project1/config/routes.rb +58 -0
- data/test/migration/projects/project1/config.ru +4 -0
- data/test/migration/projects/project1/db/seeds.rb +7 -0
- data/test/migration/projects/project1/lib/assets/.gitkeep +0 -0
- data/test/migration/projects/project1/lib/tasks/.gitkeep +0 -0
- data/test/migration/projects/project1/log/.gitkeep +0 -0
- data/test/migration/projects/project1/public/404.html +26 -0
- data/test/migration/projects/project1/public/422.html +26 -0
- data/test/migration/projects/project1/public/500.html +25 -0
- data/test/migration/projects/project1/public/favicon.ico +0 -0
- data/test/migration/projects/project1/public/index.html +241 -0
- data/test/migration/projects/project1/public/robots.txt +5 -0
- data/test/migration/projects/project1/script/rails +6 -0
- data/test/migration/projects/project2/.gitignore +15 -0
- data/test/migration/projects/project2/Gemfile +44 -0
- data/test/migration/projects/project2/Gemfile.lock +115 -0
- data/test/migration/projects/project2/README.rdoc +261 -0
- data/test/migration/projects/project2/Rakefile +17 -0
- data/test/migration/projects/project2/app/assets/images/rails.png +0 -0
- data/test/migration/projects/project2/app/assets/javascripts/application.js +15 -0
- data/test/migration/projects/project2/app/assets/stylesheets/application.css +13 -0
- data/test/migration/projects/project2/app/controllers/application_controller.rb +3 -0
- data/test/migration/projects/project2/app/helpers/application_helper.rb +2 -0
- data/test/migration/projects/project2/app/mailers/.gitkeep +0 -0
- data/test/migration/projects/project2/app/models/.gitkeep +0 -0
- data/test/migration/projects/project2/app/models/project_model.rb +8 -0
- data/test/migration/projects/project2/app/views/layouts/application.html.erb +14 -0
- data/test/migration/projects/project2/config/application.rb +62 -0
- data/test/migration/projects/project2/config/boot.rb +6 -0
- data/test/migration/projects/project2/config/database.yml +25 -0
- data/test/migration/projects/project2/config/environment.rb +5 -0
- data/test/migration/projects/project2/config/environments/development.rb +37 -0
- data/test/migration/projects/project2/config/environments/production.rb +67 -0
- data/test/migration/projects/project2/config/initializers/backtrace_silencers.rb +7 -0
- data/test/migration/projects/project2/config/initializers/inflections.rb +15 -0
- data/test/migration/projects/project2/config/initializers/mime_types.rb +5 -0
- data/test/migration/projects/project2/config/initializers/secret_token.rb +7 -0
- data/test/migration/projects/project2/config/initializers/session_store.rb +8 -0
- data/test/migration/projects/project2/config/initializers/wrap_parameters.rb +14 -0
- data/test/migration/projects/project2/config/locales/en.yml +5 -0
- data/test/migration/projects/project2/config/routes.rb +58 -0
- data/test/migration/projects/project2/config.ru +4 -0
- data/test/migration/projects/project2/db/seeds.rb +7 -0
- data/test/migration/projects/project2/lib/assets/.gitkeep +0 -0
- data/test/migration/projects/project2/lib/tasks/.gitkeep +0 -0
- data/test/migration/projects/project2/log/.gitkeep +0 -0
- data/test/migration/projects/project2/migrations/migration_2013-04-Apr-23_17.31.38.rb +16 -0
- data/test/migration/projects/project2/migrations/migration_2013-04-Apr-23_17.31.52.rb +16 -0
- data/test/migration/projects/project2/migrations/migration_2013-04-Apr-23_17.32.07.rb +16 -0
- data/test/migration/projects/project2/public/404.html +26 -0
- data/test/migration/projects/project2/public/422.html +26 -0
- data/test/migration/projects/project2/public/500.html +25 -0
- data/test/migration/projects/project2/public/favicon.ico +0 -0
- data/test/migration/projects/project2/public/index.html +241 -0
- data/test/migration/projects/project2/public/robots.txt +5 -0
- data/test/migration/projects/project2/script/rails +6 -0
- data/test/migration/test_loader.rb +78 -0
- data/test/migration/test_migration.rb +127 -0
- data/test/migration/test_nonexistent_classes.rb +120 -0
- data/test/migration/test_operations_fit_together.rb +68 -0
- data/test/migration/test_project.rb +105 -0
- data/test/migration/test_project1.slow.rb +58 -0
- data/test/migration/test_project2.slow.rb +34 -0
- data/test/migration/test_remove.rb +219 -0
- data/test/migration/test_rename.rb +238 -0
- data/test/migration/test_scenario.rb +37 -0
- data/test/migration/todo.txt +17 -0
- data/test/more_asserts.rb +63 -0
- data/test/snapshot/test_snapshot.rb +99 -0
- data/test/snapshot/test_snapshot_attributes.slow.rb +57 -0
- data/test/snapshot/test_snapshot_classes.slow.rb +32 -0
- data/test/snapshot/test_snapshotable.rb +53 -0
- data/test/test_accessors.rb +46 -0
- data/test/test_active_model_like_interface.rb +1 -1
- data/test/test_model_timestamps.rb +22 -0
- data/test/test_more_asserts.rb +68 -0
- data/test/test_naming.rb +22 -0
- data/test/test_persistence.rb +127 -0
- data/test/test_query_interface.rb +20 -25
- data/test/test_sensibles.rb +38 -0
- data/test/test_validation.rb +20 -57
- data/todo.txt +1 -0
- data/update.sh +180 -0
- metadata +156 -12
- data/lib/maglev_record/model_not_saved_or_reset.rb +0 -15
- data/test/test_dirty_object.rb +0 -50
- data/test/test_maglev_record_base.rb +0 -22
- data/test/test_maglev_simple_persistance.rb +0 -45
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
# YARD artifacts
|
16
|
+
.yardoc
|
17
|
+
_yardoc
|
18
|
+
doc/
|
19
|
+
|
20
|
+
# gemstone files
|
21
|
+
gem_*_code.log
|
22
|
+
# gvim files
|
23
|
+
*.swp
|
24
|
+
|
25
|
+
/test.rb
|
26
|
+
|
27
|
+
*~
|
28
|
+
/*.lock
|
29
|
+
/activesupport/
|
30
|
+
/maglevrecord
|
31
|
+
/test2.rb
|
32
|
+
/test_input.txt
|
33
|
+
|
34
|
+
/caller_content.rb
|
35
|
+
/module_content.rb
|
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Java, because those are the 64bit boxes. We'll change it once Ruby
|
2
|
+
# boxes are 64bit, too
|
3
|
+
language: java
|
4
|
+
before_install:
|
5
|
+
- "sudo apt-get install -qq rake"
|
6
|
+
before_script:
|
7
|
+
- "./install.sh"
|
8
|
+
- "export MAGLEV_HOME=/home/travis/build/knub/maglevrecord/maglev"
|
9
|
+
- "export PATH=$MAGLEV_HOME/bin:$PATH"
|
10
|
+
- "gem uninstall -x -i /home/travis/.rvm/gems/ruby-1.9.3-p327@global bundler"
|
11
|
+
- "maglev-gem install bundler"
|
12
|
+
- "bundle install"
|
13
|
+
- "gem install maglevrecord"
|
14
|
+
script:
|
15
|
+
- "bundle exec rake testslow"
|
16
|
+
- "bundle exec rake testslow"
|
17
|
+
- "bundle exec rake testfast TESTOPTS='-v' TEST=test/_test_object_reference.rb"
|
18
|
+
notifications:
|
19
|
+
email: false
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# MagLevRecord - a model interface for Rails
|
2
|
+
|
3
|
+
master [![Build Status master](https://travis-ci.org/knub/maglevrecord.png?branch=master)](https://travis-ci.org/knub/maglevrecord)
|
4
|
+
develop [![Build Status develop](https://travis-ci.org/knub/maglevrecord.png?branch=develop)](https://travis-ci.org/knub/maglevrecord)
|
5
|
+
|
6
|
+
This is intended to replace ActiveRecord::Base when using MagLev. It is not ready for production use, but feel free to play around with it.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
You can install this gem from rubygems.org:
|
11
|
+
```gem install maglevrecord```
|
12
|
+
|
13
|
+
|
14
|
+
## Basic Usage
|
15
|
+
|
16
|
+
### Creating classes
|
17
|
+
|
18
|
+
Classes which you wish to persist have to include ```MaglevRecord::Base``` or ```MaglevRecord::RootedBase```. You can still inherit from whatever base class you want.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require 'maglev_record'
|
22
|
+
|
23
|
+
class Book
|
24
|
+
include MaglevRecord::RootedBase
|
25
|
+
|
26
|
+
attr_accessor :author, :title, :comments
|
27
|
+
end
|
28
|
+
```
|
29
|
+
Use attr_reader, attr_writer or attr_accessor to define your fields and use the generated getters and setters to access them. Do not access the instance variables directly, because we might need to do some background work when accessing and setting in future versions.
|
30
|
+
|
31
|
+
### Saving
|
32
|
+
|
33
|
+
There is a significant difference between ActiveRecord and MaglevRecord: ActiveRecord features an object-wise saving mechanism, whereas **MaglevRecord can only save all objects marked as persistent at once**. That is the Smalltalk image idea: make some changes and then save the whole world.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
book = Book.new(:title => "A new book", :author => "The writer")
|
37
|
+
another_book = Book.new(:title => "Another new book", :author => "The writer")
|
38
|
+
MaglevRecord.save
|
39
|
+
```
|
40
|
+
|
41
|
+
*Important:* When using MaglevRecord in a Rails app, unsaved changes are lost at the end of the request (die to an automatic request-wrapper).
|
42
|
+
|
43
|
+
### Accessing model objects
|
44
|
+
|
45
|
+
Rooted model classes (```ActiveRecord::RootedBase```) implement ```Enumerable```, so you can just use the normal collection API.
|
46
|
+
You can use these methods for queries. Dynamic finders and indexes will be implemented later.
|
47
|
+
```ruby
|
48
|
+
book = Book.find { |b| b.author == "The writer" }
|
49
|
+
#book.select
|
50
|
+
#book.map
|
51
|
+
#etc.
|
52
|
+
```
|
53
|
+
|
54
|
+
Ordinary model classes (```ActiveRecord::Base```) do not provide a mechanism access such models directly. They are used only for referencing such models from other models, i.e. if the model is not reachable from a rooted model, the garbage collector will remove it after some time.
|
55
|
+
|
56
|
+
### Deleting models
|
57
|
+
|
58
|
+
Rooted models can be deleted with ```delete```.
|
59
|
+
|
60
|
+
*Warning:* This will only remove the model from the enumeration of all models. This model will not be removed until the last reachable reference to it is removed.
|
61
|
+
|
62
|
+
### Validation
|
63
|
+
|
64
|
+
MaglevRecord supports model validation via ActiveModel.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
require 'maglev_record'
|
68
|
+
|
69
|
+
class Book
|
70
|
+
include MaglevRecord::Base
|
71
|
+
|
72
|
+
validates :author, :presence => true
|
73
|
+
validates :title, :presence => true,
|
74
|
+
:length => { :minimum => 5 }
|
75
|
+
|
76
|
+
attr_accessor :author, :title, :comments
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
Using ```book.valid?``` you can determine if a model is valid. Models are *not* automatically validated on global save.
|
81
|
+
|
82
|
+
### Resetting objects
|
83
|
+
|
84
|
+
Use ```MaglevRecord.reset``` the reset all changed made since the last save or reset.
|
85
|
+
|
86
|
+
## Further questions, improvements?
|
87
|
+
|
88
|
+
Feel free to fork, pull-request or ask via email at bp2012h1 [at] hpi.uni-potsdam.de.
|
89
|
+
We are actively developing this and hope for feedback.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'logger'
|
4
|
+
$LOAD_PATH << './lib'
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs << 'test'
|
8
|
+
t.name = 'testfast'
|
9
|
+
t.test_files = FileList['test/**/test*.rb'] - FileList['test/**/test*.slow.rb']
|
10
|
+
t.ruby_opts << "-W0 -rubygems --stone test"
|
11
|
+
end
|
12
|
+
|
13
|
+
Rake::TestTask.new do |t|
|
14
|
+
t.libs << 'test'
|
15
|
+
t.name = 'testslow'
|
16
|
+
t.test_files = FileList['test/**/test*.rb']
|
17
|
+
t.ruby_opts << "-W0 -rubygems --stone test"
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Run tests"
|
21
|
+
|
22
|
+
task :default => :testfast
|
data/install.sh
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
#! /bin/bash
|
2
|
+
|
3
|
+
#=========================================================================
|
4
|
+
# Copyright (C) GemStone Systems, Inc. 2010.
|
5
|
+
#
|
6
|
+
# Name - install.sh
|
7
|
+
#
|
8
|
+
# Purpose - Make sure MagLev and GemStone are setup correctly in a fresh clone
|
9
|
+
# of MagLev from git://github.com:MagLev/maglev.git. You only need
|
10
|
+
# to run this once, you can use update.sh from then on.
|
11
|
+
#
|
12
|
+
# Be both verbose and idempotent, so we can easily diagnose
|
13
|
+
# any problems.
|
14
|
+
#
|
15
|
+
# $Id:$
|
16
|
+
#
|
17
|
+
# Description:
|
18
|
+
# Does a basic setup of memory and services for MagLev
|
19
|
+
# Setup for manual MagLev startup rather than automatic startup upon boot
|
20
|
+
# Safe to run multiple times. Only saves one prior backup repository though.
|
21
|
+
# Requires root access (using sudo) to change setings and create directories
|
22
|
+
#
|
23
|
+
# Actions:
|
24
|
+
# Verify machine is capable of running MagLev 64-bit
|
25
|
+
# Add shared memory setup to /etc/sysctl.conf
|
26
|
+
# Add GemStone netldi service port to /etc/services
|
27
|
+
# Invoke update.sh to finish the job
|
28
|
+
#=========================================================================
|
29
|
+
|
30
|
+
echo $PWD
|
31
|
+
git clone https://github.com/MagLev/maglev.git
|
32
|
+
cd maglev
|
33
|
+
git checkout stefan/maglevrecord
|
34
|
+
|
35
|
+
if [ -x bin/maglev-ruby ]; then
|
36
|
+
# echo "using $PWD as MAGLEV_HOME"
|
37
|
+
export MAGLEV_HOME=$PWD
|
38
|
+
else
|
39
|
+
echo "[Error] $PWD is not a valid MagLev directory"
|
40
|
+
echo "To fix this, 'clone git://github.com:MagLev/maglev.git'"
|
41
|
+
echo "then run install.sh from the resulting directory."
|
42
|
+
exit 1
|
43
|
+
fi
|
44
|
+
|
45
|
+
# Check that the parent directory is writable
|
46
|
+
if [ ! -w ".." ]; then
|
47
|
+
echo "[Error] This script requires write permission on the MagLev parent directory."
|
48
|
+
/bin/ls -ld ..
|
49
|
+
echo "To fix this, 'chmod u+w ..'"
|
50
|
+
exit 1
|
51
|
+
fi
|
52
|
+
|
53
|
+
# Detect operating system
|
54
|
+
PLATFORM="`uname -sm | tr ' ' '-'`"
|
55
|
+
# Macs with Core i7 use the same software as older Macs
|
56
|
+
[ $PLATFORM = "Darwin-x86_64" ] && PLATFORM="Darwin-i386"
|
57
|
+
|
58
|
+
# Check we're on a suitable 64-bit machine
|
59
|
+
case "$PLATFORM" in
|
60
|
+
Darwin-i386)
|
61
|
+
OSVERSION="`sw_vers -productVersion`"
|
62
|
+
MAJOR="`echo $OSVERSION | cut -f1 -d.`"
|
63
|
+
MINOR="`echo $OSVERSION | cut -f2 -d.`"
|
64
|
+
CPU_TYPE="`uname -p`"
|
65
|
+
CPU_CAPABLE="`sysctl hw.cpu64bit_capable | cut -f2 -d' '`"
|
66
|
+
#
|
67
|
+
# Check the CPU and Mac OS X profile.
|
68
|
+
if [[ $CPU_TYPE != "i386" || $CPU_CAPABLE -ne 1 || $MAJOR -lt 10 || $MINOR -lt 5 ]] ; then
|
69
|
+
echo "[Error] This script requires Mac OS X 10.5 or later on a 64-bit Intel CPU."
|
70
|
+
exit 1
|
71
|
+
fi
|
72
|
+
;;
|
73
|
+
Linux-x86_64)
|
74
|
+
# Linux looks OK
|
75
|
+
;;
|
76
|
+
SunOS-i86pc)
|
77
|
+
# Solaris X86 looks OK
|
78
|
+
;;
|
79
|
+
*)
|
80
|
+
echo "[Error] This script only works on a 64-bit Linux, Mac OS X, or Solaris-x86 machine"
|
81
|
+
echo "The result from \"uname -sm\" is \"`uname -sm`\""
|
82
|
+
exit 1
|
83
|
+
;;
|
84
|
+
esac
|
85
|
+
|
86
|
+
# We should run this as a normal user, not root.
|
87
|
+
if [ `id | cut -f2 -d= | cut -f1 -d\(` -eq 0 ]; then
|
88
|
+
echo "[Error] This script should be run as a normal user, not root."
|
89
|
+
exit 1
|
90
|
+
fi
|
91
|
+
|
92
|
+
# We're good to go. Let user know.
|
93
|
+
machine_name="`uname -n`"
|
94
|
+
echo "[Info] Configuring $machine_name to run MagLev"
|
95
|
+
|
96
|
+
# Do a trivial sudo to test we can and get the password prompt out of the way
|
97
|
+
sudo date
|
98
|
+
|
99
|
+
# Figure out how much total memory is installed
|
100
|
+
echo "[Info] Setting up shared memory"
|
101
|
+
#
|
102
|
+
# Ref: http://wiki.finkproject.org/index.php/Shared_Memory_Regions_on_Darwin
|
103
|
+
# Ref: http://developer.postgresql.org/pgdocs/postgres/kernel-resources.html
|
104
|
+
# Ref: http://www.idevelopment.info/data/Oracle/DBA_tips/Linux/LINUX_8.shtml
|
105
|
+
#
|
106
|
+
case "$PLATFORM" in
|
107
|
+
Linux-x86_64)
|
108
|
+
# use TotalMem: kB because Ubuntu doesn't have Mem: in Bytes
|
109
|
+
totalMemKB=`awk '/MemTotal:/{print($2);}' /proc/meminfo`
|
110
|
+
totalMem=$(($totalMemKB * 1024))
|
111
|
+
# Figure out the max shared memory segment size currently allowed
|
112
|
+
shmmax=`cat /proc/sys/kernel/shmmax`
|
113
|
+
# Figure out the max shared memory currently allowed
|
114
|
+
shmall=`cat /proc/sys/kernel/shmall`
|
115
|
+
;;
|
116
|
+
Darwin-i386)
|
117
|
+
totalMem="`sysctl hw.memsize | cut -f2 -d' '`"
|
118
|
+
# Figure out the max shared memory segment size currently allowed
|
119
|
+
shmmax="`sysctl kern.sysv.shmmax | cut -f2 -d' '`"
|
120
|
+
# Figure out the max shared memory currently allowed
|
121
|
+
shmall="`sysctl kern.sysv.shmall | cut -f2 -d' '`"
|
122
|
+
;;
|
123
|
+
SunOS-i86pc)
|
124
|
+
# TODO: figure memory needs for Solaris-x86
|
125
|
+
# Investigate project.max-shm-memory
|
126
|
+
totalMemMB="`/usr/sbin/prtconf | grep Memory | cut -f3 -d' '`"
|
127
|
+
totalMem=$(($totalMemMB * 1048576))
|
128
|
+
shmmax=$(($totalMem / 4))
|
129
|
+
shmall=$(($shmmax / 4096))
|
130
|
+
;;
|
131
|
+
*)
|
132
|
+
echo "[Error] Can't determine operating system. Check script."
|
133
|
+
exit 1
|
134
|
+
;;
|
135
|
+
esac
|
136
|
+
totalMemMB=$(($totalMem / 1048576))
|
137
|
+
shmmaxMB=$(($shmmax / 1048576))
|
138
|
+
shmallMB=$(($shmall / 256))
|
139
|
+
|
140
|
+
# Print current values
|
141
|
+
echo " Total memory available is $totalMemMB MB"
|
142
|
+
echo " Max shared memory segment size is $shmmaxMB MB"
|
143
|
+
echo " Max shared memory allowed is $shmallMB MB"
|
144
|
+
|
145
|
+
# Figure out the max shared memory segment size (shmmax) we want
|
146
|
+
# Use 75% of available memory but not more than 2GB
|
147
|
+
shmmaxNew=$(($totalMem * 3/4))
|
148
|
+
[ $shmmaxNew -gt 2147483648 ] && shmmaxNew=2147483648
|
149
|
+
shmmaxNewMB=$(($shmmaxNew / 1048576))
|
150
|
+
|
151
|
+
# Figure out the max shared memory allowed (shmall) we want
|
152
|
+
# The MacOSX default is 4MB, way too small
|
153
|
+
# The Linux default is 2097152 or 8GB, so we should never need this
|
154
|
+
# but things will certainly break if it's been reset too small
|
155
|
+
# so ensure it's at least big enough to hold a fullsize shared memory segment
|
156
|
+
shmallNew=$(($shmmaxNew / 4096))
|
157
|
+
[ $shmallNew -lt $shmall ] && shmallNew=$shmall
|
158
|
+
shmallNewMB=$(($shmallNew / 256))
|
159
|
+
|
160
|
+
# Increase shmmax if appropriate
|
161
|
+
if [ $shmmaxNew -gt $shmmax ]; then
|
162
|
+
echo "[Info] Increasing max shared memory segment size to $shmmaxNewMB MB"
|
163
|
+
[ $PLATFORM = "Darwin-i386" ] && sudo sysctl -w kern.sysv.shmmax=$shmmaxNew
|
164
|
+
[ $PLATFORM = "Linux-x86_64" ] && sudo bash -c "echo $shmmaxNew > /proc/sys/kernel/shmmax"
|
165
|
+
[ $PLATFORM = "SunOS-i86pc" ] && echo "[Warning] shmmax must be set manually on Solaris-x86"
|
166
|
+
else
|
167
|
+
echo "[Info] No need to increase max shared memory segment size"
|
168
|
+
fi
|
169
|
+
|
170
|
+
# Increase shmall if appropriate
|
171
|
+
if [ $shmallNew -gt $shmall ]; then
|
172
|
+
echo "[Info] Increasing max shared memory allowed to $shmallNewMB MB"
|
173
|
+
[ $PLATFORM = "Darwin-i386" ] && sudo sysctl -w kern.sysv.shmall=$shmallNew
|
174
|
+
[ $PLATFORM = "Linux-x86_64" ] && sudo bash -c "echo $shmallNew > /proc/sys/kernel/shmall"
|
175
|
+
[ $PLATFORM = "SunOS-i86pc" ] && echo "[Warning]shmall must be set manually on Solaris-x86"
|
176
|
+
else
|
177
|
+
echo "[Info] No need to increase max shared memory allowed"
|
178
|
+
fi
|
179
|
+
|
180
|
+
# At this point, shared memory settings contain the values we want,
|
181
|
+
# put them in sysctl.conf so they are preserved.
|
182
|
+
if [[ ! -f /etc/sysctl.conf || `grep -sc "kern.*.shm" /etc/sysctl.conf` -eq 0 ]]; then
|
183
|
+
case "$PLATFORM" in
|
184
|
+
Linux-x86_64)
|
185
|
+
echo "# kernel.shm* settings added by MagLev installation" > /tmp/sysctl.conf.$$
|
186
|
+
echo "kernel.shmmax=`cat /proc/sys/kernel/shmmax`" >> /tmp/sysctl.conf.$$
|
187
|
+
echo "kernel.shmall=`cat /proc/sys/kernel/shmall`" >> /tmp/sysctl.conf.$$
|
188
|
+
;;
|
189
|
+
Darwin-i386)
|
190
|
+
# On Mac OS X Leopard, you must have all five settings in sysctl.conf
|
191
|
+
# before they will take effect.
|
192
|
+
echo "# kern.sysv.shm* settings added by MagLev installation" > /tmp/sysctl.conf.$$
|
193
|
+
sysctl kern.sysv.shmmax kern.sysv.shmall kern.sysv.shmmin kern.sysv.shmmni \
|
194
|
+
kern.sysv.shmseg | tr ":" "=" | tr -d " " >> /tmp/sysctl.conf.$$
|
195
|
+
;;
|
196
|
+
SunOS-i86pc)
|
197
|
+
# Do nothing in Solaris-x86 since /etc/sysctl.conf is ignored on Solaris 10.
|
198
|
+
# Must configure shared memory settings manually.
|
199
|
+
;;
|
200
|
+
*)
|
201
|
+
echo "[Error] Can't determine operating system. Check script."
|
202
|
+
exit 1
|
203
|
+
;;
|
204
|
+
esac
|
205
|
+
# Do nothing on Solaris-x86 since /etc/sysctl.conf is ignored on Solaris 10.
|
206
|
+
if [[ "$PLATFORM" != "SunOS-i86pc" ]]; then
|
207
|
+
echo "[Info] Adding the following section to /etc/sysctl.conf"
|
208
|
+
cat /tmp/sysctl.conf.$$
|
209
|
+
sudo bash -c "cat /tmp/sysctl.conf.$$ >> /etc/sysctl.conf"
|
210
|
+
/bin/rm -f /tmp/sysctl.conf.$$
|
211
|
+
fi
|
212
|
+
else
|
213
|
+
echo "[Info] The following shared memory settings already exist in /etc/sysctl.conf"
|
214
|
+
echo "To change them, remove the following lines from /etc/sysctl.conf and rerun this script"
|
215
|
+
grep "kern.*.shm" /etc/sysctl.conf
|
216
|
+
fi
|
217
|
+
|
218
|
+
# Now setup for NetLDI in case we ever need it.
|
219
|
+
echo "[Info] Setting up GemStone netldi service port"
|
220
|
+
if [ `grep -sc "^gs64ldi" /etc/services` -eq 0 ]; then
|
221
|
+
echo '[Info] Adding "gs64ldi 50378/tcp" to /etc/services'
|
222
|
+
sudo bash -c 'echo "gs64ldi 50378/tcp # Gemstone netldi" >> /etc/services'
|
223
|
+
else
|
224
|
+
echo "[Info] GemStone netldi service port is already set in /etc/services"
|
225
|
+
echo "To change it, remove the following line from /etc/services and rerun this script"
|
226
|
+
grep "^gs64ldi" /etc/services
|
227
|
+
fi
|
228
|
+
|
229
|
+
# Make sure we have a compatible version of GemStone
|
230
|
+
bash ./update.sh
|
231
|
+
|
232
|
+
rake stone:create[test]
|
233
|
+
rake test:start
|
234
|
+
|
235
|
+
|
236
|
+
cd ..
|
237
|
+
# End of script
|
238
|
+
exit 0
|
data/lib/maglev_record/base.rb
CHANGED
@@ -1,66 +1,14 @@
|
|
1
|
-
require "maglev_record/persistence"
|
2
|
-
require "maglev_record/enumerable"
|
3
|
-
require "maglev_record/read_write"
|
4
|
-
require "rubygems"
|
5
|
-
require "active_support"
|
6
|
-
require "active_model"
|
7
|
-
|
8
1
|
module MaglevRecord
|
9
2
|
module Base
|
10
|
-
extend
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
include ActiveModel::Validations
|
21
|
-
include MaglevRecord::Persistence
|
22
|
-
include MaglevRecord::Enumerable
|
23
|
-
include MaglevRecord::ReadWrite
|
24
|
-
|
25
|
-
self.maglev_persistable
|
26
|
-
ActiveSupport.maglev_persistable
|
27
|
-
ActiveSupport::HashWithIndifferentAccess.maglev_persistable
|
28
|
-
end
|
29
|
-
|
30
|
-
def initialize(*args)
|
31
|
-
if args.size == 1
|
32
|
-
args[0].each do |k, v|
|
33
|
-
self.send("#{k.to_s}=".to_sym, v)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def clear_dirty
|
39
|
-
@dirty = nil
|
40
|
-
end
|
41
|
-
def reset!
|
42
|
-
changed.each do |attr|
|
43
|
-
self.send "reset_#{attr}!".to_sym
|
44
|
-
end
|
45
|
-
clear_dirty
|
46
|
-
end
|
47
|
-
|
48
|
-
def attributes
|
49
|
-
@attributes ||= {}
|
50
|
-
end
|
51
|
-
|
52
|
-
module ClassMethods
|
53
|
-
def create(*args)
|
54
|
-
x = self.new(*args)
|
55
|
-
x
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
def to_key
|
61
|
-
key = self.__id__
|
62
|
-
[key] if key
|
63
|
-
end
|
64
|
-
|
3
|
+
extend MaglevSupport::Concern
|
4
|
+
include MaglevRecord::Integration
|
5
|
+
include MaglevRecord::Persistence
|
6
|
+
include MaglevRecord::ReadWrite
|
7
|
+
include MaglevRecord::MigrationOperations
|
8
|
+
redo_include ActiveModel::Conversion
|
9
|
+
include MaglevRecord::Sensible
|
10
|
+
include ActiveModel::Conversion
|
11
|
+
include MaglevRecord::SecurePassword
|
12
|
+
include MaglevRecord::Snapshotable
|
65
13
|
end
|
66
14
|
end
|
@@ -1,35 +1,24 @@
|
|
1
|
-
require "active_support"
|
2
|
-
|
3
1
|
module MaglevRecord
|
4
2
|
module Enumerable
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
3
|
module ClassMethods
|
8
|
-
|
9
|
-
|
4
|
+
def all
|
5
|
+
raise "method not available for MaglevRecord::Base"
|
6
|
+
end
|
10
7
|
def each
|
11
|
-
|
12
|
-
yield(el)
|
13
|
-
end
|
8
|
+
raise "method not available for MaglevRecord::Base"
|
14
9
|
end
|
15
|
-
|
16
10
|
def size
|
17
|
-
|
11
|
+
raise "method not available for MaglevRecord::Base"
|
18
12
|
end
|
19
|
-
|
20
|
-
alias_method :length, :size
|
21
|
-
|
22
13
|
def find_by_objectid(id)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
14
|
+
raise "method not available for MaglevRecord::Base"
|
15
|
+
# if id.respond_to? :to_i
|
16
|
+
# id = id.to_i
|
17
|
+
# else
|
18
|
+
# raise "#{id} do not respond to :to_i!"
|
19
|
+
# end
|
20
|
+
# ObjectSpace._id2ref(id)
|
28
21
|
end
|
29
|
-
|
30
22
|
end
|
31
|
-
|
32
23
|
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
class << Deprecation
|
3
|
+
# Declare that a method has been deprecated.
|
4
|
+
def deprecate_methods(target_module, *method_names)
|
5
|
+
options = method_names.extract_options!
|
6
|
+
method_names += options.keys
|
7
|
+
method_names.each do |method_name|
|
8
|
+
next unless method_name.respond_to?(:to_sym) # next if Fixnum
|
9
|
+
next if method_name == :none # check from rubygems/deprecate.rb
|
10
|
+
next if method_name.to_s.include?(".") # . in method names is not allowed
|
11
|
+
# workaround for :==
|
12
|
+
if method_name.to_sym == :==
|
13
|
+
method_name = "equal?"
|
14
|
+
end
|
15
|
+
target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation|
|
16
|
+
target_module.module_eval(<<-end_eval, __FILE__, __LINE__ + 1)
|
17
|
+
def #{target}_with_deprecation#{punctuation}(*args, &block)
|
18
|
+
::ActiveSupport::Deprecation.warn(
|
19
|
+
::ActiveSupport::Deprecation.deprecated_method_warning(
|
20
|
+
:#{method_name},
|
21
|
+
#{options[method_name].inspect}),
|
22
|
+
caller
|
23
|
+
)
|
24
|
+
send(:#{target}_without_deprecation#{punctuation}, *args, &block)
|
25
|
+
end
|
26
|
+
end_eval
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MaglevSupport
|
2
|
+
module Concern
|
3
|
+
def included(base)
|
4
|
+
self.included_modules.reverse.each do |mod|
|
5
|
+
base.extend(mod::ClassMethods) if mod.constants.include? 'ClassMethods'
|
6
|
+
end
|
7
|
+
self.reinclude_store.each do |mod|
|
8
|
+
base.__save_for_reinclude(mod)
|
9
|
+
end unless self.reinclude_store.nil?
|
10
|
+
base.extend(self::ClassMethods) if self.constants.include? 'ClassMethods'
|
11
|
+
if base.is_a? Class
|
12
|
+
# base.send :redo_include, ActiveModel::Validations
|
13
|
+
base.send :redo_extend, Enumerable
|
14
|
+
base.send :redo_extend, MaglevSupport.constantize("ActiveModel::Naming")
|
15
|
+
end
|
16
|
+
Maglev.commit_transaction
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MaglevSupport
|
2
|
+
# Copied from activesupport/lib/active_support/inflector/methods.rb
|
3
|
+
def self.constantize(camel_cased_word)
|
4
|
+
names = camel_cased_word.split('::')
|
5
|
+
names.shift if names.empty? || names.first.empty?
|
6
|
+
|
7
|
+
constant = Object
|
8
|
+
names.each do |name|
|
9
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
10
|
+
end
|
11
|
+
constant
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
require "maglev_record/maglev_support/active_support_patch"
|