1Workflow::Persister::DBUIs(e3r)Contributed Perl DocumentWaotrikofnlow::Persister::DBI(3)
2
3
4

NAME

6       Workflow::Persister::DBI - Persist workflow and history to DBI database
7

SYNOPSIS

9        <persister name="MainDatabase"
10                   class="Workflow::Persister::DBI"
11                   dsn="DBI:mysql:database=workflows"
12                   user="wf"
13                   password="mypass"/>
14
15        <persister name="BackupDatabase"
16                   class="Workflow::Persister::DBI"
17                   dsn="DBI:Pg:dbname=workflows"
18                   user="wf"
19                   password="mypass"
20                   workflow_table="wf"
21                   workflow_sequence="wf_seq"
22                   history_table="wf_history"
23                   history_sequence="wf_history_seq"/>
24

DESCRIPTION

26       Main persistence class for storing the workflow and workflow history
27       records to a DBI-accessible datasource.
28
29       Subclassing: Getting handle from elsewhere
30
31       A common need to create a subclass is to use a database handle created
32       with other means. For instance, OpenInteract has a central configura‐
33       tion file for defining datasources, and the datasource will be avail‐
34       able in a predictable manner. So we can create a subclass to provide
35       the database handle on demand from the "CTX" object available from
36       everywhere. A sample implementation is below. (Note that in real life
37       we would just use SPOPS for this, but it is still a good example.)
38
39        package Workflow::Persister::DBI::OpenInteractHandle;
40
41        use strict;
42        use base qw( Workflow::Persister::DBI );
43        use OpenInteract2::Context qw( CTX );
44
45        my @FIELDS = qw( datasource_name );
46        __PACKAGE__->mk_accessors( @FIELDS );
47
48        # override parent method, assuming that we set the 'datasource'
49        # parameter in the persister declaration
50
51        sub init {
52           my ( $self, $params ) = @_;
53           $self->datasource_name( $params->{datasource} );
54           my $ds_config = CTX->lookup_datasource_config( $self->datasource_name );
55
56           # delegate the other assignment tasks to the parent class
57
58           $self->assign_generators( $ds_config->{driver_name}, $params );
59           $self->assign_tables( $params );
60        }
61
62        sub handle {
63            my ( $self ) = @_;
64            return CTX->datasource( $self->datasource_name );
65        }
66
67       Subclassing: Changing fieldnames
68
69       Earlier versions of Workflow used the field 'user' to record in the
70       history the user making a state change or comment. Unfortunately 'user'
71       is a reserved word in our favorite database, PostgreSQL. (Oops.) So in
72       addition to changing the field to an assuredly-unreserved word (work‐
73       flow_user), we made the fieldnames customizable by subclasses.
74
75       Just override either or both of the methods:
76
77       get_workflow_fields()
78
79       Return list of fields in this order:
80
81         workflow_id, type, state, last_update
82
83       get_history_fields()
84
85       Return list of fields in this order:
86
87         workflow_hist_id, workflow_id, action, description,
88         state, workflow_user, history_date
89
90       Note that we may cache the results, so don't try and do anything weird
91       like change the fieldnames based on the workflow user or something...
92

METHODS

94       Public Methods
95
96       All public methods are inherited from Workflow::Persister.
97
98       Private Methods
99
100       init( \%params )
101
102       Create a database handle from the given parameters. You are only
103       required to provide 'dsn', which is the full DBI DSN you normally use
104       as the first argument to "connect()".
105
106       You may also use:
107
108       user
109           Name of user to login with.
110
111       password
112           Password for "user" to login with.
113
114       workflow_table
115           Table to use for persisting workflow. Default is 'workflow'.
116
117       history_table
118           Table to use for persisting workflow history. Default is 'work‐
119           flow_history'.
120
121       You may also use parameters for the different types of ID generators.
122       See below under the "init_*_generator" for the necessary parameters for
123       your database.
124
125       In addition to creating a database handle we parse the "dsn" to see
126       what driver we are using to determine how to generate IDs. We have the
127       ability to use automatically generated IDs for PostgreSQL, MySQL, and
128       SQLite. If your database is not included a randomly generated ID will
129       be used. (Default length of 8 characters, which you can modify with a
130       "id_length" parameter.)
131
132       You can also create your own adapter for a different type of database.
133       Just check out the existing Workflow::Persister::DBI::AutoGeneratedId
134       and Workflow::Persister::DBI::SequenceId classes for examples.
135
136       assign_generators( $driver, \%params )
137
138       Given $driver and the persister parameters in "\%params", assign the
139       appropriate ID generators for both the workflow and history tables.
140
141       Returns: nothing, but assigns the object properties "workflow_id_gener‐
142       ator" and "history_id_generator".
143
144       assign_tables( \%params )
145
146       Assign the table names from "\%params" (using 'workflow_table' and
147       'history_table') or use the defaults 'workflow' and 'workflow_history'.
148
149       Returns: nothing, but assigns the object properties "workflow_table"
150       and "history_table".
151
152       init_postgres_generators( \%params )
153
154       Create ID generators for the workflow and history tables using Post‐
155       greSQL sequences. You can specify the sequences used for the workflow
156       and history tables:
157
158       workflow_sequence
159           Sequence for the workflow table. Default: 'workflow_seq'
160
161       history_sequence
162           Sequence for the workflow history table. Default: 'workflow_his‐
163           tory_seq'
164
165       init_mysql_generators( \%params )
166
167       Create ID generators for the workflow and history tables using the
168       MySQL 'auto_increment' type. No parameters are necessary.
169
170       init_sqlite_generators( \%params )
171
172       Create ID generators for the workflow and history tables using the
173       SQLite implicit increment. No parameters are necessary.
174
175       init_random_generators( \%params )
176
177       Create ID generators for the workflow and history tables using a random
178       set of characters. You can specify:
179
180       id_length
181           Length of character sequence to generate. Default: 8.
182
183       #=head3 create_history
184
185       #=head3 create_workflow
186
187       #=head3 fetch_history
188
189       #=head3 fetch_workflow
190
191       #=head3 init_oracle_generators
192
193       #=head3 update_workflow
194

SEE ALSO

196       Workflow::Persister
197
199       Copyright (c) 2003-2004 Chris Winters. All rights reserved.
200
201       This library is free software; you can redistribute it and/or modify it
202       under the same terms as Perl itself.
203

AUTHORS

205       Chris Winters <chris@cwinters.com>
206
207
208
209perl v5.8.8                       2007-04-25       Workflow::Persister::DBI(3)
Impressum