lafcadio 0.5.2 → 0.6.0
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.
- data/bin/lafcadio_schema +12 -4
- data/lib/lafcadio.rb +1 -1
- data/lib/lafcadio.rb~ +1 -1
- data/lib/lafcadio/depend.rb +2 -0
- data/lib/lafcadio/domain.rb +49 -34
- data/lib/lafcadio/domain.rb~ +50 -28
- data/lib/lafcadio/mock.rb +12 -9
- data/lib/lafcadio/objectField.rb +66 -130
- data/lib/lafcadio/objectStore.rb +106 -95
- data/lib/lafcadio/query.rb +87 -78
- data/lib/lafcadio/schema.rb +0 -1
- data/lib/lafcadio/test.rb +4 -1
- data/lib/lafcadio/test/testconfig.dat +0 -2
- data/lib/lafcadio/test/testconfig.dat~ +13 -0
- data/lib/lafcadio/util.rb +2 -120
- data/lib/lafcadio/util.rb~ +379 -0
- metadata +14 -10
- data/lib/lafcadio/TestSuite.rb +0 -18
- data/lib/lafcadio/TestSuite.rb~ +0 -16
- data/lib/lafcadio/dateTime.rb~ +0 -93
- data/lib/lafcadio/mock.rb~ +0 -93
- data/lib/lafcadio/objectField.rb~ +0 -618
- data/lib/lafcadio/objectStore.rb~ +0 -746
- data/lib/lafcadio/query.rb~ +0 -572
- data/lib/lafcadio/test.rb~ +0 -17
data/bin/lafcadio_schema
CHANGED
@@ -7,15 +7,23 @@ require 'lafcadio/util'
|
|
7
7
|
require 'getoptlong'
|
8
8
|
include Lafcadio
|
9
9
|
|
10
|
-
opts = GetoptLong.new(
|
10
|
+
opts = GetoptLong.new(
|
11
|
+
[ '--config', '-c', GetoptLong::REQUIRED_ARGUMENT ],
|
12
|
+
[ '--class', '-C', GetoptLong::OPTIONAL_ARGUMENT ]
|
13
|
+
)
|
11
14
|
if ( ( optArray = opts.get ) && ARGV.size >= 1 )
|
12
15
|
configFile = optArray[1]
|
13
16
|
LafcadioConfig.set_filename( configFile )
|
17
|
+
class_opts = opts.get
|
14
18
|
ARGV.each { |fileName|
|
15
19
|
require "#{ fileName }"
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
if class_opts
|
21
|
+
className = class_opts.last
|
22
|
+
else
|
23
|
+
fileName =~ /(\w*)\.rb/
|
24
|
+
className = $1
|
25
|
+
end
|
26
|
+
domainClass = Class.by_name( className )
|
19
27
|
if domainClass
|
20
28
|
statement = CreateTableStatement.new( domainClass )
|
21
29
|
puts statement.to_sql
|
data/lib/lafcadio.rb
CHANGED
data/lib/lafcadio.rb~
CHANGED
data/lib/lafcadio/depend.rb
CHANGED
data/lib/lafcadio/domain.rb
CHANGED
@@ -13,12 +13,12 @@ module Lafcadio
|
|
13
13
|
def get_class_field( fieldElt )
|
14
14
|
className = fieldElt.attributes['class'].to_s
|
15
15
|
name = fieldElt.attributes['name']
|
16
|
-
|
17
|
-
fieldClass = Class.
|
16
|
+
if className != ''
|
17
|
+
fieldClass = Class.by_name( 'Lafcadio::' + className )
|
18
18
|
register_name( name )
|
19
19
|
field = fieldClass.instantiate_from_xml( @domain_class, fieldElt )
|
20
20
|
set_field_attributes( field, fieldElt )
|
21
|
-
|
21
|
+
else
|
22
22
|
msg = "Couldn't find field class '#{ className }' for field " +
|
23
23
|
"'#{ name }'"
|
24
24
|
raise( MissingError, msg, caller )
|
@@ -122,14 +122,14 @@ module Lafcadio
|
|
122
122
|
module DomainComparable
|
123
123
|
include Comparable
|
124
124
|
|
125
|
-
# A DomainObject or DomainObjectProxy is compared by +
|
125
|
+
# A DomainObject or DomainObjectProxy is compared by +domain_class+ and by
|
126
126
|
# +pk_id+.
|
127
127
|
def <=>(anOther)
|
128
|
-
if anOther.respond_to?( '
|
129
|
-
if self.
|
128
|
+
if anOther.respond_to?( 'domain_class' )
|
129
|
+
if self.domain_class == anOther.domain_class
|
130
130
|
self.pk_id <=> anOther.pk_id
|
131
131
|
else
|
132
|
-
self.
|
132
|
+
self.domain_class.name <=> anOther.domain_class.name
|
133
133
|
end
|
134
134
|
else
|
135
135
|
nil
|
@@ -243,6 +243,13 @@ module Lafcadio
|
|
243
243
|
class DomainObject
|
244
244
|
@@subclassHash = {}
|
245
245
|
@@class_fields = {}
|
246
|
+
@@pk_fields =
|
247
|
+
Hash.new { |hash, key|
|
248
|
+
pk_field = PrimaryKeyField.new( key )
|
249
|
+
pk_field.db_field_name = @@sql_primary_keys[key]
|
250
|
+
hash[key] = pk_field
|
251
|
+
}
|
252
|
+
@@sql_primary_keys = Hash.new( 'pk_id' )
|
246
253
|
|
247
254
|
COMMIT_ADD = 1
|
248
255
|
COMMIT_EDIT = 2
|
@@ -277,7 +284,7 @@ module Lafcadio
|
|
277
284
|
def self.create_field( field_class, name, att_hash )
|
278
285
|
class_fields = @@class_fields[self]
|
279
286
|
if class_fields.nil?
|
280
|
-
class_fields = [
|
287
|
+
class_fields = [ @@pk_fields[self] ]
|
281
288
|
@@class_fields[self] = class_fields
|
282
289
|
end
|
283
290
|
att_hash['name'] = name
|
@@ -295,7 +302,8 @@ module Lafcadio
|
|
295
302
|
if aClass != DomainObjectProxy &&
|
296
303
|
(!DomainObject.abstract_subclasses.index(aClass))
|
297
304
|
aClass.class_fields.each { |field|
|
298
|
-
if field.
|
305
|
+
if ( field.is_a?( LinkField ) &&
|
306
|
+
field.linked_type == self.domain_class )
|
299
307
|
dependent_classes[aClass] = field
|
300
308
|
end
|
301
309
|
}
|
@@ -320,7 +328,7 @@ module Lafcadio
|
|
320
328
|
# them from XML if necessary.
|
321
329
|
def self.get_class_fields
|
322
330
|
if self.methods( false ).include?( 'get_class_fields' )
|
323
|
-
[
|
331
|
+
[ @@pk_fields[ self ] ]
|
324
332
|
else
|
325
333
|
xmlParser = try_load_xml_parser
|
326
334
|
if xmlParser
|
@@ -334,13 +342,10 @@ module Lafcadio
|
|
334
342
|
end
|
335
343
|
|
336
344
|
def self.get_domain_dirs #:nodoc:
|
337
|
-
|
338
|
-
|
339
|
-
domainDirStr = config['domainDirs']
|
340
|
-
if domainDirStr
|
341
|
-
domainDirs = domainDirStr.split(',')
|
345
|
+
if ( domainDirStr = LafcadioConfig.new['domainDirs'] )
|
346
|
+
domainDirStr.split(',')
|
342
347
|
else
|
343
|
-
|
348
|
+
[]
|
344
349
|
end
|
345
350
|
end
|
346
351
|
|
@@ -360,20 +365,20 @@ module Lafcadio
|
|
360
365
|
end
|
361
366
|
end
|
362
367
|
|
363
|
-
def self.
|
364
|
-
|
368
|
+
def self.get_domain_class_from_string(typeString) #:nodoc:
|
369
|
+
domain_class = nil
|
365
370
|
require_domain_file( typeString )
|
366
371
|
subclasses.each { |subclass|
|
367
|
-
|
372
|
+
domain_class = subclass if subclass.to_s == typeString
|
368
373
|
}
|
369
|
-
if
|
370
|
-
|
374
|
+
if domain_class
|
375
|
+
domain_class
|
371
376
|
else
|
372
|
-
raise
|
373
|
-
"couldn't match
|
377
|
+
raise CouldntMatchDomainClassError,
|
378
|
+
"couldn't match domain_class #{typeString}", caller
|
374
379
|
end
|
375
380
|
end
|
376
|
-
|
381
|
+
|
377
382
|
def self.inherited(subclass) #:nodoc:
|
378
383
|
@@subclassHash[subclass] = true
|
379
384
|
end
|
@@ -394,7 +399,7 @@ module Lafcadio
|
|
394
399
|
create_field( field_class, args[0], args[1] || {} )
|
395
400
|
end
|
396
401
|
|
397
|
-
def self.
|
402
|
+
def self.domain_class #:nodoc:
|
398
403
|
self
|
399
404
|
end
|
400
405
|
|
@@ -415,15 +420,25 @@ module Lafcadio
|
|
415
420
|
|
416
421
|
def self.self_and_concrete_superclasses # :nodoc:
|
417
422
|
classes = [ ]
|
418
|
-
|
419
|
-
until(
|
420
|
-
|
421
|
-
classes <<
|
422
|
-
|
423
|
+
a_domain_class = self
|
424
|
+
until( a_domain_class == DomainObject ||
|
425
|
+
abstract_subclasses.index( a_domain_class ) != nil )
|
426
|
+
classes << a_domain_class
|
427
|
+
a_domain_class = a_domain_class.superclass
|
423
428
|
end
|
424
429
|
classes
|
425
430
|
end
|
426
431
|
|
432
|
+
def self.singleton_method_added( symbol )
|
433
|
+
if symbol.id2name == 'sql_primary_key_name' && self < DomainObject
|
434
|
+
begin
|
435
|
+
get_field( 'pk_id' ).db_field_name = self.send( symbol )
|
436
|
+
rescue NameError
|
437
|
+
@@sql_primary_keys[self] = self.send( symbol )
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
427
442
|
# Returns the name of the primary key in the database, retrieving it from
|
428
443
|
# the class definition XML if necessary.
|
429
444
|
def self.sql_primary_key_name( set_sql_primary_key_name = nil )
|
@@ -451,7 +466,7 @@ module Lafcadio
|
|
451
466
|
if (!xmlParser.nil? && table_name = xmlParser.table_name)
|
452
467
|
table_name
|
453
468
|
else
|
454
|
-
table_name = self.
|
469
|
+
table_name = self.basename
|
455
470
|
table_name[0] = table_name[0..0].downcase
|
456
471
|
English.plural table_name
|
457
472
|
end
|
@@ -461,7 +476,7 @@ module Lafcadio
|
|
461
476
|
def self.try_load_xml_parser
|
462
477
|
require 'lafcadio/domain'
|
463
478
|
dirName = LafcadioConfig.new['classDefinitionDir']
|
464
|
-
xmlFileName = self.
|
479
|
+
xmlFileName = self.basename + '.xml'
|
465
480
|
xmlPath = File.join( dirName, xmlFileName )
|
466
481
|
xml = ''
|
467
482
|
begin
|
@@ -565,8 +580,8 @@ module Lafcadio
|
|
565
580
|
# Returns the subclass of DomainObject that this instance represents.
|
566
581
|
# Because of the way that proxying works, clients should call this method
|
567
582
|
# instead of Object.class.
|
568
|
-
def
|
569
|
-
self.class.
|
583
|
+
def domain_class
|
584
|
+
self.class.domain_class
|
570
585
|
end
|
571
586
|
|
572
587
|
# This template method is called before every commit. Subclasses can
|
data/lib/lafcadio/domain.rb~
CHANGED
@@ -13,12 +13,12 @@ module Lafcadio
|
|
13
13
|
def get_class_field( fieldElt )
|
14
14
|
className = fieldElt.attributes['class'].to_s
|
15
15
|
name = fieldElt.attributes['name']
|
16
|
-
|
17
|
-
fieldClass = Class.
|
16
|
+
if className != ''
|
17
|
+
fieldClass = Class.by_name( 'Lafcadio::' + className )
|
18
18
|
register_name( name )
|
19
19
|
field = fieldClass.instantiate_from_xml( @domain_class, fieldElt )
|
20
20
|
set_field_attributes( field, fieldElt )
|
21
|
-
|
21
|
+
else
|
22
22
|
msg = "Couldn't find field class '#{ className }' for field " +
|
23
23
|
"'#{ name }'"
|
24
24
|
raise( MissingError, msg, caller )
|
@@ -122,14 +122,14 @@ module Lafcadio
|
|
122
122
|
module DomainComparable
|
123
123
|
include Comparable
|
124
124
|
|
125
|
-
# A DomainObject or DomainObjectProxy is compared by +
|
125
|
+
# A DomainObject or DomainObjectProxy is compared by +domain_class+ and by
|
126
126
|
# +pk_id+.
|
127
127
|
def <=>(anOther)
|
128
|
-
if anOther.respond_to?( '
|
129
|
-
if self.
|
128
|
+
if anOther.respond_to?( 'domain_class' )
|
129
|
+
if self.domain_class == anOther.domain_class
|
130
130
|
self.pk_id <=> anOther.pk_id
|
131
131
|
else
|
132
|
-
self.
|
132
|
+
self.domain_class.name <=> anOther.domain_class.name
|
133
133
|
end
|
134
134
|
else
|
135
135
|
nil
|
@@ -243,6 +243,13 @@ module Lafcadio
|
|
243
243
|
class DomainObject
|
244
244
|
@@subclassHash = {}
|
245
245
|
@@class_fields = {}
|
246
|
+
@@pk_fields =
|
247
|
+
Hash.new { |hash, key|
|
248
|
+
pk_field = PrimaryKeyField.new( key )
|
249
|
+
pk_field.db_field_name = @@sql_primary_keys[key]
|
250
|
+
hash[key] = pk_field
|
251
|
+
}
|
252
|
+
@@sql_primary_keys = Hash.new( 'pk_id' )
|
246
253
|
|
247
254
|
COMMIT_ADD = 1
|
248
255
|
COMMIT_EDIT = 2
|
@@ -277,7 +284,7 @@ module Lafcadio
|
|
277
284
|
def self.create_field( field_class, name, att_hash )
|
278
285
|
class_fields = @@class_fields[self]
|
279
286
|
if class_fields.nil?
|
280
|
-
class_fields = [
|
287
|
+
class_fields = [ @@pk_fields[self] ]
|
281
288
|
@@class_fields[self] = class_fields
|
282
289
|
end
|
283
290
|
att_hash['name'] = name
|
@@ -295,7 +302,8 @@ module Lafcadio
|
|
295
302
|
if aClass != DomainObjectProxy &&
|
296
303
|
(!DomainObject.abstract_subclasses.index(aClass))
|
297
304
|
aClass.class_fields.each { |field|
|
298
|
-
if field.
|
305
|
+
if ( field.is_a?( LinkField ) &&
|
306
|
+
field.linked_type == self.domain_class )
|
299
307
|
dependent_classes[aClass] = field
|
300
308
|
end
|
301
309
|
}
|
@@ -320,7 +328,7 @@ module Lafcadio
|
|
320
328
|
# them from XML if necessary.
|
321
329
|
def self.get_class_fields
|
322
330
|
if self.methods( false ).include?( 'get_class_fields' )
|
323
|
-
[
|
331
|
+
[ @@pk_fields[ self ] ]
|
324
332
|
else
|
325
333
|
xmlParser = try_load_xml_parser
|
326
334
|
if xmlParser
|
@@ -360,20 +368,20 @@ module Lafcadio
|
|
360
368
|
end
|
361
369
|
end
|
362
370
|
|
363
|
-
def self.
|
364
|
-
|
371
|
+
def self.get_domain_class_from_string(typeString) #:nodoc:
|
372
|
+
domain_class = nil
|
365
373
|
require_domain_file( typeString )
|
366
374
|
subclasses.each { |subclass|
|
367
|
-
|
375
|
+
domain_class = subclass if subclass.to_s == typeString
|
368
376
|
}
|
369
|
-
if
|
370
|
-
|
377
|
+
if domain_class
|
378
|
+
domain_class
|
371
379
|
else
|
372
|
-
raise
|
373
|
-
"couldn't match
|
380
|
+
raise CouldntMatchDomainClassError,
|
381
|
+
"couldn't match domain_class #{typeString}", caller
|
374
382
|
end
|
375
383
|
end
|
376
|
-
|
384
|
+
|
377
385
|
def self.inherited(subclass) #:nodoc:
|
378
386
|
@@subclassHash[subclass] = true
|
379
387
|
end
|
@@ -394,7 +402,7 @@ module Lafcadio
|
|
394
402
|
create_field( field_class, args[0], args[1] || {} )
|
395
403
|
end
|
396
404
|
|
397
|
-
def self.
|
405
|
+
def self.domain_class #:nodoc:
|
398
406
|
self
|
399
407
|
end
|
400
408
|
|
@@ -415,15 +423,25 @@ module Lafcadio
|
|
415
423
|
|
416
424
|
def self.self_and_concrete_superclasses # :nodoc:
|
417
425
|
classes = [ ]
|
418
|
-
|
419
|
-
until(
|
420
|
-
|
421
|
-
classes <<
|
422
|
-
|
426
|
+
a_domain_class = self
|
427
|
+
until( a_domain_class == DomainObject ||
|
428
|
+
abstract_subclasses.index( a_domain_class ) != nil )
|
429
|
+
classes << a_domain_class
|
430
|
+
a_domain_class = a_domain_class.superclass
|
423
431
|
end
|
424
432
|
classes
|
425
433
|
end
|
426
434
|
|
435
|
+
def self.singleton_method_added( symbol )
|
436
|
+
if symbol.id2name == 'sql_primary_key_name' && self < DomainObject
|
437
|
+
begin
|
438
|
+
get_field( 'pk_id' ).db_field_name = self.send( symbol )
|
439
|
+
rescue NameError
|
440
|
+
@@sql_primary_keys[self] = self.send( symbol )
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
427
445
|
# Returns the name of the primary key in the database, retrieving it from
|
428
446
|
# the class definition XML if necessary.
|
429
447
|
def self.sql_primary_key_name( set_sql_primary_key_name = nil )
|
@@ -451,7 +469,7 @@ module Lafcadio
|
|
451
469
|
if (!xmlParser.nil? && table_name = xmlParser.table_name)
|
452
470
|
table_name
|
453
471
|
else
|
454
|
-
table_name = self.
|
472
|
+
table_name = self.basename
|
455
473
|
table_name[0] = table_name[0..0].downcase
|
456
474
|
English.plural table_name
|
457
475
|
end
|
@@ -461,7 +479,7 @@ module Lafcadio
|
|
461
479
|
def self.try_load_xml_parser
|
462
480
|
require 'lafcadio/domain'
|
463
481
|
dirName = LafcadioConfig.new['classDefinitionDir']
|
464
|
-
xmlFileName = self.
|
482
|
+
xmlFileName = self.basename + '.xml'
|
465
483
|
xmlPath = File.join( dirName, xmlFileName )
|
466
484
|
xml = ''
|
467
485
|
begin
|
@@ -553,6 +571,10 @@ module Lafcadio
|
|
553
571
|
set_field( field, args.first )
|
554
572
|
elsif ( field = get_getter_field( methId ) )
|
555
573
|
get_field( field )
|
574
|
+
elsif ( methId.to_s =~ /^get_/ and
|
575
|
+
ObjectStore.get_object_store.respond_to?( methId ) )
|
576
|
+
args = [ self ].concat( args )
|
577
|
+
ObjectStore.get_object_store.send( methId, *args )
|
556
578
|
else
|
557
579
|
super( methId, *args )
|
558
580
|
end
|
@@ -561,8 +583,8 @@ module Lafcadio
|
|
561
583
|
# Returns the subclass of DomainObject that this instance represents.
|
562
584
|
# Because of the way that proxying works, clients should call this method
|
563
585
|
# instead of Object.class.
|
564
|
-
def
|
565
|
-
self.class.
|
586
|
+
def domain_class
|
587
|
+
self.class.domain_class
|
566
588
|
end
|
567
589
|
|
568
590
|
# This template method is called before every commit. Subclasses can
|
data/lib/lafcadio/mock.rb
CHANGED
@@ -11,24 +11,26 @@ module Lafcadio
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def commit(db_object)
|
14
|
-
|
14
|
+
objects_by_domain_class = get_objects_by_domain_class(
|
15
|
+
db_object.domain_class
|
16
|
+
)
|
15
17
|
if db_object.delete
|
16
|
-
|
18
|
+
objects_by_domain_class.delete( db_object.pk_id )
|
17
19
|
else
|
18
20
|
object_pk_id = get_pk_id_before_committing( db_object )
|
19
|
-
|
21
|
+
objects_by_domain_class[object_pk_id] = db_object
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
def _get_all(
|
24
|
-
@retrievals_by_type[
|
25
|
-
@objects[
|
25
|
+
def _get_all( domain_class )
|
26
|
+
@retrievals_by_type[domain_class] = @retrievals_by_type[domain_class] + 1
|
27
|
+
@objects[domain_class] ? @objects[domain_class].values : []
|
26
28
|
end
|
27
29
|
|
28
30
|
def get_collection_by_query(query)
|
29
31
|
@query_count[query] += 1
|
30
32
|
objects = []
|
31
|
-
_get_all( query.
|
33
|
+
_get_all( query.domain_class ).each { |dbObj|
|
32
34
|
if query.condition
|
33
35
|
objects << dbObj if query.condition.object_meets(dbObj)
|
34
36
|
else
|
@@ -49,7 +51,8 @@ module Lafcadio
|
|
49
51
|
object_pk_id = db_object.pk_id
|
50
52
|
unless object_pk_id
|
51
53
|
maxpk_id = 0
|
52
|
-
get_objects_by_domain_class( db_object.
|
54
|
+
pk_ids = get_objects_by_domain_class( db_object.domain_class ).keys
|
55
|
+
pk_ids.each { |pk_id|
|
53
56
|
maxpk_id = pk_id if pk_id > maxpk_id
|
54
57
|
}
|
55
58
|
@last_pk_id_inserted = maxpk_id + 1
|
@@ -70,7 +73,7 @@ module Lafcadio
|
|
70
73
|
def group_query( query )
|
71
74
|
if query.class == Query::Max
|
72
75
|
if ( query.field_name == 'pk_id' || query.field_name == 'rate' )
|
73
|
-
query.collect( @objects[query.
|
76
|
+
query.collect( @objects[query.domain_class].values )
|
74
77
|
else
|
75
78
|
raise "Can't handle query with sql '#{ query.to_sql }'"
|
76
79
|
end
|