The generic serializable module. This is never included directly, rather
database-specific versions of it are included. MySQLSerializable for mysql,
PgSQLSerializable for postgresql, etc.
Returns sql_assoc_id of self if
it exists in the database or false if it does not. This is the closest
thing to a sql_assoc_id getter.
Insert the object and all associated objects. The new_transaction parameter
is used internally to make sure that a new transaction isn’t started
when insert is called
recursively. It should not be set when calling insert from application code.
dbi is a DBI object connected to a
database. AutoCommit should be disabled on this database handle.
Update the object and all associated objects. The new_transaction parameter
is used internally to make sure that a new transaction isn’t started
when update is called
recursively. It should not be set when calling update from application code.
Store an object and all associated objects.
Delete an object (and thereby all associated objects) if the reference
count is low enough, otherwise just decrease the reference count. The
new_transaction parameter is used internally to make sure that a new
transaction isn’t started when delete is called recursively. It
should not be set when calling delete from application code.
new_transaction has a second purpose: since it is never called by
application code it also determines whether trying to delete an object with
more than one reference to it should cause an exception. When called
internally (though recursive delete) it is ok to decrease the reference
count. When called by application code trying to delete an object with
references to it should raise an exception
This method is also aliased as
load
| Protected Instance methods |
Insert basic datatypes into entity table. This method will generate and
execute sql to insert basic datatypes. All Arrays, Hashes, and anything
that responds to sql_insert.
| TODO: | if primary key is nil then select max on it from the database, hoping that
it is a sequence or autoincrement value. This would require that the sql_create code in the database
specific modules reflect this autoincrementing behavior.
|
Generate and execute sql to insert arrays. This includes executing sql to
insert each member of the array. Objects are inserted into the database if
they don’t already exist, in which case their reference count will be
incremented in stead of adding a new copy (which would be impossible due to
primary key uniqueness constraints).
Generate and execute sql to insert hashes. This includes executing sql to
insert each key and value member of the hash. Both keys and values will
become objects in the database since anything can be a key or a value.
Objects are inserted into the database if they don’t already exist,
in which case their reference count will be incremented in stead of adding
a new copy (which would be impossible due to primary key uniqueness
constraints).
insert associated objects (that is, call insert on them and insert a
reference into the classname_assoc table). Associated objects are inserted
into the database if they don’t already exist, in which case their
reference count will be incremented in stead of adding a new copy (which
would be impossible due to primary key uniqueness constraints).
This method also takes care of built in classes that need special
attention, such as TrueClass and FalseClass. This is done using
basic_insert and an optional parameter specifying table name.
Delete from sql_ids since that should be enough to casade delete
everything. Consequences are deletion of the entity itself (don’t we
all just love ON DELETE CASADE).
Prerequisite: primary key or sql_assoc_id must be set.
Delete arrays and hashes and associated objects.
Generate and execute update sql for simple attributes
Simple select and load all variables from database. There are two modes of
operation in this method: Either selection is done on the primary key (if
it is set), or on sql_assoc_id
(if primary key isn’t set). @sql_primary_key must hold the
primary key symbol.
This will fail horribly if neither primary key not @sql_assoc_id is set.
Simple select and load all variables from database. Selection is done on
assoc_id. Returns the newly loaded object. Beware: where sql_select loads into self sql_select_from_id loads into a new
object.
Select and load all arrays, hashes and associated objects.
Fetch variable names in this class instance. Prepend sql_assoc_id to this list, since
that is also going to go in the db. If quote_name is true then escape the
names using sql_quote_name.
| TODO: | If the primary key is nil then do not include it and assume that it is a
sequence or an autoincrement value. This would require that the sql_create code in the database
specific modules reflect this autoincrementing behavior.
|
Fetch values of all variables in this class instance. Prepend sql_assoc_id to this list, since
that is also going to go in the db.
Fetch the next sql_assoc_id from
the database
The function depends on the exsistence of a sql_meta table with an id
column.
This method increments and fetches the next sql_assoc_id from the database if
this instance does not have an sql_assoc_id yet. Otherwise it just
returns the current sql_assoc_id. It is implemented in
the most database independent manner.
Database specific versions of this method should be implemented for
databases that support faster methods for achieving the same results -
sequences for instance.
Return the sql_assoc_id. If it
isn’t already defined try to load it from the database using the
primary key. If that fails then increment the global sql_assoc_id counter and return the
new sql_assoc_id.
Increase the reference count on the assoc_id. Objects with a reference
count above 0 will not be deleted.
Decrease the reference count on the assoc_id. Objects with a reference
count above 0 will not be deleted.
Return the number of references to assoc_id
methods for serializing "basic" datatypes which do not have their
own SQLSeriabliable mixin