KickJava   Java API By Example, From Geeks To Geeks.

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


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.database.general.*;
8 import com.daffodilwoods.database.resource.*;
9
10 /**
11  * Objective of this class to delete matching rows from the child table
12  * if constraint is specified with delete rule action as cascade
13  * for any match option( Simple/Partial/Full ).
14  */

15
16 public class DeleteCascadeReferencedExecuter extends ReferencedExecuter {
17
18
19   /**
20    * constructs a new instance of check constraint exception with the given arguments.
21    * @param referencedConstraint Value of the Referenced Constraint Descriptor
22    * having the details of the referenced constraints
23    * @param globalSess _ServerSession
24    * @throws DException
25    */

26
27   public DeleteCascadeReferencedExecuter( _ReferentialConstraint referencedConstraint, _ServerSession globalSess ) throws DException {
28     globalSession = globalSess;
29     setVariables( referencedConstraint );
30   }
31
32   /**
33    * The following method fires all the constraints which are having delete rule
34    * with action set to cascade. A private method is further called to
35    * permanently delete the matching rows from the child table.
36    * @param sec
37    * @throws DException
38    */

39
40   public void checkReferencedConstraints( _StatementExecutionContext sec ) throws DException {
41     populateMatchingIterator();
42     for( int i=0; i< matchingRowsPool.size(); i++ )
43         delete_SimpleFull_CASCADE( i , sec );
44   }
45
46   /**
47    * The following method deletes all rows from the child table having values of
48    * conditional columns same as that of the referenced table.
49    * @param tableIndex
50    * @param statementExecutionContext
51    * @throws DException
52    */

53
54   private void delete_SimpleFull_CASCADE( int tableIndex , _StatementExecutionContext statementExecutionContext ) throws DException {
55       ConstraintStore constraintStore = (ConstraintStore)matchingRowsPool.get(tableIndex);
56       _Iterator iterator = constraintStore.getIterator();
57       booleanvalueexpression condition = constraintStore.getCondition();
58       setParameterValues(iterator,condition, statementExecutionContext.getRecordVersion().getPreviousRecord());
59
60       if( iterator.last()){
61           _ServerTable serverTable = statementExecutionContext.getServerTable((QualifiedIdentifier)sub_superTable.get(tableIndex)) ;
62           _StatementExecutionContext sss = getNewSEC(statementExecutionContext);
63           do {
64               serverTable.delete( iterator, sss );
65           } while ( iterator.previous() ) ;
66       }
67   }
68
69 }
70
Popular Tags