KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > serversystem > dmlvalidation > constraintsystem > MatchSimpleReferencingExecuter


1 package com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem;
2
3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
4 import com.daffodilwoods.daffodildb.server.datasystem.utility.*;
5 import com.daffodilwoods.daffodildb.server.serversystem.*;
6 import com.daffodilwoods.daffodildb.server.sessionsystem.*;
7 import com.daffodilwoods.daffodildb.server.sql99.common.*;
8 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
9 import com.daffodilwoods.daffodildb.utils.field.*;
10 import com.daffodilwoods.database.resource.*;
11 import com.daffodilwoods.database.utility.P;
12 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator;
13
14 /**
15  * Objective of this class is to check rows in child table when constraint
16  * is specified with match option - SIMPLE
17  * In match SIMPLE - If any of the values of referencing table is NULL, then row matchs
18  * with corresponding record in referenced table.
19  */

20
21 public class MatchSimpleReferencingExecuter extends ReferencingExecuter {
22
23   booleanvalueexpression condition;
24
25   /**
26    * Constructor - constructs an instance of foreign constraint exception
27    * with the given arguments.
28    * @param referencingcnst Value of the Referenced Constraint Descriptor
29    * having the details of the referenced constraints
30    * @throws DException
31    */

32   public MatchSimpleReferencingExecuter( _ReferentialConstraint referencingcnst,SuperComparator[] superComp ) throws DException{
33     super(superComp);
34     referencingConstraint = referencingcnst;
35     referencedColumns = referencingcnst.getReferencedColumns() ;
36     referencingColumns = referencingcnst.getReferencingColumns() ;
37     condition = referencingcnst.getMatchingRowsBVE(true);
38     tableDetails = new TableDetails();
39     tableDetails.setTableName(new String JavaDoc[]{referencingConstraint.getReferencedTable().catalog,referencingConstraint.getReferencedTable().schema,referencingConstraint.getReferencedTable().name});
40   }
41
42   /**
43    * This method fires the constraint with match option SIMPLE, when insert/update
44    * is performed on the table.This method returns if the child table has any of
45    * the referencing column values as NULL, else checks the record against parent table.
46    * throws an exception is mismatch is found.
47    * @param recordVersion instance of RecordVersion
48    * @param globalSess instance of _ServerSession
49    * @throws DException
50    */

51   public void checkReferencingConstraints( RecordVersion recordVersion , _ServerSession globalSess ) throws DException {
52     _Record record = recordVersion.getCurrentRecord();
53     if( iterator == null ) {
54        iterator = ((GlobalSession)globalSess).getIterator( referencingConstraint.getReferencedTable(), referencingConstraint.getReferencedColumns());
55     }
56     for (int i = 0; i < referencingColumns.length; i++) {
57        if(((FieldBase)record.getObject(referencingColumns[i])).getNull())
58            return;
59     }
60     checkReferentialConstraints(setParameterValues(record));
61   }
62
63   public Object JavaDoc[] setParameterValues( _Record record) throws DException {
64       Object JavaDoc[] columnValues = new Object JavaDoc[referencingColumns.length];
65       for( int i=0; i<referencingColumns.length ; i++ )
66           columnValues[ i ] = record.getObject( referencingColumns[i] );
67       return columnValues;
68   }
69 }
70
Popular Tags