my $self = shift;
my @misc_sets = @_;
# we use 'insert ignore' so that inserts can occur safely on the farm
# otherwise 2 processes could try to insert at the same time and one
# would fail
my $insert_ignore = $self->insert_ignore_clause();
my $sth = $self->prepare(
qq{${insert_ignore} INTO misc_set (
code,
name,
description,
max_length
) VALUES (?, ?, ?, ?)
});
my $db = $self->db();
SET:
foreach my $ms (@misc_sets) {
if(!ref($ms) || !$ms->isa('Bio::EnsEMBL::MiscSet')) {
throw("List of MiscSet arguments expected.");
}
if($ms->is_stored($db)) {
warning("MiscSet [".$ms->dbID."] is already stored in this database.");
next SET;
}
$sth->bind_param(1,$ms->code,SQL_VARCHAR);
$sth->bind_param(2,$ms->name,SQL_VARCHAR);
$sth->bind_param(3,$ms->description,SQL_LONGVARCHAR);
$sth->bind_param(4,$ms->longest_feature,SQL_INTEGER);
my $num_inserted = $sth->execute();
my $dbID;
if($num_inserted == 0) {
# insert failed because set with this code already exists
my $sth2 = $self->prepare("SELECT misc_set_id from misc_set " .
"WHERE code = ?");
$sth2->bind_param(1,$ms->code,SQL_VARCHAR);
$sth2->execute();
($dbID) = $sth2->fetchrow_array();
if($sth2->rows() != 1) {
throw("Could not retrieve or store MiscSet, code=[".$ms->code."]\n".
"Wrong database user/permissions?");
}
} else {
$dbID = $self->last_insert_id('misc_set_id', undef, 'misc_set');
}
$ms->dbID($dbID);
$ms->adaptor($self);
# update the internal caches
$self->{'_id_cache'}->{$dbID} = $ms;
$self->{'_code_cache'}->{lc($ms->code())} = $ms;
}
return;
}