001: package com.quadcap.sql;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.ByteArrayOutputStream;
042: import java.io.Externalizable;
043: import java.io.IOException;
044: import java.io.ObjectInput;
045: import java.io.ObjectOutput;
046:
047: import java.util.Vector;
048:
049: import java.sql.ResultSet;
050: import java.sql.ResultSetMetaData;
051: import java.sql.SQLException;
052:
053: import com.quadcap.sql.types.Value;
054:
055: import com.quadcap.sql.io.ObjectInputStream;
056: import com.quadcap.sql.io.ObjectOutputStream;
057:
058: import com.quadcap.sql.index.Btree;
059:
060: import com.quadcap.sql.file.BlockFile;
061:
062: import com.quadcap.util.Debug;
063: import com.quadcap.util.Util;
064:
065: /**
066: * Index constraint for <b>PRIMARY KEY</b>s.
067: *
068: * @author Stan Bailes
069: */
070: public class PrimaryKeyConstraint extends UniqueConstraint implements
071: Externalizable {
072: /**
073: * Default constructor
074: */
075: public PrimaryKeyConstraint() {
076: }
077:
078: /**
079: * Explicit constructor for single column constraint, taking column name.
080: */
081: public PrimaryKeyConstraint(String name) {
082: super (name);
083: }
084:
085: /**
086: * Explicit constructor for multiple column constraint with specified
087: * constraint name and column names
088: */
089: public PrimaryKeyConstraint(String name, Vector names) {
090: super (name, names);
091: }
092:
093: /**
094: * Read me from a stream
095: *
096: * @exception IOException may be thrown
097: */
098: public void readExternal(ObjectInput in) throws IOException,
099: ClassNotFoundException {
100: super .readExternal(in);
101: }
102:
103: /**
104: * Write me to a stream
105: *
106: * @exception IOException may be thrown
107: */
108: public void writeExternal(ObjectOutput out) throws IOException {
109: super .writeExternal(out);
110: }
111:
112: /**
113: * Return the number of columns in the index
114: */
115: public int getIndexColumnCount() {
116: return getColumnCount();
117: }
118:
119: /**
120: * IndexConstraint.makeKey() I use the column(s) I was given
121: */
122: public byte[] makeKey(Session session, Row row, long rowId)
123: throws SQLException {
124: return Key.makeKey(table, row, getColumns(), 0, false);
125: }
126:
127: /**
128: * Yes, I *am* the primary key constraint.
129: */
130: public String constraintType() {
131: return "primary key";
132: }
133:
134: /**
135: * Let me tell you what you've going to do...
136: */
137: public void setTable(Table t) throws SQLException {
138: super .setTable(t);
139: int[] cols = getColumns();
140: final int notnull = ResultSetMetaData.columnNoNulls;
141: for (int i = 0; i < cols.length; i++) {
142: t.getColumn(cols[i]).setNullable(notnull);
143: }
144: }
145: }
|