KickJava   Java API By Example, From Geeks To Geeks.

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


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.serversystem.*;
7 import com.daffodilwoods.database.resource.*;
8
9
10 /**
11  * This class provides the basic functionality to check referenced constraints
12  * according to the Match option and the action specified. On the basis of the
13  * match option [Full, Partial , Simple] and Delete/Update rule option
14  * [ restrict, cascade , set null, set default, No Action], instances of
15  * appropriate executers are created which are further used for actually
16  * firing the referenced constraints.
17  * One abstract function of this class checkReferencedConstraints
18  * is overriden to implement the requred feature for Delete/Update
19  * rule and the match option accordingly in each and every class that extends
20  * this class.
21  */

22
23
24 public class ReferencedConstraints
25 {
26     BitSet bitSet = null;
27     BitSet universalBitSet = null;
28     int bitsetlength = 0;
29     ReferencedExecuter referencedExecuter;
30     boolean noAction;
31
32
33     /**
34      * Constructor: The instance of this class is created to check the
35      * referenced constraints. On the basis the specified match option and
36      * Delete/Update rule appropriate ince tance of executer is created.
37      * If the delete/update rule having the option as NO_ACTION, a flag is
38      * set to identify no effect on child table.
39      * @param referencedConstraints Value of the Referenced Constraint
40      * Descriptor having the details of the referenced constraints
41      * @param dd instance of _datadictionary
42      * @param gSession instance of _ServerSession
43      * @param deleteUpdate A flag to identify delete or update rule.
44      * @throws DException
45      */

46
47     public ReferencedConstraints( _ReferentialConstraint referencedConstraints , _DataDictionary dd , _ServerSession gSession , boolean deleteUpdate ) throws DException {
48       int type ;
49       int match = referencedConstraints.getMatch_Option();
50       if( deleteUpdate ){
51         type = referencedConstraints.getDelete_Rule() ;
52         if( type == TypeConstant.NO_ACTION )
53             noAction = true ;
54         if( type == TypeConstant.CASCADE )
55           referencedExecuter = new DeleteCascadeReferencedExecuter( referencedConstraints , gSession );
56         else if( type == TypeConstant.SETNULL )
57           referencedExecuter = new SetNullReferencedExecuter( referencedConstraints , gSession );
58         else if ( type == TypeConstant.SETDEFAULT )
59           referencedExecuter = new SetDefaultReferencedExecuter( referencedConstraints , gSession , dd );
60         else if ( type == TypeConstant.RESTRICT )
61           referencedExecuter = new RestrictReferencedExecuter( referencedConstraints , gSession );
62       }
63       else {
64         type = referencedConstraints.getUpdate_Rule();
65         if( type == TypeConstant.NO_ACTION )
66             noAction = true ;
67         if( (match == TypeConstant.Match_Simple || match == TypeConstant.Match_Full) && type == TypeConstant.CASCADE )
68           referencedExecuter = new UpdateSFCascadeReferencedExecuter( referencedConstraints , gSession );
69          else if( type == TypeConstant.SETNULL )
70            referencedExecuter = new SetNullReferencedExecuter( referencedConstraints , gSession );
71         else if( type == TypeConstant.SETDEFAULT )
72           referencedExecuter = new SetDefaultReferencedExecuter( referencedConstraints , gSession , dd );
73         else if (type == TypeConstant.RESTRICT )
74           referencedExecuter = new RestrictReferencedExecuter( referencedConstraints , gSession );
75         else if( match == TypeConstant.Match_Partial && type == TypeConstant.CASCADE )
76           referencedExecuter = new UpdatePartialCascadeReferencedExecuter( referencedConstraints , gSession );
77       }
78     }
79
80     /**
81      * This method fires the checkReferencedConstraints of the approrpriate executer.
82      * @param sec Value of statement execution context having current user session
83      * @throws DException
84      */

85
86     public void checkReferencedConstraints( _StatementExecutionContext sec ) throws DException {
87       if( noAction )
88         return;
89       referencedExecuter.checkReferencedConstraints( sec );
90     }
91
92     /**
93      * This method sets the referenced column indexes.
94      * @param bs value of referenced column indexes.
95      */

96
97     public void setBitSet( BitSet bs ) {
98         bitsetlength = bs.length();
99         bitSet = bs;
100         universalBitSet = new BitSet(bs.length());
101     }
102
103     /**
104      * This method checks the column indexes with that of the passed column indexes.
105      * @param col value of the column indexes to be compared.
106      * @return true if the column indexes are same otherwise false
107      */

108
109     public boolean fireDescriptor( int[] col ) {
110         BitSet gotBitSet = new BitSet(bitsetlength);
111         for( int i=0; i<col.length; i++ )
112             gotBitSet.set(col[i]);
113         gotBitSet.and(bitSet);
114         return !(gotBitSet.equals(universalBitSet));
115     }
116
117
118
119 /* private int[] getColumnsToBeUpdatedInReferencingTable( ) throws DException {
120         Vector returnColumns = new Vector();
121         for( int i=0 ; i<referencingColumns.length; i++ )
122             for( int k=0; k<updatedColumns.length; k++ )
123                 if( updatedColumns[k] == referencingColumns[i] )
124                     returnColumns.add( new Integer( updatedColumns[k]) );
125         return getIntArray( returnColumns.toArray() );
126     }*/

127 }
128
Popular Tags