summaryrefslogtreecommitdiffstats
path: root/config-db/ODLX/MetaDB
diff options
context:
space:
mode:
authorOliver Tappe2006-08-15 21:42:55 +0200
committerOliver Tappe2006-08-15 21:42:55 +0200
commita672837ea38476115e832580c73957f810a9f2b4 (patch)
tree0a0a43b321bd5de1462cd11b024f461010c4dcef /config-db/ODLX/MetaDB
parentUbuntu 5.10: working (diff)
downloadcore-a672837ea38476115e832580c73957f810a9f2b4.tar.gz
core-a672837ea38476115e832580c73957f810a9f2b4.tar.xz
core-a672837ea38476115e832580c73957f810a9f2b4.zip
* completed group-related interface and implementation
git-svn-id: http://svn.openslx.org/svn/openslx/trunk@298 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'config-db/ODLX/MetaDB')
-rw-r--r--config-db/ODLX/MetaDB/Base.pm60
-rw-r--r--config-db/ODLX/MetaDB/DBI.pm135
2 files changed, 186 insertions, 9 deletions
diff --git a/config-db/ODLX/MetaDB/Base.pm b/config-db/ODLX/MetaDB/Base.pm
index 72c5676a..aac97dfa 100644
--- a/config-db/ODLX/MetaDB/Base.pm
+++ b/config-db/ODLX/MetaDB/Base.pm
@@ -229,7 +229,11 @@ sub fetchSystemsById
{
}
-sub fetchAllSystemIDsForClient
+sub fetchAllSystemIDsOfClient
+{
+}
+
+sub fetchAllSystemIDsOfGroup
{
}
@@ -241,7 +245,27 @@ sub fetchClientsById
{
}
-sub fetchAllClientIDsForSystem
+sub fetchAllClientIDsOfSystem
+{
+}
+
+sub fetchAllClientIDsOfGroup
+{
+}
+
+sub fetchGroupsByFilter
+{
+}
+
+sub fetchGroupsById
+{
+}
+
+sub fetchAllGroupIDsOfClient
+{
+}
+
+sub fetchAllGroupIDsOfSystem
{
}
@@ -269,7 +293,11 @@ sub changeSystem
{
}
-sub setClientIDsForSystem
+sub setClientIDsOfSystem
+{
+}
+
+sub setGroupIDsOfSystem
{
}
@@ -285,7 +313,31 @@ sub changeClient
{
}
-sub setSystemIDsForClient
+sub setSystemIDsOfClient
+{
+}
+
+sub setGroupIDsOfClient
+{
+}
+
+sub addGroup
+{
+}
+
+sub removeGroup
+{
+}
+
+sub changeGroup
+{
+}
+
+sub setClientIDsOfGroup
+{
+}
+
+sub setSystemIDsOfGroup
{
}
diff --git a/config-db/ODLX/MetaDB/DBI.pm b/config-db/ODLX/MetaDB/DBI.pm
index 0b524e93..9a654744 100644
--- a/config-db/ODLX/MetaDB/DBI.pm
+++ b/config-db/ODLX/MetaDB/DBI.pm
@@ -102,7 +102,7 @@ sub fetchSystemsById
return $self->fetchSystemsByFilter({'id' => $id}, $resultCols);
}
-sub fetchAllSystemIDsForClient
+sub fetchAllSystemIDsOfClient
{
my $self = shift;
my $clientID = shift;
@@ -140,7 +140,7 @@ sub fetchClientsById
return $self->fetchClientsByFilter({'id' => $id}, $resultCols);
}
-sub fetchAllClientIDsForSystem
+sub fetchAllClientIDsOfSystem
{
my $self = shift;
my $clientID = shift;
@@ -166,6 +166,11 @@ sub _doInsert
my $valRow = (@$valRows)[0];
return if !defined $valRow;
+ if ($table =~ m[_ref$]) {
+ # reference tables do not have IDs:
+ $ignoreIDs = 1;
+ }
+
my $needToGenerateIDs = $self->generateNextIdForTable(undef);
if (!$ignoreIDs && $needToGenerateIDs) {
# DB requires pre-specified IDs, so we add the 'id' column:
@@ -203,14 +208,16 @@ sub _doDelete
my $self = shift;
my $table = shift;
my $IDs = shift;
+ my $idCol = shift;
my $dbh = $self->{'dbh'};
$IDs = [undef] unless defined $IDs;
+ $idCol = 'id' unless defined $idCol;
foreach my $id (@$IDs) {
my $sql = "DELETE FROM $table";
if (defined $id) {
- $sql .= " WHERE id = ".$self->quote($id);
+ $sql .= " WHERE $idCol = ".$self->quote($id);
}
my $sth = $dbh->prepare($sql)
or confess _tr(q[Can't delete from table <%s> (%s)], $table,
@@ -220,6 +227,7 @@ sub _doDelete
or confess _tr(q[Can't delete from table <%s> (%s)], $table,
$dbh->errstr);
}
+ return 1;
}
sub _doUpdate
@@ -256,6 +264,40 @@ sub _doUpdate
or confess _tr(q[Can't update table <%s> (%s)], $table,
$dbh->errstr);
}
+ return 1;
+}
+
+sub _updateRefTable
+{
+ my $self = shift;
+ my $table = shift;
+ my $keyID = shift;
+ my $newValueIDs = shift;
+ my $keyCol = shift;
+ my $valueCol = shift;
+ my $oldValueIDs = shift;
+
+ my %lastValueIDs;
+ @lastValueIDs{@$oldValueIDs} = ();
+
+ foreach my $valueID (@$newValueIDs) {
+ if (!exists $lastValueIDs{$valueID}) {
+ # value-ID is new, create it
+ my $valRow = {
+ $keyCol => $keyID,
+ $valueCol => $valueID,
+ };
+ $self->_doInsert($table, [$valRow]);
+ } else {
+ # value-ID already exists, leave as is, but remove from hash:
+ delete $lastValueIDs{$valueID};
+ }
+ }
+
+ # all the remaining value-IDs need to be removed:
+ if (scalar keys %lastValueIDs) {
+ $self->_doDelete($table, keys %lastValueIDs, $valueCol);
+ }
}
sub addSystem
@@ -283,8 +325,26 @@ sub changeSystem
return $self->_doUpdate('system', $systemIDs, $valRows);
}
-sub setClientIDsForSystem
+sub setClientIDsOfSystem
+{
+ my $self = shift;
+ my $systemID = shift;
+ my $clientIDs = shift;
+
+ my @currClients = $self->fetchAllClientIDsOfSystem($systemID);
+ $self->_updateRefTable('client_system_ref', $systemID, $clientIDs,
+ 'system_id', 'client_id', \@currClients);
+}
+
+sub setGroupIDsOfSystem
{
+ my $self = shift;
+ my $systemID = shift;
+ my $groupIDs = shift;
+
+ my @currGroups = $self->fetchAllGroupIDsOfSystem($systemID);
+ $self->_updateRefTable('grop_system_ref', $systemID, $groupIDs,
+ 'system_id', 'group_id', \@currGroups);
}
sub addClient
@@ -312,8 +372,73 @@ sub changeClient
return $self->_doUpdate('client', $clientIDs, $valRows);
}
-sub setSystemIDsForClient
+sub setSystemIDsOfClient
+{
+ my $self = shift;
+ my $clientID = shift;
+ my $systemIDs = shift;
+
+ my @currSystems = $self->fetchAllSystemsOfClient($clientID);
+ $self->_updateRefTable('client_system_ref', $clientID, $systemIDs,
+ 'client_id', 'system_id', \@currSystems);
+}
+
+sub setGroupIDsOfClient
+{
+ my $self = shift;
+ my $clientID = shift;
+ my $groupIDs = shift;
+
+ my @currGroups = $self->fetchAllGroupsOfClient($clientID);
+ $self->_updateRefTable('group_client_ref', $clientID, $groupIDs,
+ 'client_id', 'group_id', \@currGroups);
+}
+
+sub addGroup
+{
+ my $self = shift;
+ my $valRows = shift;
+
+ return $self->_doInsert('group', $valRows);
+}
+
+sub removeGroup
+{
+ my $self = shift;
+ my $groupIDs = shift;
+
+ return $self->_doDelete('group', $groupIDs);
+}
+
+sub changeGroup
{
+ my $self = shift;
+ my $groupIDs = shift;
+ my $valRows = shift;
+
+ return $self->_doUpdate('group', $groupIDs, $valRows);
+}
+
+sub setClientIDsOfGroup
+{
+ my $self = shift;
+ my $groupID = shift;
+ my $clientIDs = shift;
+
+ my @currClients = $self->fetchAllClientsOfGroup($groupID);
+ $self->_updateRefTable('group_client_ref', $groupID, $clientIDs,
+ 'group_id', 'client_id', \@currClients);
+}
+
+sub setSystemIDsOfGroup
+{
+ my $self = shift;
+ my $groupID = shift;
+ my $systemIDs = shift;
+
+ my @currSystems = $self->fetchAllSystemsOfGroup($groupID);
+ $self->_updateRefTable('group_system_ref', $groupID, $systemIDs,
+ 'group_id', 'system_id', \@currSystems);
}
################################################################################