Quadcap Embeddable Database

com/quadcap/sql/NotNullConstraint.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.Externalizable; 00042 import java.io.IOException; 00043 import java.io.ObjectInput; 00044 import java.io.ObjectOutput; 00045 00046 import java.util.Vector; 00047 00048 import java.sql.ResultSetMetaData; 00049 import java.sql.SQLException; 00050 00051 import com.quadcap.sql.types.Value; 00052 00053 import com.quadcap.util.Debug; 00054 00055 /** 00056 * Constraint implementation of <b>NOT NULL</b> 00057 * 00058 * @author Stan Bailes 00059 */ 00060 public class NotNullConstraint extends Constraint implements Externalizable { 00061 public NotNullConstraint() {} 00062 00063 public NotNullConstraint(String name) { 00064 super(name); 00065 } 00066 00067 public NotNullConstraint(String name, Vector names) { 00068 super(name, names); 00069 } 00070 00071 public void add(Session session) { 00072 } 00073 00074 public void checkInsert(Session session, Row row) 00075 throws SQLException, IOException 00076 { 00077 int[] cols = getColumns(); 00078 for (int i = 0; i < cols.length; i++) { 00079 int col = cols[i]; 00080 if (Value.isNull(row.item(col))) { 00081 throw new SQLException( 00082 "Not null constraint violated, column " + 00083 table.getColumn(col).getShortName() + " in table " + 00084 table.getName(), 00085 "23000"); 00086 } 00087 } 00088 } 00089 00090 public void applyInsert(Session session, Row row, long rowId, 00091 Constraint activeIndex) 00092 throws SQLException, IOException 00093 { 00094 } 00095 00096 public void checkUpdate(Session session, byte[] oldKey, Row row, 00097 Row oldRow, long rowId, Constraint activeIndex) 00098 throws SQLException, IOException 00099 { 00100 checkInsert(session, row); 00101 } 00102 00103 public void applyUpdate(Session session, byte[] oldKey, Row row, 00104 Row oldRow, long rowId, Constraint activeIndex) 00105 throws SQLException, IOException 00106 { 00107 } 00108 00109 public void checkDelete(Session session, Row row, long rowId) 00110 throws SQLException, IOException 00111 { 00112 } 00113 00114 public void applyDelete(Session session, Row row, long rowId, 00115 Constraint activeIndex) 00116 throws SQLException, IOException 00117 { 00118 } 00119 00120 public void delete(Session session) {} 00121 00122 public void readExternal(ObjectInput in) 00123 throws IOException, ClassNotFoundException 00124 { 00125 super.readExternal(in); 00126 } 00127 00128 public void writeExternal(ObjectOutput out) throws IOException { 00129 super.writeExternal(out); 00130 } 00131 00132 public void setTable(Table t) throws SQLException { 00133 super.setTable(t); 00134 int[] cols = getColumns(); 00135 final int notnull = ResultSetMetaData.columnNoNulls; 00136 for (int i = 0; i < cols.length; i++) { 00137 t.getColumn(cols[i]).setNullable(notnull); 00138 } 00139 } 00140 }