Referential integrity X-Tension

Hi everybody!

I need to build some kind of Referential Integrity X-Tension.

I have a “Companies” schema and another schema called “Cities”. When i execute a “Company” insertion in Tamino, i have to check the “City” code for a valid value. If the “City” code doesn’t exist in the “Cities” schema, i can’t execute the insertion, i need to send an error message.

Any example for this kind of X-Tension?

Thanks in advance,

Malena

Hi Malena,

what you need is an onInsert trigger in your schema at the node containing the city(-code).

You also need a server extension with an onInsert trigger function like


        public void checkCode (String collection, String doctype, String ino_id, String XMLObject)
        {

                // get the content of the Code element
                int IDREFStartPos = XMLObject.indexOf (">") + 1;
                String IDREF = XMLObject.substring (IDREFStartPos, XMLObject.indexOf ('<', IDREFStartPos));
                
                // checks if a document of type City in collection CitiesCollection with attribute Code = IDREF exists
               StringBuffer Response = new StringBuffer();
               StringBuffer  XMLMessage = new StringBuffer();

               int ret =  SxsXMLXql ("CitiesCollection",  "City[@Code='" + IDREF + "']", Response);

               if (ret !=  0) {
                  SxsXMLGetMessage(XMLMessage);
                  SxsException (ret, XMLMessage.toString());
               } 
               else if (Response.length() == 0) {
                  SxsXMLGetMessage(XMLMessage);
                  SxsException (-1, ": " + XMLMessage.toString()+ ": no City document found.");
               } 
        }

This doesn’t look too difficult.

Best regards,
Julius Geppert