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.SQLException;
051:
052: import com.quadcap.sql.index.Btree;
053:
054: import com.quadcap.sql.file.BlockFile;
055: import com.quadcap.sql.file.ByteUtil;
056:
057: import com.quadcap.util.Debug;
058:
059: /**
060: * If a table has no other constraints (e.g., primary key, unique), we
061: * synthesize this constraint to force the creation of an index, since
062: * the table traversal code depends on having an index to iterate.
063: * This is a performance hit for full table scans.
064: *
065: * @author Stan Bailes
066: */
067: public class DefaultTableConstraint extends IndexConstraint implements
068: Externalizable {
069: /**
070: * Default constructor
071: */
072: public DefaultTableConstraint() {
073: this .useComparator = false;
074: }
075:
076: /**
077: * Externalizable.readExternal(): Read me from a stream.
078: */
079: public void readExternal(ObjectInput in) throws IOException,
080: ClassNotFoundException {
081: super .readExternal(in);
082: }
083:
084: /**
085: * Externalizable.writeExternal(): Write me to a stream.
086: */
087: public void writeExternal(ObjectOutput out) throws IOException {
088: super .writeExternal(out);
089: }
090:
091: /**
092: * IndexConstraint.makeKey(): My key is simply the rowId, which is
093: * a short 8-byte quantity guaranteed to be unique. So there.
094: */
095: public byte[] makeKey(Session session, Row row, long rowId) {
096: byte[] key = new byte[8];
097: ByteUtil.putLong(key, 0, rowId);
098: return key;
099: }
100:
101: //#ifdef DEBUG
102: /**
103: * Return a string representation for debugging
104: */
105: public String toString() {
106: return getName();
107: }
108:
109: //#endif
110:
111: public String constraintType() {
112: return "default table constraint";
113: }
114: }
|