SlideShare une entreprise Scribd logo
1  sur  25
Data::ObjectDriver
        id:clouder
     Yokohama.pm #5
About D::OD
• Author: Benjamin Trott
• Recently Version: 0.06
• Simple, transparent data interface, with
  caching.
• Based on MT::ObjectDriver in MT.
  Now MT included D::OD.
D::OD features
• Built-in supportRAM and Apache inPartitioning.
  Support Memcached,
                     Caching and
                                    caching.

• Have to support master-slaver_handle()/rw_handle().
  Can change process for read/write using
                                          structure in mind.

• Implementation is becauseso less model feature.
  But implement by myself,
                           thin, east-to-use.
                                of
   Has ‘has_a’ but not has ‘has_many’.
Class structures
• Driver definition about how to connection to
  Class for
            class
   db and cache server, and partitioning rules.

• Object classwhat you call.
  The model class
   Class for definition about how to treat data on tables.
Class structures
• Other classes
 - D::OD::ResultSet
   In the middle of an implementation?
      Do not use in MT.

  -   D::OD::Profiler
      Simple profiler.

  -   D::OD::GearmanDBI
      I do not know how to use;)
Simple usase
• Make object class for table
  Make sub-class of D::OD::BaseObject,
   and set table information using install_properties().
   ‘driver’ is D::OD::Driver::DBI.
Simple usage
package Artist;
use strict;
use base qw( Data::ObjectDriver::BaseObject );

__PACKAGE__->install_properties(
   datasource => 'artist',
   columns     => [ qw( id name orig_name band_id ) ],
   primary_key => 'id',
   driver      => Data::ObjectDriver::Driver::DBI->new( %DB_INFO ),
);

1;
CRUD and etc
• Create
my artist = Artist->new(
  name => '                   ',
   fullname => '                         II   '
);
$artist->save;
# or
Artist->bulk_insert( [col1, col2], [ [d1, d2], [d1, d2] ]);
CRUD and etc
  • Read
