KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem;
2
3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
4 import com.daffodilwoods.daffodildb.server.serversystem.*;
5 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
6 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
7 import com.daffodilwoods.daffodildb.utils.field.*;
8 import com.daffodilwoods.database.general.*;
9 import com.daffodilwoods.database.resource.*;
10
11 /**
12  * Objective of the class is to verify referenced constraints that have
13  * been applied on the table with update rule action as CASCADE
14  * and match option is specified as FULL or SIMPLE.
15  */

16 public class UpdateSFCascadeReferencedExecuter extends ReferencedExecuter {
17
18   /**
19    * Constructor : used to construct a new instance of foreign constraint with
20    * the given arguments.
21    * @param referencedConstraint Value of the Referenced Constraint Descriptor
22    * having the details of the referenced constraints
23    * @param globalSess instance of _ServerSession
24    * @throws DException
25    */

26   public UpdateSFCascadeReferencedExecuter( _ReferentialConstraint referencedConstraint, _ServerSession globalSess ) throws DException {
27     globalSession = globalSess;
28     setVariables( referencedConstraint );
29   }
30
31   /**
32    * The following method fires all the constraints having update rule with
33    * action as cascade. A private method is called to update corresponding rows
34    * of referencing table.
35    */

36   public void checkReferencedConstraints( _StatementExecutionContext sec ) throws DException {
37     populateMatchingIterator();
38     for( int i=0; i< matchingRowsPool.size(); i++ )
39         update_SimpleFull_CASCADE( i , sec );
40   }
41
42   /**
43    * The following method updates all rows got from the iterator on child table having
44    * conditional columns as the referencing columns of the child table and corresponding
45    * values from the parent table.
46    * This method throws exception if any updation causes all the rows of child
47    * table to NON-Matching NON-NULL values in case of simple/full match.
48    */

49   private void update_SimpleFull_CASCADE( int tableIndex , _StatementExecutionContext statementExecutionContext ) throws DException {
50       ConstraintStore constraintStore = (ConstraintStore)matchingRowsPool.get(tableIndex);
51       _Iterator iterator = constraintStore.getIterator();
52       booleanvalueexpression bve = constraintStore.getCondition();
53       setParameterValues( iterator , bve , statementExecutionContext.getRecordVersion().getPreviousRecord() );
54       if(iterator.last()) {
55           _ServerTable serverTable = statementExecutionContext.getServerTable( (QualifiedIdentifier)sub_superTable.get(tableIndex) );
56           _StatementExecutionContext sss = getNewSEC( statementExecutionContext );
57           do {
58               int[] column = new int[referencingColumns.length];
59               Object JavaDoc[] value = new Object JavaDoc[referencingColumns.length];
60               for( int i=0; i<referencingColumns.length ; i++ ){
61                   column[i] = referencingColumns[i];
62                   value[i] = ( (FieldBase) statementExecutionContext.getRecordVersion().getCurrentRecord().getObject(referencedColumns[i])).getObject();
63               }
64               serverTable.update( iterator , column, value , sss );
65           } while( iterator.previous() ) ;
66       }
67   }
68 }
69
Popular Tags