KickJava   Java API By Example, From Geeks To Geeks.

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


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.datasystem.utility._Record;
8 import com.daffodilwoods.daffodildb.server.serversystem.*;
9 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
10 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
11 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
12 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
13 import com.daffodilwoods.daffodildb.utils.field.*;
14 import com.daffodilwoods.database.general.*;
15 import com.daffodilwoods.database.resource.*;
16
17 /**
18  * Objective of the class is to verify referenced constraints that have
19  * been applied on the table with update rule action as CASCADE
20  * and match option is specified as PARTIAL.
21  */

22 public class UpdatePartialCascadeReferencedExecuter extends ReferencedExecuter {
23
24   _ReferentialConstraint referencedCnstrnt;
25
26   /**
27    * Constructor : used to construct a new instance of foreign constraint with
28    * the given arguments.
29    * @param referencedConstraint Value of the Referenced Constraint Descriptor
30    * having the details of the referenced constraints
31    * @param globalSess
32    * @throws DException
33    */

34   public UpdatePartialCascadeReferencedExecuter( _ReferentialConstraint referencedConstraint, _ServerSession globalSess ) throws DException {
35     globalSession = globalSess;
36     setVariables( referencedConstraint );
37     referencedCnstrnt = referencedConstraint;
38   }
39
40   /**
41    * The following method fires all the constraints having update rule
42    * action as cascade. A private method to update corresponding rows
43    * of child table.
44    */

45   public void checkReferencedConstraints( _StatementExecutionContext sec ) throws DException {
46     populateMatchingIterator();
47     for( int i=0; i< matchingRowsPool.size(); i++ )
48         update_Partial_CASCADE( i , sec );
49   }
50
51   /**
52    * The following method updates all rows from the iterator on child table having bve
53    * conditional columns as the referencing columns of the child table and corresponding
54    * values from the parent table.
55    * This method throws exception if any updation causes all column values of a particular
56    * rows of child table to NULL.
57    */

58   private void update_Partial_CASCADE ( int tableIndex , _StatementExecutionContext statementExecutionContext ) throws DException {
59       ConstraintStore constraintStore = (ConstraintStore)matchingRowsPool.get(tableIndex);
60       _Iterator iterator = constraintStore.getIterator();
61       booleanvalueexpression bve = constraintStore.getCondition();
62       RecordVersion recordVersion = statementExecutionContext.getRecordVersion();
63       setParameterValues( iterator , bve , recordVersion.getPreviousRecord() );
64       if(iterator.last()){
65           _ServerTable serverTable = statementExecutionContext.getServerTable( (QualifiedIdentifier) sub_superTable.get(tableIndex));
66           do {
67               int[] column = getNonNullIndexesReferencing( referencingColumns , iterator.getRecord() );
68               int[] columnsToBeUpdated = new int[column.length];
69               Object JavaDoc[] value = new Object JavaDoc[column.length];
70               for( int i=0; i<column.length; i++ ){
71                   columnsToBeUpdated[i] = referencingColumns[ column[i] ];
72                   value[i] = ((FieldBase) recordVersion.getCurrentRecord().getObject( referencedColumns[column[i]])).getObject();
73               }
74               serverTable.update( iterator , columnsToBeUpdated , value , statementExecutionContext );
75           } while ( iterator.previous() ) ;
76       }
77   }
78
79
80   /** @todo
81    * Check the function below For correct implementation
82    * */

83
84
85   private void compareRecordsForPartial_CASCADE( _Iterator oldIterator , _Iterator newIterator ) throws DException {
86   }
87
88
89   private int[] getNonNullIndexesReferencing( int[] columns , _Record record ) throws DException {
90       Vector indexes = new Vector(columns.length);
91       for( int i=0 ; i<columns.length ; i++ )
92           if(( record.getObject( columns[i] ) != null ))
93               indexes.add( new Integer JavaDoc(i) );
94       return getIntArray( indexes.toArray() ) ;
95   }
96
97
98   private int checkRecordIdInNewIterator( _Iterator tableIterator , booleanvalueexpression recordCondition ) throws DException {
99       if( tableIterator.first() ){
100       }
101       return -1;
102   }
103
104   private int[] getIntArray(Object JavaDoc[] values ) throws DException {
105     if( values == null )
106         return null;
107     int[] valuesToReturn = new int[values.length];
108     for( int i=0; i<values.length ; i++ )
109         valuesToReturn[i] = ((Integer JavaDoc)values[i]).intValue();
110     return valuesToReturn;
111   }
112
113   private int[] getNonNullUnequalColumnsForPartialCascade( int[] columns , RecordVersion recordVersion ) throws DException {
114     Vector indexes = new Vector( columns.length );
115     for( int i=0 ; i<columns.length ; i++ )
116       if( ( !((FieldBase)recordVersion.getCurrentRecord().getObject(columns[i])).getNull() ) && ( ! recordVersion.getPreviousRecord().getObject(columns[i]).equals(recordVersion.getCurrentRecord().getObject(columns[i]))) )
117         indexes.add( new Integer JavaDoc(columns[i]) );
118     return getIntArray( indexes.toArray() );
119   }
120
121
122 }
123
Popular Tags