blib/lib/UR/DataSource/RDBMS/TableColumn.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 62 SCAR 24.8
CC
3
Cov
0%
_fk_constraint_class
6.0
is_time_data
6.0
get_table
2.0
CRAP 12.0
1 use strict;
2 use warnings;
3  
4 package UR::DataSource::RDBMS::TableColumn;
5  
6 use UR;
7 our $VERSION = "0.46"; # UR $VERSION;
8  
9 UR::Object::Type->define(
10 class_name => 'UR::DataSource::RDBMS::TableColumn',
11 is => ['UR::DataSource::RDBMS::Entity'],
12 dsmap => 'dd_table_column',
13 er_role => '',
14 id_properties => [qw/data_source table_name column_name/],
15 properties => [
16 column_name => { type => 'varchar', len => undef, sql => 'column_name' },
17 data_source => { type => 'varchar', len => undef, sql => 'data_source' },
18 data_source_obj => { type => 'UR::DataSource', id_by => 'data_source'},
19 namespace => { calculate_from => [ 'data_source'],
20 calculate => q( (split(/::/,$data_source))[0] ) },
21 owner => { type => 'varchar', len => undef, is_optional => 1, sql => 'owner' },
22 table_name => { type => 'varchar', len => undef, sql => 'table_name' },
23 data_length => { type => 'varchar', len => undef, is_optional => 1, sql => 'data_length' },
24 data_type => { type => 'varchar', len => undef, sql => 'data_type' },
25 last_object_revision => { type => 'timestamp', len => undef, sql => 'last_object_revision' },
26 nullable => { type => 'varchar', len => undef, sql => 'nullable' },
27 remarks => { type => 'varchar', len => undef, is_optional => 1, sql => 'remarks' },
28 ],
29 data_source => 'UR::DataSource::Meta',
30 );
31  
32 # Methods moved over from the old App::DB::TableColumn
33  
34 sub _fk_constraint_class {
35 my $self = shift;
36  
37 if (ref($self) =~ /::Ghost$/) {
38 return "UR::DataSource::RDBMS::FkConstraint::Ghost"
39 }
40 else {
41 return "UR::DataSource::RDBMS::FkConstraint"
42 }
43 }
44  
45 sub get_table {
46 my $self = shift;
47  
48 my $table_name = $self->table_name;
49 my $data_source = $self->data_source;
50 $data_source or Carp::confess("Can't determine data_source for table $table_name column ".$self->column_name );
51 my $table =
52 UR::DataSource::RDBMS::Table->get(table_name => $table_name, data_source => $data_source)
53 ||
54 UR::DataSource::RDBMS::Table::Ghost->get(table_name => $table_name, data_source => $data_source);
55 return $table;
56 }
57  
58  
59 sub fk_constraint_names {
60  
61 my @fks = shift->fk_constraints;
62 return map { $_->fk_constraint_name } @fks;
63 }
64  
65  
66 sub fk_constraints {
67 my $self = shift;
68  
69 my $fk_class = $self->_fk_constraint_class();
70 my @fks = $fk_class->get(table_name => $self->table_name,
71 data_source => $self->data_source);
72
73 return @fks;
74 }
75  
76  
77 sub bitmap_index_names {
78 Carp::confess("not implemented yet?!");
79 }
80  
81  
82 # the update classes code uses this. If the data type of a column is a time-ish format, then
83 # the data_length reported by the schema is the number of bytes used internally by the DB.
84 # Since the UR-object will store the time in text format, it will always be longer than
85 # that. To keep $obj->__errors__ from complaining, don't even bother storing the length of
86 # time-ish data
87 sub is_time_data {
88 my $self = shift;
89  
90 my $type = $self->data_type;
91 if ($type =~ m/TIMESTAMP|DATE|INTERVAL/i) {
92 return 1;
93 } else {
94 return;
95 }
96 }
97  
98 1;
99  
100 =pod
101  
102 =head1 NAME
103  
104 UR::DataSource::RDBMS::TableColumn - metadata about a data source's table's columns
105  
106 =head1 DESCRIPTION
107  
108 This class represents instances of columns in a data source's tables. They are
109 maintained by 'ur update classes' and stored in the namespace's MetaDB.
110  
111 =cut
112