lafcadio 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lafcadio.rb +1 -1
- data/lib/lafcadio.rb~ +1 -1
- data/lib/lafcadio/domain.rb +3 -3
- data/lib/lafcadio/domain.rb~ +5 -7
- data/lib/lafcadio/objectField.rb +1 -1
- data/lib/lafcadio/objectField.rb~ +561 -0
- data/lib/lafcadio/objectStore.rb +1 -1
- data/lib/lafcadio/objectStore.rb.~1.64.~ +766 -0
- data/lib/lafcadio/objectStore.rb~ +17 -5
- data/lib/lafcadio/query.rb +3 -16
- data/lib/lafcadio/query.rb~ +48 -5
- metadata +4 -2
@@ -573,11 +573,23 @@ module Lafcadio
|
|
573
573
|
|
574
574
|
def get_by_query( query )
|
575
575
|
unless @collections_by_query[query]
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
576
|
+
superset_query, pk_ids =
|
577
|
+
@collections_by_query.find { |other_query, pk_ids|
|
578
|
+
query.implies?( other_query )
|
579
|
+
}
|
580
|
+
if pk_ids
|
581
|
+
@collections_by_query[query] = ( pk_ids.collect { |pk_id|
|
582
|
+
get( query.domain_class, pk_id )
|
583
|
+
} ).select { |dobj| query.object_meets( dobj ) }.collect { |dobj|
|
584
|
+
dobj.pk_id
|
585
|
+
}
|
586
|
+
elsif @collections_by_query.values
|
587
|
+
newObjects = @dbBridge.get_collection_by_query(query)
|
588
|
+
newObjects.each { |dbObj| save dbObj }
|
589
|
+
@collections_by_query[query] = newObjects.collect { |dobj|
|
590
|
+
dobj.pk_id
|
591
|
+
}
|
592
|
+
end
|
581
593
|
end
|
582
594
|
collection = []
|
583
595
|
@collections_by_query[query].each { |pk_id|
|
data/lib/lafcadio/query.rb
CHANGED
@@ -147,7 +147,8 @@ module Lafcadio
|
|
147
147
|
|
148
148
|
def order_clause
|
149
149
|
if @order_by
|
150
|
-
|
150
|
+
order_by_field = @domain_class.get_field( @order_by )
|
151
|
+
clause = "order by #{ order_by_field.db_field_name } "
|
151
152
|
clause += @order_by_order == ASC ? 'asc' : 'desc'
|
152
153
|
clause
|
153
154
|
end
|
@@ -234,21 +235,7 @@ module Lafcadio
|
|
234
235
|
other_cond.is_a?( Condition ) and other_cond.to_sql == to_sql
|
235
236
|
end
|
236
237
|
|
237
|
-
def get_field
|
238
|
-
a_domain_class = @domain_class
|
239
|
-
field = nil
|
240
|
-
while ( a_domain_class < DomainObject ) && !field
|
241
|
-
field = a_domain_class.get_class_field( @fieldName )
|
242
|
-
a_domain_class = a_domain_class.superclass
|
243
|
-
end
|
244
|
-
if field
|
245
|
-
field
|
246
|
-
else
|
247
|
-
errStr = "Couldn't find field \"#{ @fieldName }\" in " +
|
248
|
-
"#{ @domain_class } domain class"
|
249
|
-
raise( MissingError, errStr, caller )
|
250
|
-
end
|
251
|
-
end
|
238
|
+
def get_field; @domain_class.get_field( @fieldName ); end
|
252
239
|
|
253
240
|
def query; Query.new( @domain_class, self ); end
|
254
241
|
|
data/lib/lafcadio/query.rb~
CHANGED
@@ -140,6 +140,8 @@ module Lafcadio
|
|
140
140
|
def limit_clause
|
141
141
|
"limit #{ @limit.begin }, #{ @limit.end - @limit.begin + 1 }" if @limit
|
142
142
|
end
|
143
|
+
|
144
|
+
def object_meets( dobj ); @condition.object_meets( dobj ); end
|
143
145
|
|
144
146
|
def or( &action ); compound( CompoundCondition::OR, action ); end
|
145
147
|
|
@@ -150,6 +152,18 @@ module Lafcadio
|
|
150
152
|
clause
|
151
153
|
end
|
152
154
|
end
|
155
|
+
|
156
|
+
def implies?( other_query )
|
157
|
+
if other_query == self
|
158
|
+
true
|
159
|
+
elsif @domain_class == other_query.domain_class
|
160
|
+
if other_query.condition.nil? and !self.condition.nil?
|
161
|
+
true
|
162
|
+
else
|
163
|
+
self.condition and self.condition.implies?( other_query.condition )
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
153
167
|
|
154
168
|
def sql_primary_key_field(domain_class)
|
155
169
|
"#{ domain_class.table_name }.#{ domain_class.sql_primary_key_name }"
|
@@ -207,8 +221,19 @@ module Lafcadio
|
|
207
221
|
end
|
208
222
|
end
|
209
223
|
|
224
|
+
def implies?( other_condition )
|
225
|
+
self.eql?( other_condition ) or (
|
226
|
+
other_condition.respond_to?( :implied_by? ) and
|
227
|
+
other_condition.implied_by?( self )
|
228
|
+
)
|
229
|
+
end
|
230
|
+
|
210
231
|
def db_field_name; get_field.db_table_and_field_name; end
|
211
232
|
|
233
|
+
def eql?( other_cond )
|
234
|
+
other_cond.is_a?( Condition ) and other_cond.to_sql == to_sql
|
235
|
+
end
|
236
|
+
|
212
237
|
def get_field
|
213
238
|
a_domain_class = @domain_class
|
214
239
|
field = nil
|
@@ -285,20 +310,38 @@ module Lafcadio
|
|
285
310
|
class CompoundCondition < Condition #:nodoc:
|
286
311
|
AND = 1
|
287
312
|
OR = 2
|
288
|
-
|
313
|
+
|
289
314
|
def initialize(*conditions)
|
290
315
|
if( [ AND, OR ].index(conditions.last) )
|
291
|
-
@
|
316
|
+
@compound_type = conditions.last
|
292
317
|
conditions.pop
|
293
318
|
else
|
294
|
-
@
|
319
|
+
@compound_type = AND
|
295
320
|
end
|
296
321
|
@conditions = conditions
|
297
322
|
@domain_class = conditions[0].domain_class
|
298
323
|
end
|
324
|
+
|
325
|
+
def implied_by?( other_condition )
|
326
|
+
@compound_type == OR && @conditions.any? { |cond|
|
327
|
+
cond.implies?( other_condition )
|
328
|
+
}
|
329
|
+
end
|
330
|
+
|
331
|
+
def implies?( other_condition )
|
332
|
+
super( other_condition ) or (
|
333
|
+
@compound_type == AND and @conditions.any? { |cond|
|
334
|
+
cond.implies?( other_condition )
|
335
|
+
}
|
336
|
+
) or (
|
337
|
+
@compound_type == OR and @conditions.all? { |cond|
|
338
|
+
cond.implies?( other_condition )
|
339
|
+
}
|
340
|
+
)
|
341
|
+
end
|
299
342
|
|
300
343
|
def object_meets(anObj)
|
301
|
-
if @
|
344
|
+
if @compound_type == AND
|
302
345
|
@conditions.inject( true ) { |result, cond|
|
303
346
|
result && cond.object_meets( anObj )
|
304
347
|
}
|
@@ -310,7 +353,7 @@ module Lafcadio
|
|
310
353
|
end
|
311
354
|
|
312
355
|
def to_sql
|
313
|
-
booleanString = @
|
356
|
+
booleanString = @compound_type == AND ? 'and' : 'or'
|
314
357
|
subSqlStrings = @conditions.collect { |cond| cond.to_sql }
|
315
358
|
"(#{ subSqlStrings.join(" #{ booleanString } ") })"
|
316
359
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: lafcadio
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.7.
|
7
|
-
date: 2005-01-
|
6
|
+
version: 0.7.1
|
7
|
+
date: 2005-01-27
|
8
8
|
summary: Lafcadio is an object-relational mapping layer
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -40,7 +40,9 @@ files:
|
|
40
40
|
- lib/lafcadio/mock.rb
|
41
41
|
- lib/lafcadio/mock.rb~
|
42
42
|
- lib/lafcadio/objectField.rb
|
43
|
+
- lib/lafcadio/objectField.rb~
|
43
44
|
- lib/lafcadio/objectStore.rb
|
45
|
+
- lib/lafcadio/objectStore.rb.~1.64.~
|
44
46
|
- lib/lafcadio/objectStore.rb~
|
45
47
|
- lib/lafcadio/query.rb
|
46
48
|
- lib/lafcadio/query.rb~
|