lafcadio 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lafcadio.rb +32 -0
- data/lib/lafcadio.rb~ +32 -0
- data/lib/lafcadio/TestSuite.rb +16 -0
- data/lib/lafcadio/dateTime.rb +2 -0
- data/lib/lafcadio/dateTime/Month.rb +93 -0
- data/lib/lafcadio/domain.rb +119 -0
- data/lib/lafcadio/domain.rb~ +119 -0
- data/lib/lafcadio/domain/DomainObject.rb +375 -0
- data/lib/lafcadio/domain/DomainObject.rb~ +371 -0
- data/lib/lafcadio/domain/MapObject.rb +22 -0
- data/lib/lafcadio/domain/ObjectType.rb +80 -0
- data/lib/lafcadio/includer.rb +18 -0
- data/lib/lafcadio/mock.rb +2 -0
- data/lib/lafcadio/mock/MockDbBridge.rb +78 -0
- data/lib/lafcadio/mock/MockDbBridge.rb~ +74 -0
- data/lib/lafcadio/mock/MockObjectStore.rb +20 -0
- data/lib/lafcadio/objectField.rb +14 -0
- data/lib/lafcadio/objectField/AutoIncrementField.rb +25 -0
- data/lib/lafcadio/objectField/BooleanField.rb +83 -0
- data/lib/lafcadio/objectField/DateField.rb +33 -0
- data/lib/lafcadio/objectField/DateTimeField.rb +25 -0
- data/lib/lafcadio/objectField/DecimalField.rb +41 -0
- data/lib/lafcadio/objectField/EmailField.rb +28 -0
- data/lib/lafcadio/objectField/EnumField.rb +62 -0
- data/lib/lafcadio/objectField/FieldValueError.rb +4 -0
- data/lib/lafcadio/objectField/IntegerField.rb +15 -0
- data/lib/lafcadio/objectField/LinkField.rb +92 -0
- data/lib/lafcadio/objectField/LinkField.rb~ +86 -0
- data/lib/lafcadio/objectField/MoneyField.rb +13 -0
- data/lib/lafcadio/objectField/MonthField.rb +16 -0
- data/lib/lafcadio/objectField/ObjectField.rb +142 -0
- data/lib/lafcadio/objectField/PasswordField.rb +29 -0
- data/lib/lafcadio/objectField/StateField.rb +13 -0
- data/lib/lafcadio/objectField/SubsetLinkField.rb +25 -0
- data/lib/lafcadio/objectField/TextField.rb +23 -0
- data/lib/lafcadio/objectField/TextListField.rb +21 -0
- data/lib/lafcadio/objectField/TimeStampField.rb +15 -0
- data/lib/lafcadio/objectStore.rb +100 -0
- data/lib/lafcadio/objectStore/Cache.rb +81 -0
- data/lib/lafcadio/objectStore/Committer.rb +65 -0
- data/lib/lafcadio/objectStore/CouldntMatchObjectTypeError.rb +4 -0
- data/lib/lafcadio/objectStore/DbBridge.rb +140 -0
- data/lib/lafcadio/objectStore/DbBridge.rb~ +140 -0
- data/lib/lafcadio/objectStore/DomainComparable.rb +25 -0
- data/lib/lafcadio/objectStore/DomainObjectInitError.rb +9 -0
- data/lib/lafcadio/objectStore/DomainObjectNotFoundError.rb +4 -0
- data/lib/lafcadio/objectStore/DomainObjectProxy.rb +62 -0
- data/lib/lafcadio/objectStore/DomainObjectSqlMaker.rb +74 -0
- data/lib/lafcadio/objectStore/ObjectStore.rb +207 -0
- data/lib/lafcadio/objectStore/ObjectStore.rb~ +207 -0
- data/lib/lafcadio/objectStore/SqlValueConverter.rb +30 -0
- data/lib/lafcadio/objectStore/SqlValueConverter.rb~ +30 -0
- data/lib/lafcadio/query.rb +203 -0
- data/lib/lafcadio/query/Compare.rb +55 -0
- data/lib/lafcadio/query/CompoundCondition.rb +39 -0
- data/lib/lafcadio/query/Condition.rb +66 -0
- data/lib/lafcadio/query/Condition.rb~ +66 -0
- data/lib/lafcadio/query/Equals.rb +45 -0
- data/lib/lafcadio/query/In.rb +20 -0
- data/lib/lafcadio/query/Like.rb +48 -0
- data/lib/lafcadio/query/Link.rb +20 -0
- data/lib/lafcadio/query/Max.rb +32 -0
- data/lib/lafcadio/query/Max.rb~ +25 -0
- data/lib/lafcadio/query/Not.rb +21 -0
- data/lib/lafcadio/query/Query.rb +92 -0
- data/lib/lafcadio/schema.rb +2 -0
- data/lib/lafcadio/schema/CreateTableStatement.rb +61 -0
- data/lib/lafcadio/schema/CreateTableStatement.rb~ +59 -0
- data/lib/lafcadio/test.rb +2 -0
- data/lib/lafcadio/test/LafcadioTestCase.rb +17 -0
- data/lib/lafcadio/test/testconfig.dat +13 -0
- data/lib/lafcadio/util.rb +180 -0
- data/lib/lafcadio/util/Context.rb +61 -0
- data/lib/lafcadio/util/ContextualService.rb +33 -0
- data/lib/lafcadio/util/English.rb +117 -0
- data/lib/lafcadio/util/HashOfArrays.rb +48 -0
- data/lib/lafcadio/util/LafcadioConfig.rb +25 -0
- data/lib/lafcadio/util/QueueHash.rb +67 -0
- data/lib/lafcadio/util/UsStates.rb +29 -0
- data/lib/lafcadio/xml.rb +2 -0
- metadata +135 -0
@@ -0,0 +1,55 @@
|
|
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
|
@@ -0,0 +1,39 @@
|
|
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
|
@@ -0,0 +1,66 @@
|
|
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
|
@@ -0,0 +1,66 @@
|
|
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
|
@@ -0,0 +1,45 @@
|
|
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
|
@@ -0,0 +1,20 @@
|
|
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
|
@@ -0,0 +1,48 @@
|
|
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
|
@@ -0,0 +1,20 @@
|
|
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
|
@@ -0,0 +1,32 @@
|
|
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
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Lafcadio
|
2
|
+
class Query
|
3
|
+
class Max < Query #:nodoc:
|
4
|
+
attr_reader :field_name
|
5
|
+
|
6
|
+
def initialize( objectType, field_name = 'pkId' )
|
7
|
+
super( objectType )
|
8
|
+
@field_name = field_name
|
9
|
+
end
|
10
|
+
|
11
|
+
def collect( coll )
|
12
|
+
max = nil
|
13
|
+
coll.each { |d_obj|
|
14
|
+
a_value = d_obj.send( @field_name )
|
15
|
+
max = a_value if max.nil? || a_value > max
|
16
|
+
}
|
17
|
+
[ max ]
|
18
|
+
end
|
19
|
+
|
20
|
+
def fields
|
21
|
+
"max(#{ @field_name })"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'lafcadio/query/Condition'
|
2
|
+
|
3
|
+
module Lafcadio
|
4
|
+
class Query
|
5
|
+
class Not < Condition #:nodoc:
|
6
|
+
def initialize(unCondition)
|
7
|
+
@unCondition = unCondition
|
8
|
+
end
|
9
|
+
|
10
|
+
def toSql
|
11
|
+
"!(#{ @unCondition.toSql })"
|
12
|
+
end
|
13
|
+
|
14
|
+
def objectMeets(obj)
|
15
|
+
!@unCondition.objectMeets(obj)
|
16
|
+
end
|
17
|
+
|
18
|
+
def objectType; @unCondition.objectType; end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|