KickJava   Java API By Example, From Geeks To Geeks.

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


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.serversystem.*;
8 import com.daffodilwoods.database.resource.*;
9 import com.daffodilwoods.daffodildb.server.serversystem._ServerSession;
10 import com.daffodilwoods.daffodildb.utils.ColumnCharacteristicsUtilities;
11 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator;
12 import com.daffodilwoods.daffodildb.utils.GetByteComparator;
13
14 /**
15  *
16  * <p>Title: ReferencingConstraints </p>
17  * <p>Description: This class provides the basic functionality needed for firing
18  * referencing constraints according to the Match Option [ Simple , Partial
19  * and Full ] specified</p>
20  * <p>Copyright: Copyright (c) 2003</p>
21  * <p>Company: </p>
22  * @author unascribed
23  * @version 1.0
24  */

25 public class ReferencingConstraints{
26
27    BitSet bitSet = null;
28    BitSet universalBitSet = null;
29    int bitsetlength = 0;
30    ReferencingExecuter referencingExecuter = null;
31
32    /**
33     * Constructor : creates a instance of ReferencingConstraints with specified arguments
34     * @param referencingcnst
35     * @throws DException
36     */

37    public ReferencingConstraints( _ReferentialConstraint referencingcnst, _ServerSession globalSession ) throws DException {
38      int[] referencingColumn = referencingcnst.getReferencingColumns();
39     int[] referencedColumn = referencingcnst.getReferencedColumns();
40     _ColumnCharacteristics ccReferenced = globalSession.getColumnCharacteristics(referencingcnst.getReferencedTable());
41     _ColumnCharacteristics ccReferencing =globalSession.getColumnCharacteristics(referencingcnst.getReferencingTable());
42     int[] colType1 = ColumnCharacteristicsUtilities.getColumnsType(referencingColumn,ccReferencing);
43     int[] colType2 = ColumnCharacteristicsUtilities.getColumnsType(referencedColumn , ccReferenced);
44       SuperComparator[] superComp = new SuperComparator[colType1.length];
45       for(int i = 0 ; i < colType1.length ; i++ ){
46         superComp[i] = GetByteComparator.getAppropriateComparator(colType1[i],colType2[i],globalSession, ccReferenced.getCollator());
47
48       }
49          int match = referencingcnst.getMatch_Option() ;
50      if( match == TypeConstant.Match_Simple )
51          referencingExecuter = new MatchSimpleReferencingExecuter(referencingcnst,superComp);
52      else if ( match == TypeConstant.Match_Full )
53          referencingExecuter = new MatchFullReferencingExecuter(referencingcnst,superComp);
54      else if ( match == TypeConstant.Match_Partial )
55          referencingExecuter = new MatchPartialReferencingExecuter(referencingcnst,superComp);
56    }
57
58    /**
59     * This method calls appropriate executer method based on specified match option.
60     * @param recordVersion
61     * @param globalSess
62     * @throws DException
63     */

64    public void checkReferencingConstraints( RecordVersion recordVersion , _ServerSession globalSess ) throws DException {
65      referencingExecuter.checkReferencingConstraints( recordVersion , globalSess );
66    }
67
68    public void setBitSet( BitSet bs ) {
69         bitSet = bs;
70        bitsetlength = bs.length();
71        universalBitSet = new BitSet(bs.length());
72      }
73
74      public boolean fireDescriptor( int[] col ) {
75        BitSet gotBitSet = new BitSet(bitsetlength);
76        for( int i=0; i<col.length; i++ )
77          gotBitSet.set(col[i]);
78          gotBitSet.and(bitSet);
79        return !(gotBitSet.equals(universalBitSet));
80      }
81 }
82
Popular Tags