Source code: javatools/db/DbReferencedInserter.java
1 /*
2 * DbReferencedInserter.java
3 *
4 * Created on 12 febbraio 2002, 20.27
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 import java.util.*;
28 import java.sql.*;
29 import javatools.util.FileLog;
30 import javatools.util.ArrayComparator;
31
32 /**
33 * It is just like a DbInserter, except on the fact it takes care of constraints.
34 * @author Antonio Petrelli
35 * @version 0.2.0
36 */
37 public class DbReferencedInserter extends DbInserter {
38
39 /** Creates new DbReferencedInserter
40 * @param table The table to insert rows into.
41 * @param selector The selector used to insert rows.
42 */
43
44 DbReferencedInserter(DbAbstractTable table, DbSelector selector) {
45 super(table, selector);
46 }
47
48 /** Creates new DbReferencedInserter
49 * @param table The table to insert rows into.
50 */
51 DbReferencedInserter(DbAbstractTable table) {
52 super(table);
53 }
54
55 /**
56 * Execute this command on a specific connection.
57 *
58 * @param dbcon Description of Parameter
59 * @return The number of record affected.
60 * @exception DbException Description of Exception
61 */
62
63 /**
64 * Execute this command on the default connection.
65 *
66 * @return The number of record affected.
67 * @exception DbException If something goes wrong, for example father keys not found.
68 */
69 public int execute() throws DbException {
70 DbConstraint tempConstraint;
71
72 tempConstraint = table.getConstraint();
73 if (tempConstraint != null) {
74 tempConstraint.clear();
75 tempConstraint.setSelector(selector);
76 tempConstraint.setValueLists(intoList, fromList);
77 return tempConstraint.update(DbConstraint.INSERT_OPERATION);
78 }
79 else
80 return super.execute();
81 }
82
83 }