However there is a little trick you can apply to update the ID of an object in the main table and all the related records. The technique consists in using the Data Dictionary stored in MAXATTRIBUTE table to find all the possible tables and fields where references to the renamed object could be stored.
Let's pretend we have to rename an object stored in the [TABLE] table and whose ID is stored in attribute [IDATTR]. The following SQL query will generate a set of update statements to update both the main record and all its potential references.
SELECT 'update ' || a.objectname ||
' set ' || a.attributename || '=''[NEWVALUE]''' ||
' where ' || a.attributename || '=''[OLDVALUE]'';'
FROM maxattribute a
JOIN maxobject o ON o.objectname=a.objectname
WHERE a.persistent=1 AND o.isview=0
AND ((a.sameasobject='[TABLE]' AND a.sameasattribute='[IDATTR]') OR
(a.objectname='[TABLE]' AND a.attributename='[IDATTR]'))
ORDER BY a.objectname, a.attributename;
Example
For example, if we need to rename a security group called 'MAINGRP1' to 'NEWGROUP' you will need to run the following query.
SELECT 'update ' || a.objectname ||
' set ' || a.attributename || '=''NEWGROUP''' ||
' where ' || a.attributename || '=''MAINGRP1'';'
FROM maxattribute a
JOIN maxobject o ON o.objectname=a.objectname
WHERE a.persistent=1 AND o.isview=0
AND ((a.sameasobject='MAXGROUP' AND a.sameasattribute='GROUPNAME') OR
(a.objectname='MAXGROUP' AND a.attributename='GROUPNAME'))
ORDER BY a.objectname, a.attributename;
The result of the select will be something similar to this.
update APPLICATIONAUTH set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update COLLECTIONAUTH set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update CTRLGROUP set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update GLAUTH set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update GROUPUSER set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update GRPREASSIGNAUTH set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update LABORAUTH set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update LIMITTOLERANCE set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update LOCAUTH set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update MAXGROUP set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update PMSCCATSEC set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update REPORTAPPAUTH set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update REPORTAUTH set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update SECURITYRESTRICT set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
update SITEAUTH set GROUPNAME='NEWGROUP' where GROUPNAME='MAINGRP1';
Now run this set of update statements in a single transaction against your database and you are done.
Important notes
- It is better to execute the update statements after having stopped the Maximo application server.
- Store the update statements in a text file you can revert your changes back if something goes wrong.
- This is not a supported procedure so you must be very careful when using it. Test it in a dev/test environment before using it in production.
- Backup your database first.
Source:http://maximodev.blogspot.com/2013/05/how-to-rename-objects.html
Tidak ada komentar:
Posting Komentar