01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.lucene.store.jdbc.index.oracle;
18:
19: import java.io.IOException;
20: import java.io.OutputStream;
21: import java.sql.ResultSet;
22:
23: import org.apache.lucene.store.jdbc.support.JdbcTable;
24: import org.compass.core.util.MethodInvoker;
25:
26: /**
27: * @author kimchy
28: */
29: public abstract class OracleIndexOutputHelper {
30:
31: public static String sqlInsert(JdbcTable table) {
32: return new StringBuffer().append("insert into ").append(
33: table.getQualifiedName()).append(" (").append(
34: table.getNameColumn().getQuotedName()).append(", ")
35: .append(table.getValueColumn().getQuotedName()).append(
36: ", ").append(
37: table.getSizeColumn().getQuotedName()).append(
38: ", ").append(
39: table.getLastModifiedColumn().getQuotedName())
40: .append(", ").append(
41: table.getDeletedColumn().getQuotedName())
42: .append(") values ( ?, EMPTY_BLOB(), ?, ").append(
43: table.getDialect()
44: .getCurrentTimestampFunction()).append(
45: ", ?").append(" )").toString();
46: }
47:
48: public static String sqlUpdate(JdbcTable table) {
49: return new StringBuffer().append("select ").append(
50: table.getValueColumn().getQuotedName()).append(
51: " as x from ").append(table.getQualifiedName()).append(
52: " where ")
53: .append(table.getNameColumn().getQuotedName()).append(
54: " = ? for update").toString();
55: }
56:
57: public static OutputStream getBlobOutputStream(ResultSet rs)
58: throws IOException {
59: MethodInvoker getBlobMethod = new MethodInvoker();
60: getBlobMethod.setTargetMethod("getBLOB");
61: getBlobMethod.setTargetObject(rs);
62: getBlobMethod.setArguments(new Object[] { "x" });
63: Object BLOB;
64: try {
65: BLOB = getBlobMethod.prepare().invoke();
66: } catch (Exception e) {
67: throw new RuntimeException("Failed to getBLOB on [" + rs
68: + "]", e);
69: }
70: MethodInvoker getBinaryOutputStreamMethod = new MethodInvoker();
71: getBinaryOutputStreamMethod
72: .setTargetMethod("getBinaryOutputStream");
73: getBinaryOutputStreamMethod.setTargetObject(BLOB);
74: try {
75: return (OutputStream) getBinaryOutputStreamMethod.prepare()
76: .invoke();
77: } catch (Exception e) {
78: throw new RuntimeException(
79: "Failed to getBinaryOutputStream on [" + BLOB + "]",
80: e);
81: }
82: }
83:
84: }
|