lafcadio 0.4.3 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/bin/lafcadio_schema +28 -0
  2. data/lib/lafcadio.rb +3 -4
  3. data/lib/lafcadio.rb~ +3 -4
  4. data/lib/lafcadio/TestSuite.rb +2 -0
  5. data/lib/lafcadio/TestSuite.rb~ +16 -0
  6. data/lib/lafcadio/dateTime.rb +93 -2
  7. data/lib/lafcadio/{dateTime/Month.rb → dateTime.rb~} +33 -33
  8. data/lib/lafcadio/depend.rb +3 -0
  9. data/lib/lafcadio/domain.rb +574 -70
  10. data/lib/lafcadio/domain.rb~ +570 -70
  11. data/lib/lafcadio/mock.rb +92 -2
  12. data/lib/lafcadio/mock.rb~ +93 -0
  13. data/lib/lafcadio/objectField.rb +614 -3
  14. data/lib/lafcadio/objectField.rb~ +618 -0
  15. data/lib/lafcadio/objectStore.rb +662 -19
  16. data/lib/lafcadio/objectStore.rb~ +746 -0
  17. data/lib/lafcadio/query.rb +415 -31
  18. data/lib/lafcadio/query.rb~ +572 -0
  19. data/lib/lafcadio/schema.rb +57 -2
  20. data/lib/lafcadio/test.rb +17 -2
  21. data/lib/lafcadio/{test/LafcadioTestCase.rb → test.rb~} +5 -5
  22. data/lib/lafcadio/test/testconfig.dat +1 -1
  23. data/lib/lafcadio/util.rb +337 -20
  24. metadata +16 -77
  25. data/lib/lafcadio/domain/DomainObject.rb +0 -375
  26. data/lib/lafcadio/domain/DomainObject.rb~ +0 -371
  27. data/lib/lafcadio/domain/MapObject.rb +0 -22
  28. data/lib/lafcadio/domain/ObjectType.rb +0 -80
  29. data/lib/lafcadio/includer.rb +0 -18
  30. data/lib/lafcadio/mock/MockDbBridge.rb +0 -78
  31. data/lib/lafcadio/mock/MockDbBridge.rb~ +0 -74
  32. data/lib/lafcadio/mock/MockObjectStore.rb +0 -20
  33. data/lib/lafcadio/objectField/AutoIncrementField.rb +0 -25
  34. data/lib/lafcadio/objectField/BooleanField.rb +0 -83
  35. data/lib/lafcadio/objectField/DateField.rb +0 -33
  36. data/lib/lafcadio/objectField/DateTimeField.rb +0 -25
  37. data/lib/lafcadio/objectField/DecimalField.rb +0 -41
  38. data/lib/lafcadio/objectField/EmailField.rb +0 -28
  39. data/lib/lafcadio/objectField/EnumField.rb +0 -62
  40. data/lib/lafcadio/objectField/FieldValueError.rb +0 -4
  41. data/lib/lafcadio/objectField/IntegerField.rb +0 -15
  42. data/lib/lafcadio/objectField/LinkField.rb +0 -92
  43. data/lib/lafcadio/objectField/LinkField.rb~ +0 -86
  44. data/lib/lafcadio/objectField/MoneyField.rb +0 -13
  45. data/lib/lafcadio/objectField/MonthField.rb +0 -16
  46. data/lib/lafcadio/objectField/ObjectField.rb +0 -142
  47. data/lib/lafcadio/objectField/PasswordField.rb +0 -29
  48. data/lib/lafcadio/objectField/StateField.rb +0 -13
  49. data/lib/lafcadio/objectField/SubsetLinkField.rb +0 -25
  50. data/lib/lafcadio/objectField/TextField.rb +0 -23
  51. data/lib/lafcadio/objectField/TextListField.rb +0 -21
  52. data/lib/lafcadio/objectField/TimeStampField.rb +0 -15
  53. data/lib/lafcadio/objectStore/Cache.rb +0 -81
  54. data/lib/lafcadio/objectStore/Committer.rb +0 -65
  55. data/lib/lafcadio/objectStore/CouldntMatchObjectTypeError.rb +0 -4
  56. data/lib/lafcadio/objectStore/DbBridge.rb +0 -140
  57. data/lib/lafcadio/objectStore/DbBridge.rb~ +0 -140
  58. data/lib/lafcadio/objectStore/DomainComparable.rb +0 -25
  59. data/lib/lafcadio/objectStore/DomainObjectInitError.rb +0 -9
  60. data/lib/lafcadio/objectStore/DomainObjectNotFoundError.rb +0 -4
  61. data/lib/lafcadio/objectStore/DomainObjectProxy.rb +0 -62
  62. data/lib/lafcadio/objectStore/DomainObjectSqlMaker.rb +0 -74
  63. data/lib/lafcadio/objectStore/ObjectStore.rb +0 -207
  64. data/lib/lafcadio/objectStore/ObjectStore.rb~ +0 -207
  65. data/lib/lafcadio/objectStore/SqlValueConverter.rb +0 -30
  66. data/lib/lafcadio/objectStore/SqlValueConverter.rb~ +0 -30
  67. data/lib/lafcadio/query/Compare.rb +0 -55
  68. data/lib/lafcadio/query/CompoundCondition.rb +0 -39
  69. data/lib/lafcadio/query/Condition.rb +0 -66
  70. data/lib/lafcadio/query/Condition.rb~ +0 -66
  71. data/lib/lafcadio/query/Equals.rb +0 -45
  72. data/lib/lafcadio/query/In.rb +0 -20
  73. data/lib/lafcadio/query/Like.rb +0 -48
  74. data/lib/lafcadio/query/Link.rb +0 -20
  75. data/lib/lafcadio/query/Max.rb +0 -32
  76. data/lib/lafcadio/query/Max.rb~ +0 -25
  77. data/lib/lafcadio/query/Not.rb +0 -21
  78. data/lib/lafcadio/query/Query.rb +0 -92
  79. data/lib/lafcadio/schema/CreateTableStatement.rb +0 -61
  80. data/lib/lafcadio/schema/CreateTableStatement.rb~ +0 -59
  81. data/lib/lafcadio/util/Context.rb +0 -61
  82. data/lib/lafcadio/util/ContextualService.rb +0 -33
  83. data/lib/lafcadio/util/English.rb +0 -117
  84. data/lib/lafcadio/util/HashOfArrays.rb +0 -48
  85. data/lib/lafcadio/util/LafcadioConfig.rb +0 -25
  86. data/lib/lafcadio/util/QueueHash.rb +0 -67
  87. data/lib/lafcadio/util/UsStates.rb +0 -29
  88. data/lib/lafcadio/xml.rb +0 -2
