001: /*
002: * $Id: Table.java,v 1.61 2007/11/13 19:04:02 rwald Exp $
003: * =======================================================================
004: * Copyright (c) 2002-2005 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040:
041: package org.axiondb;
042:
043: import java.io.File;
044: import java.util.Iterator;
045: import java.util.List;
046:
047: import org.apache.commons.collections.primitives.IntCollection;
048: import org.axiondb.event.TableModificationListener;
049:
050: /**
051: * A database table.
052: *
053: * @version $Revision: 1.61 $ $Date: 2007/11/13 19:04:02 $
054: * @author Chuck Burdick
055: * @author Rodney Waldhoff
056: * @author Ahimanikya Satapathy
057: */
058: public interface Table extends RowSource {
059: public static final String REGULAR_TABLE_TYPE = "TABLE";
060: public static final String SYSTEM_TABLE_TYPE = "SYSTEM TABLE";
061:
062: /**
063: * Add the given {@link Column}to this table.
064: */
065: void addColumn(Column col) throws AxionException;
066:
067: void addConstraint(Constraint constraint) throws AxionException;
068:
069: /**
070: * Add an index, associating it with a {@link Column}, and adding it as a
071: * {@link org.axiondb.TableModificationListener}to the table.
072: *
073: * @see #addIndex
074: * @see #addTableModificationListener
075: * @see #getIndexForColumn
076: * @see #isColumnIndexed
077: * @see #populateIndex
078: * @param index
079: * @exception AxionException
080: */
081: void addIndex(Index index) throws AxionException;
082:
083: /**
084: * Insert the given {@link Row}.
085: */
086: void addRow(Row row) throws AxionException;
087:
088: /**
089: * Adds a listener to receive events on this table
090: */
091: void addTableModificationListener(TableModificationListener listener);
092:
093: Iterator<TableModificationListener> getTableModificationListeners();
094:
095: /**
096: * Remove the specified rows from this table and any associated indices. This process
097: * is allowed to be destructive, the table my delete values from the given list.
098: */
099: void applyDeletes(IntCollection rowids) throws AxionException;
100:
101: /**
102: * Insert the given rows into this table and any associated indices. This process is
103: * allowed to be destructive, the table my delete rows from the given list.
104: *
105: * @param rows a collection of Rows
106: * @throws AxionException
107: */
108: void applyInserts(RowCollection rows) throws AxionException;
109:
110: /**
111: * Update the given rows in this table and any associated indices. This process is
112: * allowed to be destructive, the table my delete rows from the given list.
113: */
114: void applyUpdates(RowCollection rows) throws AxionException;
115:
116: /** Drop this table from the database. */
117: void drop() throws AxionException;
118:
119: /** Un-reserve a row id. */
120: void freeRowId(int id);
121:
122: /**
123: * Return the {@link Column}corresponding to the given zero-based <i>index </i>.
124: */
125: Column getColumn(int index);
126:
127: /**
128: * Return the {@link Column}for the given <i>name </i>.
129: */
130: Column getColumn(String name);
131:
132: /**
133: * Return the number of {@link Column}s I contain.
134: */
135: int getColumnCount();
136:
137: /**
138: * Return an readonly {@link List}over the {@link ColumnIdentifier ColumnIdentifiers}for
139: * my {@link Column}s.
140: */
141: List getColumnIdentifiers();
142:
143: /**
144: * Return the zero-based index of the {@link Column}with the given <i>name </i>.
145: */
146: int getColumnIndex(String name) throws AxionException;
147:
148: Iterator getConstraints();
149:
150: /**
151: * @param readOnly when <code>true</code>, the caller does not expect to be able to
152: * modify (i.e., call {@link RowIterator#set}or {@link RowIterator#remove}on)
153: * the returned {@link RowIterator}, the returned iterator <i>may </i> be
154: * unmodifiable.
155: */
156: RowIterator getIndexedRows(Selectable where, boolean readOnly)
157: throws AxionException;
158:
159: RowIterator getIndexedRows(RowSource source, Selectable where,
160: boolean readOnly) throws AxionException;
161:
162: /**
163: * Return the first {@link Index}that pertains to the given {@link Column}, or
164: * <code>null</code> if no such {@link Index}exists.
165: *
166: * @return the pertinent {@link Column}, or <code>null</code> if no such
167: * {@link Index}exists
168: */
169: Index getIndexForColumn(Column column);
170:
171: /** Obtain an {@link Iterator}over my indices. */
172: Iterator<Index> getIndices();
173:
174: /**
175: * Obtain an {@link RowIterator iterator}over my {@link Row}s where each
176: * {@link Selectable Selectable}in the <i>selectable </i> {@link List list}
177: * {@link Selectable#evaluate evaluates}to the corresponding value in the <i>value
178: * </i> {@link List list}.
179: * <p>
180: * This is functionally similiar to executing a SELECT over this table where
181: * <i>selectable[i] </i>= <i>value[i] </i> for each value of <i>i </i>. The return
182: * RowIterator is not modifiable.
183: */
184: RowIterator getMatchingRows(List selectables, List values,
185: boolean readOnly) throws AxionException;
186:
187: /** Get the name of this table. */
188: String getName();
189:
190: /** Reserve a row id. */
191: int getNextRowId();
192:
193: /**
194: * Return the number of {@link Row}s I contain.
195: */
196: int getRowCount();
197:
198: /**
199: * Obtain an {@link RowIterator iterator}over my {@link Row}s.
200: *
201: * @param readOnly when <code>true</code>, the caller does not expect to be able to
202: * modify (i.e., call {@link RowIterator#set}or {@link RowIterator#remove}on)
203: * the returned {@link RowIterator}, the returned iterator <i>may </i> be
204: * unmodifiable.
205: */
206: RowIterator getRowIterator(boolean readOnly) throws AxionException;
207:
208: /** Get the type of this table. */
209: String getType();
210:
211: /**
212: * Indicate whether the {@link ColumnIdentifier}references a column in this table
213: */
214: boolean hasColumn(ColumnIdentifier id);
215:
216: boolean hasIndex(String name) throws AxionException;
217:
218: /**
219: * Check to see if an {@link Index}exists for the given {@link Column}
220: *
221: * @param column {@link Column}to check
222: * @return true iff there is an existing {@link Index}for the given {@link Column}
223: */
224: boolean isColumnIndexed(Column column);
225:
226: /**
227: * check if primary constraint exists on a column
228: *
229: * @param ColumnName name of the column
230: * @return if PrimaryKeyConstraint exists on the column
231: */
232: boolean isPrimaryKeyConstraintExists(String columnName);
233:
234: /**
235: * check if unique constraint exists on a column
236: *
237: * @param columnName name of the columm
238: * @return true if uniqueConstraint exists on the column
239: */
240: boolean isUniqueConstraintExists(String columnName);
241:
242: RowDecorator makeRowDecorator();
243:
244: /** Create a {@link TransactableTable}for this table. */
245: TransactableTable makeTransactableTable();
246:
247: /** Migrate from older version to newer version for this table*/
248: void migrate() throws AxionException;
249:
250: /**
251: * Populate an {@link Index}, adding my current rows to it. Does not
252: * {@link #addIndex add}the index.
253: *
254: * @see #addIndex
255: * @param index
256: * @exception AxionException
257: */
258: void populateIndex(Index index) throws AxionException;
259:
260: /** Notify this table that its disk-location has moved. */
261: void remount(File dir, boolean dataOnly) throws AxionException;
262:
263: Constraint removeConstraint(String name);
264:
265: Constraint getConstraint(String name);
266:
267: /**
268: * Remove an index, both from the indices and as a TableModificationListener
269: *
270: * @param index
271: * @exception AxionException
272: */
273: void removeIndex(Index index) throws AxionException;
274:
275: /**
276: * Removes a listener so that it stops receiving events on this table
277: */
278: void removeTableModificationListener(
279: TableModificationListener listener);
280:
281: void rename(String oldName, String newName) throws AxionException;
282:
283: /** The database is shutting down, shutdown this table also. */
284: void shutdown() throws AxionException;
285:
286: /**
287: * Unconditionally delete all rows in this table.
288: *
289: * @return true if truncation succeeded; false otherwise
290: */
291: void truncate() throws AxionException;
292:
293: /**
294: * Update the given {@link Row}.
295: */
296: void updateRow(Row oldrow, Row newrow) throws AxionException;
297:
298: /**
299: * Delete the given {@link Row}.
300: */
301: void deleteRow(Row row) throws AxionException;
302:
303: void checkpoint() throws AxionException;
304:
305: void setSequence(Sequence seq) throws AxionException;
306:
307: Sequence getSequence();
308:
309: void setDeferAllConstraints(boolean deferAll);
310:
311: }
|