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.ByteArrayInputStream;
21: import java.io.InputStream;
22: import java.sql.Blob;
23: import java.sql.PreparedStatement;
24: import java.sql.ResultSet;
25: import java.sql.SQLException;
26:
27: public class PostgreSQLLOBPolicy implements LOBPolicy {
28:
29: /**
30: * Answer true is SELECT FOR UPDATE is necessary to for setting the blob
31: */
32: public boolean requiresSelectForUpdate() {
33: return false;
34: }
35:
36: public boolean supportsSelectIntoForBlobs() {
37: return true;
38: }
39:
40: /**
41: * Answer the String to be included in an insert statement to create an
42: * empty blob
43: */
44: public String getEmptyBlobFunction() {
45: return "null";
46: }
47:
48: /**
49: * Set the blob field in the way required by the underlying database.
50: */
51: public void setBlob(Blob blob, PreparedStatement statement,
52: int index, byte[] bytes) throws SQLException {
53: InputStream in = new ByteArrayInputStream(bytes);
54: statement.setBinaryStream(index, in, bytes.length);
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: statement.setBinaryStream(index, stream, length);
64: }
65:
66: /**
67: * Retrieve the blob field in the way required by the underlying database.
68: */
69: public InputStream getBinaryStream(ResultSet rs, int index)
70: throws SQLException {
71: return rs.getBinaryStream(index);
72: }
73: }
|