01: package org.apache.ojb.broker.accesslayer.sql;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.util.logging.Logger;
19:
20: /**
21: * Model an INSERT Statement for M:N indirection table
22: *
23: * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
24: * @version $Id: SqlInsertMNStatement.java,v 1.7.2.1 2005/12/21 22:23:44 tomdz Exp $
25: */
26: public class SqlInsertMNStatement extends SqlMNStatement {
27:
28: /**
29: * Constructor for SqlInsertMNStatement.
30: * @param table
31: * @param columns
32: */
33: public SqlInsertMNStatement(String table, String[] columns,
34: Logger logger) {
35: super (table, columns, logger);
36: }
37:
38: /**
39: * generates a values(?,) for a prepared insert statement.
40: * @param stmt the StringBuffer
41: */
42: private void appendListOfValues(StringBuffer stmt) {
43: int cnt = getColumns().length;
44:
45: stmt.append(" VALUES (");
46:
47: for (int i = 0; i < cnt; i++) {
48: if (i > 0) {
49: stmt.append(',');
50: }
51: stmt.append('?');
52: }
53: stmt.append(')');
54: }
55:
56: /**
57: * @see org.apache.ojb.broker.accesslayer.SqlStatement#getStatement()
58: */
59: public String getStatement() {
60: StringBuffer stmt = new StringBuffer(1024);
61:
62: stmt.append("INSERT INTO ");
63: appendTable(getTable(), stmt);
64: stmt.append(" (");
65: appendListOfColumns(getColumns(), stmt);
66: stmt.append(")");
67: appendListOfValues(stmt);
68: return stmt.toString();
69: }
70:
71: }
|