68
|
1 /*
|
|
2 Copyright (c) 2008 Franklin Schmidt <fschmidt@gmail.com>
|
|
3
|
|
4 Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5 of this software and associated documentation files (the "Software"), to deal
|
|
6 in the Software without restriction, including without limitation the rights
|
|
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8 copies of the Software, and to permit persons to whom the Software is
|
|
9 furnished to do so, subject to the following conditions:
|
|
10
|
|
11 The above copyright notice and this permission notice shall be included in
|
|
12 all copies or substantial portions of the Software.
|
|
13
|
|
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20 THE SOFTWARE.
|
|
21 */
|
|
22
|
|
23 package fschmidt.db.extend;
|
|
24
|
|
25 import java.sql.ResultSet;
|
|
26 import java.sql.SQLException;
|
|
27 import fschmidt.db.DbTable;
|
|
28 import fschmidt.db.DbDatabase;
|
|
29 import fschmidt.db.DbObject;
|
|
30 import fschmidt.db.DbKeySetter;
|
|
31 import fschmidt.db.DbKey;
|
|
32 import fschmidt.db.DbRecord;
|
|
33
|
|
34
|
|
35 public abstract class DbTableExt<K extends DbKey,V extends DbObject<K,V>> implements DbTable<K,V> {
|
|
36 protected final DbDatabaseExt database;
|
|
37
|
|
38 protected DbTableExt(DbDatabaseExt database) {
|
|
39 this.database = database;
|
|
40 }
|
|
41
|
|
42 public abstract DbKeySetter<K> getKeySetter();
|
|
43 public abstract V getDbObject(K key,ResultSet rs,String tableName) throws SQLException;
|
|
44
|
|
45 public final DbDatabaseExt getDbDatabaseExt() {
|
|
46 return database;
|
|
47 }
|
|
48
|
|
49 public final DbDatabase getDbDatabase() {
|
|
50 return getDbDatabaseExt();
|
|
51 }
|
|
52
|
|
53 public final DbRecord<K,V> newRecord(V obj,K key) {
|
|
54 return getDbDatabaseExt().newRecord(this,obj,key);
|
|
55 }
|
|
56
|
|
57 public final DbRecord<K,V> newRecord(V obj) {
|
|
58 return getDbDatabaseExt().newRecord(this,obj);
|
|
59 }
|
|
60
|
|
61 public final V getDbObject(K key,ResultSet rs)
|
|
62 throws SQLException
|
|
63 {
|
|
64 return getDbObject(key,rs,getTableName());
|
|
65 }
|
|
66
|
|
67 public final V getDbObject(ResultSet rs)
|
|
68 throws SQLException
|
|
69 {
|
|
70 return getDbObject(getKeySetter().getKey(rs),rs);
|
|
71 }
|
|
72
|
|
73 public final V getDbObject(ResultSet rs,String tableName)
|
|
74 throws SQLException
|
|
75 {
|
|
76 return getDbObject(getKeySetter().getKey(rs,tableName),rs,tableName);
|
|
77 }
|
|
78
|
|
79 public String toString() {
|
|
80 return getTableName();
|
|
81 }
|
|
82
|
|
83 }
|