KickJava   Java API By Example, From Geeks To Geeks.

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


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.daffodildb.utils.comparator.SuperComparator;
12
13 /**
14  * Objective of this class is to check rows in child table when constraint
15  * is specified with match option - FULL
16  * In match full - Child table can have either all null or all non-null must
17  * match correspondingly.
18  */

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

31   public MatchFullReferencingExecuter( _ReferentialConstraint referencingcnst, SuperComparator[] superComp ) throws DException{
32     super(superComp);
33     referencingConstraint = referencingcnst;
34     referencedColumns = referencingcnst.getReferencedColumns() ;
35     referencingColumns = referencingcnst.getReferencingColumns() ;
36     condition = referencingcnst.getMatchingRowsBVE(true);
37     tableDetails = new TableDetails();
38     tableDetails.setTableName(new String JavaDoc[]{referencingConstraint.getReferencedTable().catalog,referencingConstraint.getReferencedTable().schema,referencingConstraint.getReferencedTable().name});
39   }
40
41   /**
42    * This method fires the constraint when insert/update is performed
43    * on the table having constraint with match option Full.
44    * @param recordVersion
45    * @param globalSess
46    * @throws DException
47    */

48   public void checkReferencingConstraints( RecordVersion recordVersion , _ServerSession globalSess ) throws DException {
49     _Record record = recordVersion.getCurrentRecord();
50     if( iterator == null ) {
51       iterator = ((GlobalSession)globalSess).getIterator( referencingConstraint.getReferencedTable(), referencingConstraint.getReferencedColumns());
52     }
53
54     Object JavaDoc[] referencingColumnsValue = setParameterValues(record);
55     if( check( referencingColumnsValue))
56        return ;
57     checkReferentialConstraints(referencingColumnsValue );
58   }
59
60   public Object JavaDoc[] setParameterValues( _Record record) throws DException {
61     Object JavaDoc[] columnValues = new Object JavaDoc[referencingColumns.length];
62     boolean isNull = true;
63     for( int i=0; i< referencingColumns.length;i++ ){
64         Object JavaDoc val = record.getObject( referencingColumns[i]);
65         if( i == 0 )
66             isNull = val == null;
67         if((val == null) == isNull ){
68             if( val != null ){
69                 columnValues[i] = val ;
70             }
71         }
72         else
73         throw new DException("DSE382",new Object JavaDoc[] {referencingConstraint.getConstraintName(),referencingConstraint.getReferencedTable().getName(),record});
74     }
75     return columnValues;
76   }
77
78   private boolean check(Object JavaDoc[] temp) throws DException {
79        for( int i=0; i< temp.length; i++ )
80           if(!((FieldBase)temp[i]).getNull())
81              return false;
82        return true;
83   }
84 }
85
Popular Tags