KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

32   public SetDefaultReferencedExecuter( _ReferentialConstraint referencedConstraint, _ServerSession globalSess , _DataDictionary dd ) throws DException {
33     globalSession = globalSess;
34     setVariables( referencedConstraint );
35     dataDictionary = dd;
36   }
37
38   /**
39    * The following method fires all the constraints which having delete/update rule
40    * SET DEFAULT. This calls the private method to check if the cheild table having matching
41    * values.
42    */

43   public void checkReferencedConstraints( _StatementExecutionContext sec ) throws DException {
44     populateMatchingIterator();
45     for( int i=0; i< matchingRowsPool.size(); i++ )
46         matching_SETDEFAULT( i , sec );
47   }
48
49   /**
50    * The following method checks all rows from the iterator on child table having bve
51    * conditional columns as the referencing columns values from the child table and values
52    * from the default value expression.
53    */

54   private void matching_SETDEFAULT( int tableIndex , _StatementExecutionContext statementExecutionContext ) throws DException {
55       ConstraintStore constraintStore = (ConstraintStore)matchingRowsPool.get(tableIndex);
56       RecordVersion recordVersion = statementExecutionContext.getRecordVersion();
57       _Iterator iterator = constraintStore.getIterator();
58       booleanvalueexpression bve = constraintStore.getCondition();
59       setParameterValues( iterator , bve , recordVersion.getPreviousRecord());
60       defaultoption defaultExpression = null ;
61       Object JavaDoc[] value = new Object JavaDoc[referencingColumns.length];
62       if( iterator.last() ){
63           _ServerTable serverTable = statementExecutionContext.getServerTable( (QualifiedIdentifier)sub_superTable.get(tableIndex) );
64           do {
65               for(int j=0 ; j< referencingColumns.length ; j++){
66                   defaultExpression = dataDictionary.getDefaultValueGetter( (QualifiedIdentifier)sub_superTable.get(tableIndex) ).getDefaultValueExpression(referencingColumns[j]);
67                   try {
68                       value[j] = ((FieldBase) defaultExpression.run(globalSession )).getObject();
69                       } catch( Exception JavaDoc e ) {}
70               }
71               serverTable.update( iterator , referencingColumns , value , statementExecutionContext );
72           } while ( iterator.previous() ) ;
73       }
74   }
75 }
76
Popular Tags