KickJava   Java API By Example, From Geeks To Geeks.

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


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._Record;
7 import com.daffodilwoods.daffodildb.server.serversystem.*;
8 import com.daffodilwoods.daffodildb.server.sql99.common.*;
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.database.general.*;
14 import com.daffodilwoods.database.resource.*;
15
16
17 /**
18  * This abstract class provides the basic functionality needed for firing
19  * referenced constraints according to the Match types and the action
20  * specified. On the basis the match option and the Delete/Update rule - Option
21  * [ restrict, cascade , set null, set default, No Action], instances of
22  * appropriate executers are created which are further used for actually firing
23  * the referenced constraints.
24  * One abstract function of this class checkReferencedConstraints
25  * is overriden to implement the requred feature for Delete/Update
26  * rule and the match option accordingly in each and every class that extends
27  * this class.
28  */

29
30
31 public abstract class ReferencedExecuter {
32
33     ArrayList sub_superTable ;
34     ArrayList matchingRowsPool ;
35     booleanvalueexpression condition;
36     TableDetails tableDetails;
37     _ServerSession globalSession;
38     QualifiedIdentifier referencingTable , referencedTable ;
39     int type, match;
40     int[] referencedColumns , referencingColumns ;
41
42 /**
43  * This method creates an instance of _Iterator depending on the referencing table and
44  * refernced condition and creates an instance of ConstraintStore which is added to the
45  * map matchingRowsPool.
46  * @throws DException
47  */

48   public void populateMatchingIterator() throws DException {
49     if( matchingRowsPool.size() == 0 )
50       for( int i=0; i<sub_superTable.size(); i++ ){
51         _Iterator iterator = getIterator( condition ,(QualifiedIdentifier) sub_superTable.get(i) ) ;
52         ConstraintStore constraintStore = new ConstraintStore( iterator , referencingColumns , condition );
53         matchingRowsPool.add(i,constraintStore );
54       }
55   }
56
57   /**
58    * This method returns an instance of _Iterator depending on the condition and
59    * table name passed.
60    * @param bve instance of booleanvalueexpression
61    * @param tableName table name on which constraint to be fired is applied
62    * @return
63    * @throws DException
64    */

65   public _Iterator getIterator( booleanvalueexpression bve , QualifiedIdentifier tableName ) throws DException {
66       _SingleTableExecuter singleTE = new ConditionSingleTableExecuter( null , tableDetails , globalSession , bve , null );
67       return globalSession.getIterator( tableName , singleTE );
68   }
69
70   /**
71    * This record set the condition and the values from the passed record into the
72    * passed instance of _Iterator.
73    * @param iterator instance of _Iterator
74    * @param condition instance of booleanvalueexpression
75    * @param previousRecord instance of _Record
76    * @throws DException
77    */

78   public void setParameterValues( _Iterator iterator , booleanvalueexpression condition, _Record previousRecord ) throws DException {
79     Object JavaDoc[] columnValues = null ;
80       columnValues = new Object JavaDoc[referencingColumns.length];
81       for( int i=0; i<referencingColumns.length ; i++ ){
82           Object JavaDoc value = previousRecord.getObject( referencedColumns[i]);
83           columnValues[i] = value ;
84       }
85      iterator.setConditionVariableValue( getReferences ((Object JavaDoc[])condition.getParameters(null)), columnValues , 1);
86   }
87
88   /**
89    * This method returns an array of reference from passed object array.
90    * @param obj an object array
91    * @return an array of references
92    * @throws DException
93    */

94   public _Reference[] getReferences(Object JavaDoc[] obj) throws DException {
95       int len = obj.length;
96       _Reference[] ref = new _Reference[len] ;
97       for( int i=0; i<len; i++ )
98           ref[i] = (_Reference)obj[i] ;
99       return ref;
100   }
101
102   /**
103    * This method creates a new instance of _StatementExecutionContext and sets
104    * recordversion, serversession, serversystem and usersession from the passed
105    * instance of _StatementExecutionContext and retruns newly created
106    * instance of _StatementExecutionContext.
107    * @param statementExecutionContext instance of _StatementExecutionContext
108    * @return an instance of _StatementExecutionContext
109    * @throws DException
110    */

111   public _StatementExecutionContext getNewSEC( _StatementExecutionContext statementExecutionContext ) throws DException {
112       _StatementExecutionContext sss = new StatementExecutionContext();
113       sss.setConstraintTypeDeferred( statementExecutionContext.isConstraintCheckedForDefferable() );
114       sss.setRecordVersion( statementExecutionContext.getRecordVersion() );
115       sss.setServerSession( statementExecutionContext.getServerSession() );
116       sss.setServerSystem( statementExecutionContext.getServerSystem() );
117       sss.setUserSession( statementExecutionContext.getUserSession() );
118       return sss;
119   }
120
121   /**
122    * This method sets the information got from the passed instance of Referenced-
123    * ConstraintDescriptor which has the complete details of the constraint including
124    * name and column indexes of referenced and referencing columns, referencing and
125    * referenced table and referenced condition.
126    * @param referencedConstraints instance of _ReferentialConstraint
127    * @throws DException
128    */

129   public void setVariables(_ReferentialConstraint referencedConstraints ) throws DException {
130       referencedColumns = referencedConstraints.getReferencedColumns();
131       referencingColumns = referencedConstraints.getReferencingColumns();
132       match = referencedConstraints.getMatch_Option() ;
133       referencingTable = referencedConstraints.getReferencingTable();
134       referencedTable = referencedConstraints.getReferencedTable();
135       tableDetails = new TableDetails();
136       sub_superTable = referencedConstraints.getSub_SuperTables();
137       tableDetails.setTableName(new String JavaDoc[]{referencingTable.catalog,referencingTable.schema,referencingTable.name});
138       condition = referencedConstraints.getMatchingRowsBVE(false);
139       tableDetails.cc = globalSession.getColumnCharacteristics(tableDetails.getQualifiedIdentifier());
140       SetColumnProperties.setTableNamesAndDatatypesOfAllColumns(globalSession,condition.getColumnDetails(),new TableDetails[]{tableDetails},null,new ArrayList());
141       matchingRowsPool = new ArrayList();
142   }
143
144
145   /**
146    * This abstract method is implemented by class depending on the delete/update
147    * rule action and match option specified.
148    * * @param sec instance of _StatementExecutionContext
149    * @throws DException
150    */

151   public abstract void checkReferencedConstraints( _StatementExecutionContext sec ) throws DException ;
152
153 }
154
Popular Tags