Source code: javatools/db/DbAbstractTable.java
1 /*
2 * DbAbstractDatabaseTable.java
3 *
4 * Created on 31 marzo 2003, 11.02
5 Javatools (modified version) - Some useful general classes.
6 Copyright (C) 2002-2003 Chris Bitmead (original) Antonio Petrelli (modified)
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 Contact me at: brenmcguire@users.sourceforge.net
23 */
24
25 package javatools.db;
26
27 /**
28 *
29 * @author Antonio Petrelli
30 * @version 0.2.0
31 */
32 public abstract class DbAbstractTable extends javatools.db.AbstractTable {
33
34 /** Creates a new instance of DbAbstractDatabaseTable */
35 public DbAbstractTable(DbDatabase db) {
36 this.db = db;
37 }
38
39 /** Get the database that this table came from
40 * When inheriting, you can pass a "null" value.
41 *
42 * @return The database value
43 */
44 public DbDatabase getDatabase() {
45 return db;
46 }
47
48 /** Returns the DbConstraint object associated with this table.
49 * @return The requested DbConstraint.
50 */
51 public abstract DbConstraint getConstraint();
52
53 /**
54 * Get the DbColumn representing the column with this name.
55 *
56 * @param name The name of the needed column
57 * @return The column value
58 * @exception DbException If something goes wrong.
59 */
60 public abstract DbColumn getColumn(String name) throws DbException;
61
62 /**
63 * Get the column of the given index. Index is a zero based array.
64 *
65 * @param index The position of the needed column.
66 * @return The column value
67 * @exception DbException If something goes wrong.
68 */
69 public abstract DbColumn getColumn(int index) throws DbException;
70
71 /** Returns the default value for the field at the given index.
72 * @param index The field index.
73 * @throws DbException If something goes wrong.
74 * @return The default value for the requested field.
75 */
76 public abstract Object getDefault(int index) throws DbException;
77
78 /** Returns the default value for the field whose name is specified.
79 * @param name The name of the needed field.
80 * @throws DbException If something goes wrong.
81 * @return The default value for the requested field.
82 */
83 public abstract Object getDefault(String name) throws DbException;
84
85 /**
86 * Return an inserter for inserting new data in the database. This method is
87 * for SQL of the form INSERT INTO table(...) SELECT ...
88 *
89 * @param selector The selector that will be used to build this inserter.
90 * @return The brand new inserter.
91 * @exception DbException If something goes wrong.
92 */
93 public DbInserter inserter(DbSelector selector) throws DbException {
94 return new DbInserter(this, selector);
95 }
96
97 /** Return an inserter for inserting new data in the database. This method is
98 * for SQL of the form INSERT INTO table(...) SELECT ...
99 * This inserter DOES NOT take care of constraints.
100 *
101 * @param selector The selector to create the DbInserter object.
102 * @throws DbException If something goes wrong.
103 * @return The DbInserter object to perform a simple insertion.
104 */
105 public DbInserter simpleInserter(DbSelector selector) throws DbException {
106 return new DbInserter(this, selector);
107 }
108
109 /**
110 * Return an inserter for inserting new data in the database. This method is
111 * for SQL of the form INSERT INTO table(...) VALUES(...)
112 *
113 * @return The brand new inserter.
114 * @exception DbException If something goes wrong.
115 */
116 public DbInserter inserter() throws DbException {
117 return new DbInserter(this);
118 }
119
120 /** Return an inserter for inserting new data in the database. This method is
121 * for SQL of the form INSERT INTO table(...) SELECT ...
122 * This inserter DOES NOT take care of constraints.
123 *
124 * @throws DbException If something goes wrong.
125 * @return The DbInserter object to perform a simple insertion.
126 */
127 public DbInserter simpleInserter() throws DbException {
128 return new DbInserter(this);
129 }
130
131 /** Returns an updater for this table.
132 * @throws DbException If something goes wrong.
133 * @return The brand new updater.
134 */
135 public DbUpdater updater() throws DbException {
136 return new DbUpdater(this);
137 }
138
139 /** Return an updater for updating rows in the database.
140 * This updater DOES NOT take care of constraints.
141 *
142 * @throws DbException If something goes wrong.
143 * @return The DbUpdater object to perform update operations.
144 */
145 public DbUpdater simpleUpdater() throws DbException {
146 return new DbUpdater(this);
147 }
148
149 /** Returns a deleter for this table.
150 * @throws DbException If something goes wrong.
151 * @return The brand new deleter.
152 */
153 public DbDeleter deleter() throws DbException {
154 return new DbDeleter(this);
155 }
156
157 /** Returns a deleter for deleting rows in the database.
158 * This deleter takes care of constraints.
159 *
160 * @throws DbException If something goes wrong.
161 * @return The DbDeleter object to perform delete operations.
162 */
163 public DbDeleter simpleDeleter() throws DbException {
164 return new DbDeleter(this);
165 }
166
167 protected DbDatabase db;
168 }