KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > access > trans > LOBInsertBatchQueryBuilder


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20
21 package org.apache.cayenne.access.trans;
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.apache.cayenne.dba.DbAdapter;
28 import org.apache.cayenne.map.DbAttribute;
29 import org.apache.cayenne.query.BatchQuery;
30
31 /**
32  * @author Andrus Adamchik
33  */

34 public class LOBInsertBatchQueryBuilder extends LOBBatchQueryBuilder {
35
36     public LOBInsertBatchQueryBuilder(DbAdapter adapter) {
37         super(adapter);
38     }
39
40     public List JavaDoc getValuesForLOBUpdateParameters(BatchQuery query) {
41         List JavaDoc dbAttributes = query.getDbAttributes();
42         int len = dbAttributes.size();
43
44         List JavaDoc values = new ArrayList JavaDoc(len);
45         for (int i = 0; i < len; i++) {
46             Object JavaDoc value = query.getValue(i);
47             DbAttribute attribute = (DbAttribute) dbAttributes.get(i);
48             if (isUpdateableColumn(value, attribute.getType())) {
49                 values.add(value);
50             }
51         }
52
53         return values;
54     }
55
56     public String JavaDoc createSqlString(BatchQuery batch) {
57         String JavaDoc table = batch.getDbEntity().getFullyQualifiedName();
58         List JavaDoc dbAttributes = batch.getDbAttributes();
59         StringBuffer JavaDoc query = new StringBuffer JavaDoc("INSERT INTO ");
60         query.append(table).append(" (");
61         for (Iterator JavaDoc i = dbAttributes.iterator(); i.hasNext();) {
62             DbAttribute attribute = (DbAttribute) i.next();
63             query.append(attribute.getName());
64             if (i.hasNext()) {
65                 query.append(", ");
66             }
67         }
68         query.append(") VALUES (");
69         for (int i = 0; i < dbAttributes.size(); i++) {
70             if (i > 0) {
71                 query.append(", ");
72             }
73
74             appendUpdatedParameter(
75                 query,
76                 (DbAttribute) dbAttributes.get(i),
77                 batch.getValue(i));
78         }
79         query.append(')');
80         return query.toString();
81     }
82 }
83
Popular Tags