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.Externalizable;
042: import java.io.IOException;
043: import java.io.ObjectInput;
044: import java.io.ObjectOutput;
045:
046: import java.util.Vector;
047:
048: import java.sql.ResultSetMetaData;
049: import java.sql.SQLException;
050:
051: import com.quadcap.sql.types.Value;
052:
053: import com.quadcap.util.Debug;
054:
055: /**
056: * Constraint implementation of <b>NOT NULL</b>
057: *
058: * @author Stan Bailes
059: */
060: public class NotNullConstraint extends Constraint implements
061: Externalizable {
062: public NotNullConstraint() {
063: }
064:
065: public NotNullConstraint(String name) {
066: super (name);
067: }
068:
069: public NotNullConstraint(String name, Vector names) {
070: super (name, names);
071: }
072:
073: public void add(Session session) {
074: }
075:
076: public void checkInsert(Session session, Row row)
077: throws SQLException, IOException {
078: int[] cols = getColumns();
079: for (int i = 0; i < cols.length; i++) {
080: int col = cols[i];
081: if (Value.isNull(row.item(col))) {
082: throw new SQLException(
083: "Not null constraint violated, column "
084: + table.getColumn(col).getShortName()
085: + " in table " + table.getName(),
086: "23000");
087: }
088: }
089: }
090:
091: public void applyInsert(Session session, Row row, long rowId,
092: Constraint activeIndex) throws SQLException, IOException {
093: }
094:
095: public void checkUpdate(Session session, byte[] oldKey, Row row,
096: Row oldRow, long rowId, Constraint activeIndex)
097: throws SQLException, IOException {
098: checkInsert(session, row);
099: }
100:
101: public void applyUpdate(Session session, byte[] oldKey, Row row,
102: Row oldRow, long rowId, Constraint activeIndex)
103: throws SQLException, IOException {
104: }
105:
106: public void checkDelete(Session session, Row row, long rowId)
107: throws SQLException, IOException {
108: }
109:
110: public void applyDelete(Session session, Row row, long rowId,
111: Constraint activeIndex) throws SQLException, IOException {
112: }
113:
114: public void delete(Session session) {
115: }
116:
117: public void readExternal(ObjectInput in) throws IOException,
118: ClassNotFoundException {
119: super .readExternal(in);
120: }
121:
122: public void writeExternal(ObjectOutput out) throws IOException {
123: super .writeExternal(out);
124: }
125:
126: public void setTable(Table t) throws SQLException {
127: super .setTable(t);
128: int[] cols = getColumns();
129: final int notnull = ResultSetMetaData.columnNoNulls;
130: for (int i = 0; i < cols.length; i++) {
131: t.getColumn(cols[i]).setNullable(notnull);
132: }
133: }
134: }
|