KickJava   Java API By Example, From Geeks To Geeks.

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


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.sessioncondition.*;
7 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
8 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
9 import com.daffodilwoods.database.general.*;
10 import com.daffodilwoods.database.resource.*;
11
12 /**
13  * Objective of the class is to set the referenced column values to NULL in the child
14  * table when parent table is specified with foreign constraint if the delete
15  * rule or update rule is specified with option SET NULL for any match option.
16  */

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

29   public SetNullReferencedExecuter( _ReferentialConstraint referencedConstraint, _ServerSession globalSess ) throws DException {
30     globalSession = globalSess;
31     setVariables( referencedConstraint );
32   }
33
34   /**
35    * The following method fires all the constraints which having delete/update rule
36    * with action set to SET NULL. A private method is further called to
37    * set the matching column values as null in referencing table.
38    * values.
39    */

40   public void checkReferencedConstraints( _StatementExecutionContext sec ) throws DException {
41     populateMatchingIterator();
42     for( int i=0; i< matchingRowsPool.size(); i++ )
43         matching_SETNULL( i , sec );
44   }
45
46   /**
47    * The following method updates matched rows got from the iterator on child table with
48    * conditional columns as the referencing columns values from the child table
49    * and values equal to NULL.
50    */

51   private void matching_SETNULL( int tableIndex, _StatementExecutionContext statementExecutionContext ) throws DException {
52       ConstraintStore constraintStore = (ConstraintStore)matchingRowsPool.get(tableIndex);
53       RecordVersion recordVersion = statementExecutionContext.getRecordVersion();
54       _Iterator iterator = constraintStore.getIterator();
55       booleanvalueexpression bve = constraintStore.getCondition();
56       setParameterValues( iterator , bve , recordVersion.getPreviousRecord() );
57       if(iterator.last()){
58           _ServerTable serverTable = statementExecutionContext.getServerTable( (QualifiedIdentifier)sub_superTable.get(tableIndex) );
59           do {
60               int[] column = new int[ referencingColumns.length ];
61               Object JavaDoc[] values = new Object JavaDoc[ referencingColumns.length ];
62               for( int i=0; i<referencingColumns.length; i++ ) {
63                   column[i] = referencingColumns[i];
64                   values[i] = null ;
65               }
66
67               serverTable.update( iterator , column , values , statementExecutionContext );
68           }while( iterator.previous() ) ;
69       }
70   }
71
72 }
73
Popular Tags