Quadcap Embeddable Database

com/quadcap/sql/PrimaryKeyConstraint.java

Go to the documentation of this file.
00001 package com.quadcap.sql; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 import java.io.ByteArrayOutputStream; 00042 import java.io.Externalizable; 00043 import java.io.IOException; 00044 import java.io.ObjectInput; 00045 import java.io.ObjectOutput; 00046 00047 import java.util.Vector; 00048 00049 import java.sql.ResultSet; 00050 import java.sql.ResultSetMetaData; 00051 import java.sql.SQLException; 00052 00053 import com.quadcap.sql.types.Value; 00054 00055 import com.quadcap.sql.io.ObjectInputStream; 00056 import com.quadcap.sql.io.ObjectOutputStream; 00057 00058 import com.quadcap.sql.index.Btree; 00059 00060 import com.quadcap.sql.file.BlockFile; 00061 00062 import com.quadcap.util.Debug; 00063 import com.quadcap.util.Util; 00064 00065 /** 00066 * Index constraint for <b>PRIMARY KEY</b>s. 00067 * 00068 * @author Stan Bailes 00069 */ 00070 public class PrimaryKeyConstraint extends UniqueConstraint 00071 implements Externalizable { 00072 /** 00073 * Default constructor 00074 */ 00075 public PrimaryKeyConstraint() {} 00076 00077 /** 00078 * Explicit constructor for single column constraint, taking column name. 00079 */ 00080 public PrimaryKeyConstraint(String name) { 00081 super(name); 00082 } 00083 00084 /** 00085 * Explicit constructor for multiple column constraint with specified 00086 * constraint name and column names 00087 */ 00088 public PrimaryKeyConstraint(String name, Vector names) { 00089 super(name, names); 00090 } 00091 00092 /** 00093 * Read me from a stream 00094 * 00095 * @exception IOException may be thrown 00096 */ 00097 public void readExternal(ObjectInput in) 00098 throws IOException, ClassNotFoundException 00099 { 00100 super.readExternal(in); 00101 } 00102 00103 /** 00104 * Write me to a stream 00105 * 00106 * @exception IOException may be thrown 00107 */ 00108 public void writeExternal(ObjectOutput out) throws IOException { 00109 super.writeExternal(out); 00110 } 00111 00112 /** 00113 * Return the number of columns in the index 00114 */ 00115 public int getIndexColumnCount() { 00116 return getColumnCount(); 00117 } 00118 00119 /** 00120 * IndexConstraint.makeKey() I use the column(s) I was given 00121 */ 00122 public byte[] makeKey(Session session, Row row, long rowId) 00123 throws SQLException 00124 { 00125 return Key.makeKey(table, row, getColumns(), 0, false); 00126 } 00127 00128 /** 00129 * Yes, I *am* the primary key constraint. 00130 */ 00131 public String constraintType() { return "primary key"; } 00132 00133 /** 00134 * Let me tell you what you've going to do... 00135 */ 00136 public void setTable(Table t) throws SQLException { 00137 super.setTable(t); 00138 int[] cols = getColumns(); 00139 final int notnull = ResultSetMetaData.columnNoNulls; 00140 for (int i = 0; i < cols.length; i++) { 00141 t.getColumn(cols[i]).setNullable(notnull); 00142 } 00143 } 00144 }