[Jifty-commit] r2780 - in jifty/branches/virtual-models: . lib/Jifty t/TestApp/t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sat Feb 10 18:59:31 EST 2007


Author: jesse
Date: Sat Feb 10 18:59:31 2007
New Revision: 2780

Added:
   jifty/branches/virtual-models/lib/Jifty/Manual/Config.pm
Modified:
   jifty/branches/virtual-models/   (props changed)
   jifty/branches/virtual-models/lib/Jifty/Config.pm
   jifty/branches/virtual-models/lib/Jifty/Handle.pm
   jifty/branches/virtual-models/t/TestApp/t/uuid.t

Log:
 r21972 at hualien:  jesse | 2007-02-10 18:57:47 -0500
 * Added the ability to configure uuid generation.


Modified: jifty/branches/virtual-models/lib/Jifty/Config.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Config.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Config.pm	Sat Feb 10 18:59:31 2007
@@ -254,6 +254,7 @@
                 Password => "",
                 User     => "",
                 Version  => "0.0.1",
+                RecordUUIDs => 'active',
                 RecordBaseClass => 'Jifty::DBI::Record::Cachable',
                 CheckSchema => '1'
             },

Modified: jifty/branches/virtual-models/lib/Jifty/Handle.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Handle.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Handle.pm	Sat Feb 10 18:59:31 2007
@@ -228,7 +228,7 @@
 
     my $rv = $self->SUPER::insert($table, %args);
 
-    if ($rv) {
+    if ($rv and ($uuid || Jifty->config->framework('Database')->{'RecordUUIDs'} !~ /^(?:lazy|off)/i) ) {
         $self->_insert_uuid( table => $table, id => $rv, uuid => $uuid);
 
     }
@@ -243,12 +243,13 @@
                 id => undef,
                 uuid => undef,
                 @_);
+           my $uuid =  ($args{uuid} || Jifty::Util->generate_uuid);
         # Generate a UUID on the sideband: $table - $rv - UUID.
         $self->dbh->do(
             qq[ INSERT INTO _jifty_uuids VALUES (?, ?, ?) ], {},
-            ($args{uuid} || Jifty::Util->generate_uuid), $args{table}, $args{id}
+           $uuid , $args{table}, $args{id}
         );
-
+    return $uuid; 
 }
 
 =head2 bootstrap_uuid_table 
@@ -286,7 +287,11 @@
 
 sub lookup_uuid {
     my ($self, $table, $id) = @_;
+    return undef unless ( Jifty->config->framework('Database')->{'RecordUUIDs'} ne 'off');
     my ($uuid) = $self->fetch_result(qq[ SELECT uuid FROM _jifty_uuids WHERE row_table = ? AND row_id = ?  ], $table, $id);
+    unless ($uuid) {
+        $uuid = $self->_insert_uuid( table => $table, id => $id);
+    }
     return $uuid;
 }
 

