0
|
1 use strict;
|
|
2 package Schema::DataSource::TypeMapping;
|
|
3 use Common;
|
|
4 our @ISA = qw(Object);
|
|
5
|
|
6 BEGIN {
|
|
7 DeclareProperty Mappings => ACCESS_NONE;
|
|
8 DeclareProperty DBIdentifierType => ACCESS_READ;
|
|
9 DeclareProperty DBValueType => ACCESS_READ;
|
|
10 }
|
|
11
|
|
12 sub MapType {
|
|
13 my ($this,$Type) = @_;
|
|
14
|
|
15 if (my $mapped = $this->{$Mappings}->{$Type->Name->Canonical}) {
|
|
16 return $mapped;
|
|
17 } elsif ($Type->Attributes and $Type->GetAttribute('ValueType')) {
|
|
18 return $this->{$DBValueType};
|
|
19 } else {
|
|
20 return $this->{$DBIdentifierType};
|
|
21 }
|
|
22 }
|
|
23
|
|
24 package Schema::DataSource::TypeMapping::Std;
|
|
25 use Schema::DB::Type;
|
|
26 our @ISA = qw(Schema::DataSource::TypeMapping);
|
|
27
|
|
28 sub CTOR {
|
|
29 my ($this) = @_;
|
|
30 $this->SUPER::CTOR(
|
|
31 Mappings => {
|
|
32 Identifier => new Schema::DB::Type(Name => 'Integer'),
|
|
33 String => new Schema::DB::Type(Name => 'varchar', MaxLength => 255),
|
|
34 Integer => new Schema::DB::Type(Name => 'Integer'),
|
|
35 Float => new Schema::DB::Type(Name => 'Real'),
|
|
36 DateTime => new Schema::DB::Type(Name => 'DateTime'),
|
|
37 Bool => new Schema::DB::Type(Name => 'Tinyint'),
|
|
38 Blob => new Schema::DB::Type(Name => 'Blob'),
|
|
39 Text => new Schema::DB::Type(Name => 'Text')
|
|
40 },
|
|
41 DBIdentifierType => new Schema::DB::Type(Name => 'Integer'),
|
|
42 DBValueType => new Schema::DB::Type(Name => 'varchar', MaxLength => 255)
|
|
43 );
|
|
44 }
|
|
45
|
|
46 1;
|