KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datadictionarysystem > information > ConstraintInformation


1 package com.daffodilwoods.daffodildb.server.datadictionarysystem.information;
2
3 /**
4  * Title:
5  * Description:
6  * Copyright: Copyright (c) 2002
7  * Company:
8  * @author
9  * @version 1.0
10  */

11  import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
12  import com.daffodilwoods.database.resource.*;
13  import java.util.ArrayList JavaDoc;
14  import com.daffodilwoods.daffodildb.server.sql99.common.SqlKeywords;
15  import java.io.*;
16 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference;
17 public class ConstraintInformation implements _ConstraintInformation {
18
19     _ConstraintInfo[] constraintInfo;
20
21     public ConstraintInformation(_ConstraintInfo[] constraintInfo) {
22        this.constraintInfo = constraintInfo;
23     }
24
25     public ConstraintInformation() {
26     }
27
28     public _ConstraintInfo getConstraintInfo(int index) {
29       return constraintInfo[index];
30     }
31
32     ArrayList JavaDoc getAllConstraints(){
33         ArrayList JavaDoc constraintsList = new ArrayList JavaDoc();
34         for(int i =0 ;i<constraintInfo.length;i++)
35            constraintsList.add(constraintInfo[i].getName());
36         return constraintsList;
37     }
38
39      public _ConstraintInfo[] getAllCheckConstraints() {
40         ArrayList JavaDoc constraintsList = new ArrayList JavaDoc();
41         for(int i =0 ,size = constraintInfo.length;i<size;i++)
42            if(constraintInfo[i].getType().equalsIgnoreCase(SqlKeywords.CHECK))
43               constraintsList.add(constraintInfo[i]);
44         return constraintsList.size() == 0 ? null : (_ConstraintInfo[])constraintsList.toArray(new _ConstraintInfo[0]);
45      }
46
47      public _ConstraintInfo[] getAllPrimaryConstraints() {
48         ArrayList JavaDoc constraintsList = new ArrayList JavaDoc();
49         String JavaDoc requiredType = SqlKeywords.PRIMARY +" "+SqlKeywords.KEY;
50         for(int i =0 ,size = constraintInfo.length;i<size;i++)
51            if(constraintInfo[i].getType().equalsIgnoreCase(requiredType))
52               constraintsList.add(constraintInfo[i]);
53         return constraintsList.size() == 0 ? null : (_ConstraintInfo[])constraintsList.toArray(new _ConstraintInfo[0]);
54      }
55
56      public _ConstraintInfo[] getAllUniqueConstraints() {
57         ArrayList JavaDoc constraintsList = new ArrayList JavaDoc();
58         for(int i =0 ,size = constraintInfo.length;i<size;i++)
59            if(constraintInfo[i].getType().equalsIgnoreCase(SqlKeywords.UNIQUE))
60               constraintsList.add(constraintInfo[i]);
61         return constraintsList.size() == 0 ? null : (_ConstraintInfo[])constraintsList.toArray(new _ConstraintInfo[0]);
62      }
63
64      public _ConstraintInfo[] getAllForeignConstraints() {
65         ArrayList JavaDoc constraintsList = new ArrayList JavaDoc();
66         for(int i =0 ,size = constraintInfo.length;i<size;i++)
67            if(constraintInfo[i].getType().equalsIgnoreCase("Foreign/Referencing"))
68               constraintsList.add(constraintInfo[i]);
69         return constraintsList.size() == 0 ? null : (_ConstraintInfo[])constraintsList.toArray(new _ConstraintInfo[0]);
70      }
71
72      public void readExternal(ObjectInput objectInput) throws IOException, ClassNotFoundException JavaDoc{
73             constraintInfo = (_ConstraintInfo[])objectInput.readObject();
74     }
75
76     public void writeExternal(ObjectOutput objectOutput) throws IOException {
77             objectOutput.writeObject(constraintInfo);
78     }
79
80
81
82 }
83
Popular Tags