my $artist = Artist->lookup(1);
print $artist->name;
# or
$artist_iter = Artist->search( { name => '            ' } );
@artists = Artist->search( { name => '           ' );
# or
$artists_ref = Artist->lookup_multi( [ 1, 2, 3 ] );
CRUD and etc
• Update
 $artist->name( '   ' );
 $artist->save;
CRUD and etc
• Delete

 $artist->remove;
CRUD and etc
• has_a()
 __PACKAGE__->has_a( {
     class => 'Band',
     column => 'band_id',
     cached => 1,
 } );
CRUD and etc
• add_trigger() post_load pre_search pre_insert
  pre_save post_save
   post_insert pre_update post_update pre_remove
   post_remove post_inflate

 __PACKAGE__->add_trigger(
    pre_insert => sub {
       my ( $obj, $orig_obj ) = @_;
       ...
    },
 );
Caching
• Only change driver
  If there is not cache,
  connect to db using D::OD::Driver::DBI.
Caching
package Artist;
use strict;
use base qw( Data::ObjectDriver::BaseObject );

__PACKAGE__->install_properties(
   ...
   driver => Data::ObjectDriver::Driver::Cache::Memcached->new(
       cache => Cache::Memcached->new( servers => @servers ),
       fallback => Data::ObjectDriver::Driver::DBI->new( %DB_INFO ),
   ),
   ...
);

1;
Master-Slave structure
• Only override r_handle().in read process,
  r_handle() is method that execute
  so this method is used to connect to slave database.
Master-Slave structure
 • Object class
package Artist;
use strict;
use base qw( Data::ObjectDriver::BaseObject );

__PACKAGE__->install_properties(
   ...
   driver => Data::ObjectDriver::Driver::Cache::Memcached->new(
       cache => Cache::Memcached->new( servers => @servers ),
       fallback => ReplDriver->new( %DB_INFO, slaves => [ slave01, ... ] ),
   ),
   ...
);
Master-Slave structure
 • Driver class
package ReplDriver;
use strict;
use base qw( Data::ObjectDriver::Driver::DBI );

__PACKAGE__->mk_accessors( qw( slaves ) );

sub init {
  my $driver = shift;
  my %param = @_;
  $driver->slaves( delete $param{ slaves } );
  $driver->SUPER::init( %param );
  return $driver;
}

# cont.
Master-Slave structure
 • Driver class(cont.)
# cont.

sub r_handle {
  my $driver = shift;
  my $db = shift || 'main';
  for my $slave ( shuffle @{ $driver->slaves } ) {
     # connect to $slave
     my $dbh = DBI->connect( $slave->{DB_INFO} );
     $driver->dbd->init_dbh($dbh);
     return $dbh;
  }
  $driver->rw_handle($db);
}

1;
Partitioning
package CD;
use strict;
use base qw( Data::ObjectDriver::BaseObject );

__PACKAGE__->install_properties(
   datasource => 'cd',
   columns     => [ qw( artist_id id title ) ],
   primary_key => [ qw( artist_id id ) ],
   driver      => PartitionDriver->driver,
);

1;
Partitioning
package PartitionDriver;
use strict;

sub driver {
  my $fallback = Data::ObjectDriver::Driver::Partition->new(
     get_driver => &find_partition,
  );
  Data::ObjectDriver::Driver::Cache::Memcached->new(
     cache => Cache::Memcached->new( servers => @servers ),
     fallback => $fallback,
  ),
}

# cont.
Partitioning
# cont.

sub find_partition {
  my ( $terms, $args ) = @_;
  my $artist = Artist->lookup( $terms->{ artist_id } );
  return ReplDriver->new(
     %{ $artist->partition_obj->master },
     slaves => $artist->partition_obj->slaves,
     pk_generator => &pk_generator,
  );
}

sub pk_generator {
   my $obj = shift;
   $obj->id( generate_id() );
   1;
},

1;
Partitioning

my $cd = CD->new(
  artist_id => 1,
  title => '      '
);
$cd->save;


lookup() is depends on PartitionDriver implementation in partitioning.
At the end, I wish...
• Built-in support pager using Data::Page.
• Wants count() and more useful methods.
• Hard to execute simple SQL.
  (Just do using D::OD::SQL?)
• And hard to execute ‘JOIN’.
Fin.

Contenu connexe

Tendances

Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
Plack on SL4A in Yokohama.pm #8
Plack on SL4A in Yokohama.pm #8Plack on SL4A in Yokohama.pm #8
Plack on SL4A in Yokohama.pm #8
Yoshiki Kurihara
 
Bootstrap your Cloud Infrastructure using puppet and hashicorp stack
Bootstrap your Cloud Infrastructure using puppet and hashicorp stackBootstrap your Cloud Infrastructure using puppet and hashicorp stack
Bootstrap your Cloud Infrastructure using puppet and hashicorp stack
Bram Vogelaar
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
som_nangia
 

Tendances (20)

Puppet and the HashiCorp Suite
Puppet and the HashiCorp SuitePuppet and the HashiCorp Suite
Puppet and the HashiCorp Suite
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet Profiles
 
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-ThonApache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
 
D2
D2D2
D2
 
Plack on SL4A in Yokohama.pm #8
Plack on SL4A in Yokohama.pm #8Plack on SL4A in Yokohama.pm #8
Plack on SL4A in Yokohama.pm #8
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
 
Practical Testing of Ruby Core
Practical Testing of Ruby CorePractical Testing of Ruby Core
Practical Testing of Ruby Core
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
mruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなしmruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなし
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStack
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
Bootstrap your Cloud Infrastructure using puppet and hashicorp stack
Bootstrap your Cloud Infrastructure using puppet and hashicorp stackBootstrap your Cloud Infrastructure using puppet and hashicorp stack
Bootstrap your Cloud Infrastructure using puppet and hashicorp stack
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 

Similaire à About Data::ObjectDriver

DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
chuvainc
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
Kar Juan
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objects
webhostingguy
 
CHI-YAPC-2009
CHI-YAPC-2009CHI-YAPC-2009
CHI-YAPC-2009
jonswar
 
Nko workshop - node js & nosql
Nko workshop - node js & nosqlNko workshop - node js & nosql
Nko workshop - node js & nosql
Simon Su
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 

Similaire à About Data::ObjectDriver (20)

DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たち
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic Components
 
DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Edition
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objects
 
Terraform Cosmos DB
Terraform Cosmos DBTerraform Cosmos DB
Terraform Cosmos DB
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
 
Mojo – Simple REST Server
Mojo – Simple REST ServerMojo – Simple REST Server
Mojo – Simple REST Server
 
Api Design
Api DesignApi Design
Api Design
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
 
CHI-YAPC-2009
CHI-YAPC-2009CHI-YAPC-2009
CHI-YAPC-2009
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
Nko workshop - node js & nosql
Nko workshop - node js & nosqlNko workshop - node js & nosql
Nko workshop - node js & nosql
 
Scaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterScaling Databases with DBIx::Router
Scaling Databases with DBIx::Router
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

About Data::ObjectDriver

  • 1. Data::ObjectDriver id:clouder Yokohama.pm #5
  • 2. About D::OD • Author: Benjamin Trott • Recently Version: 0.06 • Simple, transparent data interface, with caching. • Based on MT::ObjectDriver in MT. Now MT included D::OD.
  • 3. D::OD features • Built-in supportRAM and Apache inPartitioning. Support Memcached, Caching and caching. • Have to support master-slaver_handle()/rw_handle(). Can change process for read/write using structure in mind. • Implementation is becauseso less model feature. But implement by myself, thin, east-to-use. of Has ‘has_a’ but not has ‘has_many’.
  • 4. Class structures • Driver definition about how to connection to Class for class db and cache server, and partitioning rules. • Object classwhat you call. The model class Class for definition about how to treat data on tables.
  • 5. Class structures • Other classes - D::OD::ResultSet In the middle of an implementation? Do not use in MT. - D::OD::Profiler Simple profiler. - D::OD::GearmanDBI I do not know how to use;)
  • 6. Simple usase • Make object class for table Make sub-class of D::OD::BaseObject, and set table information using install_properties(). ‘driver’ is D::OD::Driver::DBI.
  • 7. Simple usage package Artist; use strict; use base qw( Data::ObjectDriver::BaseObject ); __PACKAGE__->install_properties( datasource => 'artist', columns => [ qw( id name orig_name band_id ) ], primary_key => 'id', driver => Data::ObjectDriver::Driver::DBI->new( %DB_INFO ), ); 1;
  • 8. CRUD and etc • Create my artist = Artist->new( name => ' ', fullname => ' II ' ); $artist->save; # or Artist->bulk_insert( [col1, col2], [ [d1, d2], [d1, d2] ]);
  • 9. CRUD and etc • Read my $artist = Artist->lookup(1); print $artist->name; # or $artist_iter = Artist->search( { name => ' ' } ); @artists = Artist->search( { name => ' ' ); # or $artists_ref = Artist->lookup_multi( [ 1, 2, 3 ] );
  • 10. CRUD and etc • Update $artist->name( ' ' ); $artist->save;
  • 11. CRUD and etc • Delete $artist->remove;
  • 12. CRUD and etc • has_a() __PACKAGE__->has_a( { class => 'Band', column => 'band_id', cached => 1, } );
  • 13. CRUD and etc • add_trigger() post_load pre_search pre_insert pre_save post_save post_insert pre_update post_update pre_remove post_remove post_inflate __PACKAGE__->add_trigger( pre_insert => sub { my ( $obj, $orig_obj ) = @_; ... }, );
  • 14. Caching • Only change driver If there is not cache, connect to db using D::OD::Driver::DBI.
  • 15. Caching package Artist; use strict; use base qw( Data::ObjectDriver::BaseObject ); __PACKAGE__->install_properties( ... driver => Data::ObjectDriver::Driver::Cache::Memcached->new( cache => Cache::Memcached->new( servers => @servers ), fallback => Data::ObjectDriver::Driver::DBI->new( %DB_INFO ), ), ... ); 1;
  • 16. Master-Slave structure • Only override r_handle().in read process, r_handle() is method that execute so this method is used to connect to slave database.
  • 17. Master-Slave structure • Object class package Artist; use strict; use base qw( Data::ObjectDriver::BaseObject ); __PACKAGE__->install_properties( ... driver => Data::ObjectDriver::Driver::Cache::Memcached->new( cache => Cache::Memcached->new( servers => @servers ), fallback => ReplDriver->new( %DB_INFO, slaves => [ slave01, ... ] ), ), ... );
  • 18. Master-Slave structure • Driver class package ReplDriver; use strict; use base qw( Data::ObjectDriver::Driver::DBI ); __PACKAGE__->mk_accessors( qw( slaves ) ); sub init { my $driver = shift; my %param = @_; $driver->slaves( delete $param{ slaves } ); $driver->SUPER::init( %param ); return $driver; } # cont.
  • 19. Master-Slave structure • Driver class(cont.) # cont. sub r_handle { my $driver = shift; my $db = shift || 'main'; for my $slave ( shuffle @{ $driver->slaves } ) { # connect to $slave my $dbh = DBI->connect( $slave->{DB_INFO} ); $driver->dbd->init_dbh($dbh); return $dbh; } $driver->rw_handle($db); } 1;
  • 20. Partitioning package CD; use strict; use base qw( Data::ObjectDriver::BaseObject ); __PACKAGE__->install_properties( datasource => 'cd', columns => [ qw( artist_id id title ) ], primary_key => [ qw( artist_id id ) ], driver => PartitionDriver->driver, ); 1;
  • 21. Partitioning package PartitionDriver; use strict; sub driver { my $fallback = Data::ObjectDriver::Driver::Partition->new( get_driver => &find_partition, ); Data::ObjectDriver::Driver::Cache::Memcached->new( cache => Cache::Memcached->new( servers => @servers ), fallback => $fallback, ), } # cont.
  • 22. Partitioning # cont. sub find_partition { my ( $terms, $args ) = @_; my $artist = Artist->lookup( $terms->{ artist_id } ); return ReplDriver->new( %{ $artist->partition_obj->master }, slaves => $artist->partition_obj->slaves, pk_generator => &pk_generator, ); } sub pk_generator { my $obj = shift; $obj->id( generate_id() ); 1; }, 1;
  • 23. Partitioning my $cd = CD->new( artist_id => 1, title => ' ' ); $cd->save; lookup() is depends on PartitionDriver implementation in partitioning.
  • 24. At the end, I wish... • Built-in support pager using Data::Page. • Wants count() and more useful methods. • Hard to execute simple SQL. (Just do using D::OD::SQL?) • And hard to execute ‘JOIN’.
  • 25. Fin.

Notes de l'éditeur