01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.persistence.lobs;
19:
20: import java.io.InputStream;
21: import java.sql.Blob;
22: import java.sql.PreparedStatement;
23: import java.sql.ResultSet;
24: import java.sql.SQLException;
25:
26: public class DB2LOBPolicy implements LOBPolicy {
27:
28: /**
29: * Answer true is SELECT FOR UPDATE is necessary to for setting the blob
30: */
31: public boolean requiresSelectForUpdate() {
32: return true;
33: }
34:
35: public boolean supportsSelectIntoForBlobs() {
36: return true;
37: }
38:
39: /**
40: * Answer the String to be included in an insert statement to create an
41: * empty blob
42: */
43: public String getEmptyBlobFunction() {
44: return "null";
45: }
46:
47: /**
48: * Set the blob field in the way required by the underlying database.
49: */
50: public void setBlob(Blob blob, PreparedStatement statement,
51: int index, byte[] bytes) throws SQLException {
52: BlobImpl db2Blob = new BlobImpl(bytes);
53:
54: statement.setBlob(index, db2Blob);
55: }
56:
57: /**
58: * Set the blob field in the way required by the underlying database.
59: */
60: public void setBlob(Blob blob, PreparedStatement statement,
61: int index, InputStream stream, int length)
62: throws SQLException {
63:
64: statement.setBinaryStream(index, stream, length);
65: }
66:
67: /**
68: * Retrieve the blob field in the way required by the underlying database.
69: */
70: public InputStream getBinaryStream(ResultSet rs, int index)
71: throws SQLException {
72: Blob blob = rs.getBlob(index);
73:
74: if (blob == null) {
75:
76: return null;
77: } else {
78:
79: return blob.getBinaryStream();
80: }
81: }
82: }
|