Author: spadkins
Date: Fri Jan 6 08:47:14 2012
New Revision: 15071
Added:
p5ee/trunk/App-Repository/bin/dbmetadata (contents, props changed)
Log:
support metadata caching on disk. (first release candidate)
Added: p5ee/trunk/App-Repository/bin/dbmetadata
==============================================================================
--- (empty file)
+++ p5ee/trunk/App-Repository/bin/dbmetadata Fri Jan 6 08:47:14 2012
@@ -0,0 +1,125 @@
+#!/usr/local/bin/perl -w
+
+use Date::Format;
+
+use App::Options (
+ options => [ qw(dbhost dbname dbschema dbuser dbpass repository class
table tmpdir verbose) ],
+ option => {
+ repository => {
+ description => "Name of repository",
+ },
+ class => {
+ description => "The class of the Repository
(App::Repository::MySQL, App::Repository::Oracle) (if not as currently
defined)",
+ },
+ table => {
+ description => "List of table names (default is all)",
+ },
+ tmpdir => {
+ description => "Temporary directory used for writing out the
metadata",
+ default => '${prefix}/tmp',
+ },
+ force_metadata_reload => {
+ description => "Activates the metadata loading from the database
regardless of whether the files exist",
+ default => 1,
+ },
+ force_metadata_write => {
+ description => "Activates the metadata writing to the file system",
+ default => 1,
+ },
+ verbose => {
+ description => "Verbose level",
+ default => 1,
+ },
+ },
+);
+
+use App;
+use Data::Dumper;
+use strict;
+
+$| = 1; # autoflush stdout
+
+{
+ my $context = App->context();
+ my $options = $context->{options};
+ my $repname = $options->{repository} || "default";
+ my $realrep = $context->repository($repname);
+ my $class = $options->{class};
+ my ($rep);
+ if ($realrep->isa("App::Repository::DBI")) {
+ my $class = ref($realrep);
+ my ($dbhost, $dbname, $dbschema, $dbuser, $dbpass);
+ if ($options->{"$repname.dbhost"} ||
+ $options->{"$repname.dbname"} ||
+ $options->{"$repname.dbschema"} ||
+ $options->{"$repname.dbuser"} ||
+ $options->{"$repname.dbpass"}) {
+ $dbhost = $options->{"$repname.dbhost"};
+ $dbname = $options->{"$repname.dbname"};
+ $dbschema = $options->{"$repname.dbschema"};
+ $dbuser = $options->{"$repname.dbuser"};
+ $dbpass = $options->{"$repname.dbpass"};
+ }
+ else {
+ $dbhost = $options->{dbhost};
+ $dbname = $options->{dbname};
+ $dbschema = $options->{dbschema};
+ $dbuser = $options->{dbuser};
+ $dbpass = $options->{dbpass};
+ }
+ $options->{"_meta.dbhost"} = $dbhost if ($dbhost);
+ $options->{"_meta.dbname"} = $dbname if ($dbname);
+ $options->{"_meta.dbschema"} = $dbschema if ($dbschema);
+ $options->{"_meta.dbuser"} = $dbuser if ($dbuser);
+ $options->{"_meta.dbpass"} = $dbpass if ($dbpass);
+
+ $rep = $context->repository($repname, class => $class);
+ }
+ else {
+ $rep = $realrep;
+ }
+ #print $rep->dump();
+
+ my $table = $options->{table};
+ my $verbose = $options->{verbose};
+ my ($tables, $table_def);
+ if ($table) {
+ $tables = [ split(/,/, $table) ];
+ }
+ else {
+ $tables = $rep->get_phys_table_names();
+ }
+ foreach my $tab (@$tables) {
+ print "Getting table_def for $tab...\n";
+ $table_def = $rep->get_table_def($tab);
+# my $tabalias = $table_def->{alias} || &sym2abbr($tab);
+# my $column_defs = $table_def->{column};
+# print
"#######################################################################\n";
+# print Dumper $table_def;
+# print <<EOF;
+# $tab => {
+# alias => "$tabalias",
+# tablealias => {
+# $tabalias => {
+# table => "$tab",
+# },
+# },
+#EOF
+# foreach my $col (keys %$column_defs) {
+# printf(" %-30s => { dbexpr => \"$tabalias.$col\",
},\n", $col);
+# }
+# print <<EOF;
+# },
+#EOF
+ }
+}
+
+sub sym2abbr {
+ my ($sym) = @_;
+ my @abbr = grep { s/^(.).*/$1/ } split(/_/, lc($sym));
+ my $abbr = join("", @abbr);
+ return($abbr);
+}
+
+exit (0);
+