Added: jifty/branches/virtual-models/lib/Jifty/Manual/Config.pm
==============================================================================
--- (empty file)
+++ jifty/branches/virtual-models/lib/Jifty/Manual/Config.pm	Sat Feb 10 18:59:31 2007
@@ -0,0 +1,116 @@
+
+=head1 NAME
+
+Jifty::Manual::Config
+
+
+=head1 CONTENT
+
+THIS IS NOTES SO THAT SOMEONE CAN TURN THEM INTO A REAL MANUAL CHAPTER
+
+
+Jifty has four stages of configuration:
+
+
+* internal default config
+
+* app configuration
+
+* vendor configuration
+
+* site configuration.
+
+
+All four are merged together. Your configuration overrides the vendor's configuration which overrides the app configuration which overrides the internal defaults.
+
+When you create an application, jifty writes out the standard default to C<etc/config.yml>.
+
+
+The configuration is split into two sections
+
+=head2 Framework
+
+There are some toplevel configuration directives at the framework level and some sections:
+
+
+=head3 Configuration directives
+
+
+            AdminMode        => 1,
+            DevelMode        => 1,
+            ApplicationClass => $app_class,
+            ApplicationName  => $app_name,
+            ApplicationUUID  => $app_uuid,
+            LogLevel         => 'INFO',
+
+            Mailer     => 'Sendmail',
+            MailerArgs => [],
+            L10N       => {
+                PoDir => "share/po",
+            },
+            Plugins    => [],
+
+=head3 Sections
+
+=head4 PubSub
+
+            PubSub           => {
+                Enable => undef,
+                Backend => 'Memcached',
+                    },
+
+=head4 Database
+
+=over
+=item                Database =>  $db_name,
+
+=item                Driver   => "SQLite",
+
+SQLite, Pg, mysql, Oracle. These correspond to DBI driver names
+
+
+=item                Host     => "localhost",
+
+=item                Password => "",
+
+=item                User     => "",
+
+=item                Version  => "0.0.1",
+
+=item                RecordUUIDs => 'active',
+
+The three options are: C<active>, C<lazy>, C<off>
+
+In C<active> mode, Jifty will record a uuid for any record as it's inserted
+into the database.  In C<lazy> mode, Jifty will only create a UUID for a row the first time you ask for it. In "off" mode, Jifty will never generate UUIDs for records and asking for one will always return C<undef>. If you don't intend to use UUIDs, the C<lazy> setting is recommended, as certain jifty admin tools can make use of UUIDs.
+ 
+
+
+=item                RecordBaseClass => 'Jifty::DBI::Record::Cachable',
+
+=item                CheckSchema => '1'
+
+=back
+
+=head4 Web
+
+            Web        => {
+                Port => '8888',
+                BaseURL => 'http://localhost',
+                DataDir     => "var/mason",
+                StaticRoot   => "share/web/static",
+                TemplateRoot => "share/web/templates",
+                ServeStaticFiles => 1,
+                MasonConfig => {
+                    autoflush    => 0,
+                    error_mode   => 'fatal',
+                    error_format => 'text',
+                    default_escape_flags => 'h',
+                },
+                Globals      => [],
+
+
+=head2 Application
+
+
+Inside this section, you can stuff anything you want. Have fun

Modified: jifty/branches/virtual-models/t/TestApp/t/uuid.t
==============================================================================
--- jifty/branches/virtual-models/t/TestApp/t/uuid.t	(original)
+++ jifty/branches/virtual-models/t/TestApp/t/uuid.t	Sat Feb 10 18:59:31 2007
@@ -11,7 +11,7 @@
 use lib 't/lib';
 use Jifty::SubTest;
 
-use Jifty::Test tests => 12;
+use Jifty::Test tests => 31;
 # Make sure we can load the model
 use_ok('TestApp::Model::User');
 
@@ -19,6 +19,45 @@
 my $system_user = TestApp::CurrentUser->superuser;
 ok($system_user, "Found a system user");
 
+
+Jifty->config->framework('Database')->{'RecordUUIDs'} = 'lazy';
+run_uuid_tests();
+Jifty->config->framework('Database')->{'RecordUUIDs'} = 'active';
+run_uuid_tests();
+Jifty->config->framework('Database')->{'RecordUUIDs'} = 'off';
+run_uuid_tests_off();
+
+
+
+sub run_uuid_tests_off {
+
+# Try testing a create
+my $o = TestApp::Model::User->new(current_user => $system_user);
+my ($id) = $o->create( name => $$, email => $$, password => $$ );
+ok($id, "User create returned success");
+ok($o->id, "New User has valid id set");
+is($o->id, $id, "Create returned the right id");
+is($o->name, $$, "Created object has the right name");
+ok(!$o->__uuid, "We got no UUID");
+
+
+
+# And another
+my $p = TestApp::Model::User->new(current_user => $system_user);
+$p->create( name => $$, email => $$, password => $$ );
+ok($p->id, "User create returned another value");
+is($p->__uuid,undef, "And it is different from the previous one");
+
+my $generated_uuid = Jifty::Util->generate_uuid;
+my $q = TestApp::Model::User->new(current_user => $system_user);
+$q->create( name => $$, email => $$, password => $$, __uuid =>$generated_uuid);
+ok($q->id, "User create returned another value");
+is($q->__uuid, undef, "When UUIDs are off, we really make sure that even explicit uuids get dropped");
+}
+
+
+sub run_uuid_tests {
+
 # Try testing a create
 my $o = TestApp::Model::User->new(current_user => $system_user);
 my ($id) = $o->create( name => $$, email => $$, password => $$ );
@@ -42,5 +81,5 @@
 ok($q->id, "User create returned another value");
 is($q->__uuid, $generated_uuid);
 isnt($q->__uuid, $o->__uuid, "And it is different from the previous one");
-
+}
 


More information about the Jifty-commit mailing list