KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
6 import com.daffodilwoods.daffodildb.server.datasystem.utility.*;
7 import com.daffodilwoods.daffodildb.server.serversystem.*;
8 import com.daffodilwoods.daffodildb.server.sql99.common.*;
9 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
10 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
11 import com.daffodilwoods.daffodildb.utils.field.*;
12 import com.daffodilwoods.database.resource.*;
13 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator;
14 import com.daffodilwoods.database.utility.P;
15
16 /**
17  * Objective of this class is to check rows in child table when constraint
18  * is specified with match option - PARTIAL
19  * In match partail - All non-null values must match correspondingly.
20  * ALL NULL VALUES ARE NOT ALLOWED
21  */

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

35   public MatchPartialReferencingExecuter( _ReferentialConstraint referencingcnst,SuperComparator[] superComp ) throws DException{
36     super(superComp);
37     referencingConstraint = referencingcnst;
38     referencedColumns = referencingcnst.getReferencedColumns() ;
39     referencingColumns = referencingcnst.getReferencingColumns() ;
40     condition = referencingcnst.getMatchingRowsBVE(true);
41     tableDetails = new TableDetails();
42     tableDetails.setTableName(new String JavaDoc[]{referencingConstraint.getReferencedTable().catalog,referencingConstraint.getReferencedTable().schema,referencingConstraint.getReferencedTable().name});
43   }
44
45   /**
46    * This method is used to fire the constraint when insert/update is performed
47    * on the table having constraint with match option partail.
48    * If all the values in the child table are null, throw the exception.
49    * @param recordVersion
50    * @param globalSess
51    * @throws DException
52    */

53   public void checkReferencingConstraints( RecordVersion recordVersion , _ServerSession globalSess ) throws DException {
54     _Record record = recordVersion.getCurrentRecord();
55     if( iterator == null ) {
56        tableDetails.cc = globalSess.getColumnCharacteristics(tableDetails.getQualifiedIdentifier());
57        SetColumnProperties.setTableNamesAndDatatypesOfAllColumns(globalSess,condition.getColumnDetails(),new TableDetails[]{tableDetails},new ArrayList(),new ArrayList());
58       _SingleTableExecuter singleTE = new ConditionSingleTableExecuter( null , tableDetails , globalSess , condition , null );
59        iterator = globalSess.getIterator( referencingConstraint.getReferencedTable(), singleTE );
60     }
61     Object JavaDoc[] values = setParameterValues(record);
62     if( check( values))
63      return;
64     Object JavaDoc []array = (Object JavaDoc[])condition.getParameters(null);
65     iterator.setConditionVariableValue( getReferences(array) , values , 1 );
66     checkReferentialConstraints(condition, values);
67   }
68
69   public Object JavaDoc[] setParameterValues( _Record record) throws DException {
70     int len = 2*referencingColumns.length;
71     Object JavaDoc[] columnValues = new Object JavaDoc[len];
72     int i=0;
73     int j=0;
74        for( ; i<referencingColumns.length ; i++ ){
75            Object JavaDoc value = record.getObject( referencingColumns[i] );
76          columnValues[j++] = value ;
77          columnValues[j++] = value;
78        }
79     return columnValues;
80   }
81
82   private boolean check(Object JavaDoc[] temp) throws DException {
83        for( int i=0; i< temp.length; i++ )
84           if( !((FieldBase)temp[i]).getNull())
85              return false;
86        return true;
87   }
88
89 }
90
Popular Tags