@@ -1,30 +0,0 @@
1
- module Lafcadio
2
- class SqlValueConverter #:nodoc:
3
- attr_reader :objectType, :rowHash
4
-
5
- def initialize(objectType, rowHash)
6
- @objectType = objectType
7
- @rowHash = rowHash
8
- end
9
-
10
- def []( key )
11
- if key == 'pkId'
12
- if ( field_val = @rowHash[@objectType.sqlPrimaryKeyName] ).nil?
13
- error_msg = "The field \"" + @objectType.sqlPrimaryKeyName +
14
- "\" can\'t be found in the table \"" +
15
- @objectType.tableName + "\"."
16
- raise FieldMatchError, error_msg, caller
17
- else
18
- field_val.to_i
19
- end
20
- else
21
- begin
22
- field = @objectType.getField( key )
23
- field.valueFromSQL( @rowHash[ field.dbFieldName ] )
24
- rescue MissingError
25
- nil
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,30 +0,0 @@
1
- module Lafcadio
2
- class SqlValueConverter #:nodoc:
3
- attr_reader :objectType, :rowHash
4
-
5
- def initialize(objectType, rowHash)
6
- @objectType = objectType
7
- @rowHash = rowHash
8
- end
9
-
10
- def []( key )
11
- if key == 'pkId'
12
- if ( field_val = @rowHash[@objectType.sqlPrimaryKeyName] ).nil?
13
- error_msg = "The field \"" + @objectType.sqlPrimaryKeyName +
14
- "\" can\'t be found in the table \"" +
15
- @objectType.tableName + "\"."
16
- raise FieldMatchError, error_msg, caller
17
- else
18
- field_val.to_i
19
- end
20
- else
21
- begin
22
- field = @objectType.getField( key )
23
- field.valueFromSQL( @rowHash[ key ] )
24
- rescue MissingError
25
- nil
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,55 +0,0 @@
1
- require 'lafcadio/query/Condition'
2
-
3
- module Lafcadio
4
- class Query
5
- class Compare < Condition #:nodoc:
6
- LESS_THAN = 1
7
- LESS_THAN_OR_EQUAL = 2
8
- GREATER_THAN_OR_EQUAL = 3
9
- GREATER_THAN = 4
10
-
11
- @@comparators = {
12
- LESS_THAN => '<',
13
- LESS_THAN_OR_EQUAL => '<=',
14
- GREATER_THAN_OR_EQUAL => '>=',
15
- GREATER_THAN => '>'
16
- }
17
-
18
- def initialize(fieldName, searchTerm, objectType, compareType)
19
- super fieldName, searchTerm, objectType
20
- @compareType = compareType
21
- end
22
-
23
- def toSql
24
- useFieldForSqlValue = false
25
- if @fieldName != @objectType.sqlPrimaryKeyName
26
- field = getField
27
- useFieldForSqlValue = true unless field.class <= LinkField
28
- end
29
- if useFieldForSqlValue
30
- "#{ dbFieldName } #{ @@comparators[@compareType] } " +
31
- field.valueForSQL(@searchTerm).to_s
32
- else
33
- "#{ dbFieldName } #{ @@comparators[@compareType] } #{ @searchTerm }"
34
- end
35
- end
36
-
37
- @@mockComparators = {
38
- LESS_THAN => Proc.new { |d1, d2| d1 < d2 },
39
- LESS_THAN_OR_EQUAL => Proc.new { |d1, d2| d1 <= d2 },
40
- GREATER_THAN_OR_EQUAL => Proc.new { |d1, d2| d1 >= d2 },
41
- GREATER_THAN => Proc.new { |d1, d2| d1 > d2 }
42
- }
43
-
44
- def objectMeets(anObj)
45
- value = anObj.send @fieldName
46
- value = value.pkId if value.class <= DomainObject
47
- if value
48
- @@mockComparators[@compareType].call(value, @searchTerm)
49
- else
50
- false
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,39 +0,0 @@
1
- require 'lafcadio/query/Condition'
2
-
3
- module Lafcadio
4
- class Query
5
- class CompoundCondition < Condition #:nodoc:
6
- AND = 1
7
- OR = 2
8
-
9
- def initialize(*conditions)
10
- if( [ AND, OR ].index(conditions.last) )
11
- @compoundType = conditions.last
12
- conditions.pop
13
- else
14
- @compoundType = AND
15
- end
16
- @conditions = conditions
17
- @objectType = conditions[0].objectType
18
- end
19
-
20
- def toSql
21
- booleanString = @compoundType == AND ? 'and' : 'or'
22
- subSqlStrings = @conditions.collect { |cond| cond.toSql }
23
- "(#{ subSqlStrings.join(" #{ booleanString } ") })"
24
- end
25
-
26
- def objectMeets(anObj)
27
- if @compoundType == AND
28
- om = true
29
- @conditions.each { |cond| om = om && cond.objectMeets(anObj) }
30
- om
31
- else
32
- om = false
33
- @conditions.each { |cond| om = om || cond.objectMeets(anObj) }
34
- om
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,66 +0,0 @@
1
- require 'lafcadio/util'
2
-
3
- module Lafcadio
4
- class Query
5
- class Condition #:nodoc:
6
- def Condition.searchTermType
7
- Object
8
- end
9
-
10
- attr_reader :objectType
11
-
12
- def initialize(fieldName, searchTerm, objectType)
13
- require 'lafcadio/domain/DomainObject'
14
-
15
- @fieldName = fieldName
16
- @searchTerm = searchTerm
17
- unless @searchTerm.class <= self.class.searchTermType
18
- raise "Incorrect searchTerm type #{ searchTerm.class }"
19
- end
20
- @objectType = objectType
21
- if @objectType
22
- unless @objectType <= DomainObject
23
- raise "Incorrect object type #{ @objectType.to_s }"
24
- end
25
- end
26
- end
27
-
28
- def primaryKeyField?
29
- [ @objectType.sqlPrimaryKeyName, 'pkId' ].include?( @fieldName )
30
- end
31
-
32
- def dbFieldName
33
- if primaryKeyField?
34
- db_table = @objectType.tableName
35
- db_field_name = @objectType.sqlPrimaryKeyName
36
- "#{ db_table }.#{ db_field_name }"
37
- else
38
- getField.db_table_and_field_name
39
- end
40
- end
41
-
42
- def getField
43
- anObjectType = @objectType
44
- field = nil
45
- while (anObjectType < DomainObject || anObjectType < DomainObject) &&
46
- !field
47
- field = anObjectType.getClassField( @fieldName ) ||
48
- anObjectType.getClassFieldByDbFieldName( @fieldName )
49
- anObjectType = anObjectType.superclass
50
- end
51
- if field
52
- field
53
- else
54
- errStr = "Couldn't find field \"#{ @fieldName }\" in " +
55
- "#{ @objectType } domain class"
56
- raise( MissingError, errStr, caller )
57
- end
58
- end
59
-
60
- def not
61
- require 'lafcadio/query/Not'
62
- Query::Not.new( self )
63
- end
64
- end
65
- end
66
- end
@@ -1,66 +0,0 @@
1
- require 'lafcadio/util'
2
-
3
- module Lafcadio
4
- class Query
5
- class Condition #:nodoc:
6
- def Condition.searchTermType
7
- Object
8
- end
9
-
10
- attr_reader :objectType
11
-
12
- def initialize(fieldName, searchTerm, objectType)
13
- require 'lafcadio/domain/DomainObject'
14
-
15
- @fieldName = fieldName
16
- @searchTerm = searchTerm
17
- unless @searchTerm.class <= self.class.searchTermType
18
- raise "Incorrect searchTerm type #{ searchTerm.class }"
19
- end
20
- @objectType = objectType
21
- if @objectType
22
- unless @objectType <= DomainObject
23
- raise "Incorrect object type #{ @objectType.to_s }"
24
- end
25
- end
26
- end
27
-
28
- def primaryKeyField?
29
- [ @objectType.sqlPrimaryKeyName, 'pkId' ].include?( @fieldName )
30
- end
31
-
32
- def dbFieldName
33
- if primaryKeyField?
34
- db_table = @objectType.tableName
35
- db_field_name = @objectType.sqlPrimaryKeyName
36
- "#{ db_table }.#{ db_field_name }"
37
- else
38
- getField.db_table_and_field_name
39
- end
40
- end
41
-
42
- def getField
43
- anObjectType = @objectType
44
- field = nil
45
- while (anObjectType < DomainObject || anObjectType < DomainObject) &&
46
- !field
47
- field = anObjectType.getClassField( @fieldName ) ||
48
- anObjectType.getClassFieldByDbFieldName( @fieldName )
49
- anObjectType = anObjectType.superclass
50
- end
51
- if field
52
- field
53
- else
54
- errStr = "Couldn't find field \"#{ @fieldName }\" in " +
55
- "#{ @objectType } domain class"
56
- raise( MissingError, errStr, caller )
57
- end
58
- end
59
-
60
- def not
61
- require 'lafcadio/query/Not'
62
- Query::Not.new( self )
63
- end
64
- end
65
- end
66
- end
@@ -1,45 +0,0 @@
1
- require 'lafcadio/query/Condition'
2
-
3
- module Lafcadio
4
- class Query
5
- class Equals < Condition #:nodoc:
6
- def toSql
7
- sql = "#{ dbFieldName } "
8
- unless @searchTerm.nil?
9
- sql += "= " + r_val_string
10
- else
11
- sql += "is null"
12
- end
13
- sql
14
- end
15
-
16
- def r_val_string
17
- if primaryKeyField?
18
- @searchTerm.to_s
19
- else
20
- field = getField
21
- if @searchTerm.class <= ObjectField
22
- @searchTerm.db_table_and_field_name
23
- else
24
- field.valueForSQL(@searchTerm).to_s
25
- end
26
- end
27
- end
28
-
29
- def objectMeets(anObj)
30
- if @fieldName == @objectType.sqlPrimaryKeyName
31
- object_value = anObj.pkId
32
- else
33
- object_value = anObj.send @fieldName
34
- end
35
- compare_value =
36
- if @searchTerm.class <= ObjectField
37
- compare_value = anObj.send( @searchTerm.name )
38
- else
39
- compare_value = @searchTerm
40
- end
41
- compare_value == object_value
42
- end
43
- end
44
- end
45
- end
@@ -1,20 +0,0 @@
1
- require 'lafcadio/query/Condition'
2
-
3
- module Lafcadio
4
- class Query
5
- class In < Condition #:nodoc:
6
- def In.searchTermType
7
- Array
8
- end
9
-
10
- def toSql
11
- "#{ dbFieldName } in (#{ @searchTerm.join(', ') })"
12
- end
13
-
14
- def objectMeets(anObj)
15
- value = anObj.send @fieldName
16
- @searchTerm.index(value) != nil
17
- end
18
- end
19
- end
20
- end
@@ -1,48 +0,0 @@
1
- require 'lafcadio/query/Condition'
2
-
3
- module Lafcadio
4
- class Query
5
- class Like < Condition #:nodoc:
6
- PRE_AND_POST = 1
7
- PRE_ONLY = 2
8
- POST_ONLY = 3
9
-
10
- def initialize(
11
- fieldName, searchTerm, objectType, matchType = PRE_AND_POST)
12
- super fieldName, searchTerm, objectType
13
- @matchType = matchType
14
- end
15
-
16
- def toSql
17
- withWildcards = @searchTerm
18
- if @matchType == PRE_AND_POST
19
- withWildcards = "%" + withWildcards + "%"
20
- elsif @matchType == PRE_ONLY
21
- withWildcards = "%" + withWildcards
22
- elsif @matchType == POST_ONLY
23
- withWildcards += "%"
24
- end
25
- "#{ dbFieldName } like '#{ withWildcards }'"
26
- end
27
-
28
- def objectMeets(anObj)
29
- value = anObj.send @fieldName
30
- if value.class <= DomainObject || value.class == DomainObjectProxy
31
- value = value.pkId.to_s
32
- end
33
- if value.class <= Array
34
- (value.index(@searchTerm) != nil)
35
- else
36
- if @matchType == PRE_AND_POST
37
- regexp = Regexp.new(@searchTerm)
38
- elsif @matchType == PRE_ONLY
39
- regexp = Regexp.new(@searchTerm.to_s + "$")
40
- elsif @matchType == POST_ONLY
41
- regexp = Regexp.new("^" + @searchTerm)
42
- end
43
- regexp.match(value) != nil
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,20 +0,0 @@
1
- require 'lafcadio/query/Condition'
2
-
3
- module Lafcadio
4
- class Query
5
- class Link < Condition #:nodoc:
6
- def Link.searchTermType
7
- DomainObject
8
- end
9
-
10
- def toSql
11
- "#{ dbFieldName } = #{ @searchTerm.pkId }"
12
- end
13
-
14
- def objectMeets(anObj)
15
- value = anObj.send @fieldName
16
- value ? value.pkId == @searchTerm.pkId : false
17
- end
18
- end
19
- end
20
- end
@@ -1,32 +0,0 @@
1
- module Lafcadio
2
- class Query
3
- class Max < Query #:nodoc:
4
- attr_reader :field_name
5
-
6
- def initialize( objectType, field_name = nil )
7
- super( objectType )
8
- if field_name
9
- @field_name = field_name
10
- @pk = false
11
- else
12
- @field_name = objectType.sqlPrimaryKeyName
13
- @pk = true
14
- end
15
- end
16
-
17
- def collect( coll )
18
- max = nil
19
- fn = @pk ? 'pkId': @field_name
20
- coll.each { |d_obj|
21
- a_value = d_obj.send( fn )
22
- max = a_value if max.nil? || a_value > max
23
- }
24
- [ max ]
25
- end
26
-
27
- def fields
28
- "max(#{ @field_name })"
29
- end
30
- end
31
- end
32
- end