00001
package com.quadcap.sql;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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
00057
00058
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 }