7 |
############################################ |
############################################ |
8 |
# |
# |
9 |
# $Log$ |
# $Log$ |
10 |
|
# Revision 1.14 2002/12/19 16:27:59 joko |
11 |
|
# - moved 'sub dropDb' to Data::Storage::Handler::DBI |
12 |
|
# |
13 |
|
# Revision 1.13 2002/12/17 21:54:12 joko |
14 |
|
# + feature when using Tangram: |
15 |
|
# + what? each object created should delivered with a globally(!?) unique identifier (GUID) besides the native tangram object id (OID) |
16 |
|
# + patched Tangram::Storage (jonen) |
17 |
|
# + enhanced Data::Storage::Schema::Tangram (joko) |
18 |
|
# + enhanced Data::Storage::Handler::Tangram 'sub getObjectByGuid' (jonen) |
19 |
|
# + how? |
20 |
|
# + each concrete (non-abstract) class gets injected with an additional field/property called 'guid' - this is done (dynamically) on schema level |
21 |
|
# + this property ('guid') gets filled on object creation/insertion from 'sub Tangram::Storage::_insert' using Data::UUID from CPAN |
22 |
|
# + (as for now) this property can get accessed by calling 'getObjectByGuid' on the already known storage-handle used throughout the application |
23 |
|
# |
24 |
|
# Revision 1.12 2002/12/12 02:50:15 joko |
25 |
|
# + this now (unfortunately) needs DBI for some helper functions |
26 |
|
# + TODO: these have to be refactored to another scope! (soon!) |
27 |
|
# |
28 |
|
# Revision 1.11 2002/12/11 06:53:19 joko |
29 |
|
# + updated pod |
30 |
|
# |
31 |
|
# Revision 1.10 2002/12/07 03:37:23 joko |
32 |
|
# + updated pod |
33 |
|
# |
34 |
|
# Revision 1.9 2002/12/01 22:15:45 joko |
35 |
|
# - sub createDb: moved to handler |
36 |
|
# |
37 |
# Revision 1.8 2002/11/29 04:48:23 joko |
# Revision 1.8 2002/11/29 04:48:23 joko |
38 |
# + updated pod |
# + updated pod |
39 |
# |
# |
74 |
|
|
75 |
=head1 NAME |
=head1 NAME |
76 |
|
|
77 |
Data::Storage - Interface for accessing various Storage implementations for Perl in an independent way |
Data::Storage - Interface for accessing various Storage implementations for Perl in an independent way |
78 |
|
|
79 |
|
|
80 |
=head1 AIMS |
=head1 AIMS |
188 |
|
|
189 |
=head2 NOTE |
=head2 NOTE |
190 |
|
|
191 |
This module heavily relies on DBI and Tangram, but adds a lot of additional bugs and quirks. |
This module heavily relies on DBI and Tangram, but adds a lot of additional bugs and quirks. |
192 |
Please look at their documentation and/or this code for additional information. |
Please look at their documentation and/or this code for additional information. |
193 |
|
|
194 |
|
|
195 |
=head1 REQUIREMENTS |
=head1 REQUIREMENTS |
217 |
use Data::Storage::Locator; |
use Data::Storage::Locator; |
218 |
use Data::Dumper; |
use Data::Dumper; |
219 |
|
|
220 |
|
# TODO: wipe out! |
221 |
|
use DBI; |
222 |
|
|
223 |
# TODO: actually implement level (integrate with Log::Dispatch) |
# TODO: actually implement level (integrate with Log::Dispatch) |
224 |
my $TRACELEVEL = 0; |
my $TRACELEVEL = 0; |
225 |
|
|
385 |
return $database_name; |
return $database_name; |
386 |
} |
} |
387 |
|
|
|
sub testDsn { |
|
|
my $self = shift; |
|
|
my $dsn = $self->{locator}->{dbi}->{dsn}; |
|
|
my $result; |
|
|
if ( my $dbh = DBI->connect($dsn, '', '', { |
|
|
PrintError => 0, |
|
|
} ) ) { |
|
|
$dbh->disconnect(); |
|
|
return 1; |
|
|
} else { |
|
|
$logger->warning( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); |
|
|
} |
|
|
} |
|
|
|
|
388 |
sub testAvailability { |
sub testAvailability { |
389 |
my $self = shift; |
my $self = shift; |
390 |
my $status = $self->testDsn(); |
my $status = $self->testDsn(); |
392 |
return $status; |
return $status; |
393 |
} |
} |
394 |
|
|
395 |
sub createDb { |
sub isConnected { |
396 |
my $self = shift; |
my $self = shift; |
397 |
my $dsn = $self->{locator}->{dbi}->{dsn}; |
# TODO: REVIEW! |
398 |
|
return 1 if $self->{STORAGEHANDLE}; |
|
$logger->debug( __PACKAGE__ . "->createDb( dsn $dsn )" ); |
|
|
|
|
|
$dsn =~ s/database=(.+?);//; |
|
|
my $database_name = $1; |
|
|
|
|
|
my $ok; |
|
|
|
|
|
if ( my $dbh = DBI->connect($dsn, '', '', { |
|
|
PrintError => 0, |
|
|
} ) ) { |
|
|
if ($database_name) { |
|
|
if ($dbh->do("CREATE DATABASE $database_name;")) { |
|
|
$ok = 1; |
|
|
} |
|
|
} |
|
|
$dbh->disconnect(); |
|
|
} |
|
|
|
|
|
return $ok; |
|
|
|
|
399 |
} |
} |
400 |
|
|
401 |
sub dropDb { |
sub testDsn { |
402 |
my $self = shift; |
my $self = shift; |
403 |
my $dsn = $self->{locator}->{dbi}->{dsn}; |
my $dsn = $self->{locator}->{dbi}->{dsn}; |
404 |
|
my $result; |
|
$logger->debug( __PACKAGE__ . "->dropDb( dsn $dsn )" ); |
|
|
|
|
|
$dsn =~ s/database=(.+?);//; |
|
|
my $database_name = $1; |
|
|
|
|
|
my $ok; |
|
|
|
|
405 |
if ( my $dbh = DBI->connect($dsn, '', '', { |
if ( my $dbh = DBI->connect($dsn, '', '', { |
406 |
PrintError => 0, |
PrintError => 0, |
407 |
} ) ) { |
} ) ) { |
408 |
if ($database_name) { |
|
409 |
if ($dbh->do("DROP DATABASE $database_name;")) { |
# TODO: REVIEW |
|
$ok = 1; |
|
|
} |
|
|
} |
|
410 |
$dbh->disconnect(); |
$dbh->disconnect(); |
411 |
|
|
412 |
|
return 1; |
413 |
|
} else { |
414 |
|
$logger->warning( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); |
415 |
} |
} |
|
|
|
|
return $ok; |
|
|
} |
|
|
|
|
|
sub isConnected { |
|
|
my $self = shift; |
|
|
return 1 if $self->{STORAGEHANDLE}; |
|
416 |
} |
} |
417 |
|
|
418 |
1; |
1; |
421 |
|
|
422 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
423 |
|
|
424 |
Data::Storage is a module for accessing various "data structures" stored inside |
=head2 Data::Storage |
|
various "data containers". It sits on top of DBI and/or Tangram. |
|
425 |
|
|
426 |
|
Data::Storage is a module for accessing various "data structures / kinds of structured data" stored inside |
427 |
|
various "data containers". |
428 |
|
We tried to use the AdapterPattern (http://c2.com/cgi/wiki?AdapterPattern) to implement a wrapper-layer |
429 |
|
around core CPAN modules (Tangram, DBI). |
430 |
|
|
431 |
|
=head2 Why? |
432 |
|
|
433 |
|
You will get a better code-structure (not bad for later maintenance) in growing Perl code projects, |
434 |
|
especially when using multiple database connections at the same time. |
435 |
|
You will be able to switch between different _kinds_ of implementations used for storing data. |
436 |
|
Your code will use the very same API to access these storage layers. |
437 |
|
... implementation has to be changed for now |
438 |
|
Maybe you will be able to switch "on-the-fly" without changing any bits in code in the future.... |
439 |
|
... but that's not the focus |
440 |
|
|
441 |
=head1 AUTHORS / COPYRIGHT |
=head2 What else? |
442 |
|
|
443 |
The Data::Storage module is Copyright (c) 2002 Andreas Motl. |
Having this, we were able to do implement a generic data synchronization module more easy, |
444 |
All rights reserved. |
please look at Data::Transfer. |
445 |
|
|
446 |
|
|
447 |
|
=head1 AUTHORS / COPYRIGHT |
448 |
|
|
449 |
You may distribute it under the terms of either the GNU General Public |
The Data::Storage module is Copyright (c) 2002 Andreas Motl. |
450 |
License or the Artistic License, as specified in the Perl README file. |
All rights reserved. |
451 |
|
You may distribute it under the terms of either the GNU General Public |
452 |
|
License or the Artistic License, as specified in the Perl README file. |
453 |
|
|
454 |
|
|
455 |
=head1 ACKNOWLEDGEMENTS |
=head1 ACKNOWLEDGEMENTS |
456 |
|
|
457 |
Larry Wall for Perl, Tim Bunce for DBI, Jean-Louis Leroy for Tangram and Set::Object, |
Larry Wall for Perl, Tim Bunce for DBI, Jean-Louis Leroy for Tangram and Set::Object, |
458 |
Sam Vilain for Class::Tangram, Jochen Wiedmann and Jeff Zucker for DBD::CSV and related, |
Sam Vilain for Class::Tangram, Jochen Wiedmann and Jeff Zucker for DBD::CSV & Co., |
459 |
Adam Spiers for MySQL::Diff and all contributors. |
Adam Spiers for MySQL::Diff and all contributors. |
460 |
|
|
461 |
|
|
462 |
=head1 SUPPORT / WARRANTY |
=head1 SUPPORT / WARRANTY |
463 |
|
|
464 |
Data::Storage is free software. IT COMES WITHOUT WARRANTY OF ANY KIND. |
Data::Storage is free software. IT COMES WITHOUT WARRANTY OF ANY KIND. |
465 |
|
|
466 |
|
|
467 |
=head1 TODO |
=head1 TODO |
532 |
- .pst - files (Outlook Post Storage?) |
- .pst - files (Outlook Post Storage?) |
533 |
- XML (e.g. via XML::Simple?) |
- XML (e.g. via XML::Simple?) |
534 |
- Move to t3, look at InCASE |
- Move to t3, look at InCASE |
535 |
|
- some kind of security layer for methods/objects |
536 |
|
- acls (stored via tangram/ldap?) for functions, methods and objects (entity- & data!?) |
537 |
|
- where are the hooks needed then? |
538 |
|
- is Data::Storage & Co. okay, or do we have to touch the innards of DBI and/or Tangram? |
539 |
|
- an attempt to start could be: |
540 |
|
- 'sub getACLByObjectId($id, $context)' |
541 |
|
- 'sub getACLByMethodname($id, $context)' |
542 |
|
- 'sub getACLByName($id, $context)' |
543 |
|
( would require a kinda registry to look up these very names pointing to arbitrary locations (code, data, ...) ) |
544 |
|
- add more hooks and various levels |
545 |
|
- better integrate introduced 'getObjectByGuid'-mechanism from Data::Storage::Handler::Tangram |
546 |
|
|
547 |
|
|
548 |
=head3 LINKS / REFERENCES |
=head3 LINKS / REFERENCES |