01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: org_apache_derby_jdbc_EmbeddedDriver.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.cmf.dam.contentstores.textstoredrivers;
09:
10: import com.uwyn.rife.config.RifeConfig;
11: import com.uwyn.rife.database.Datasource;
12: import com.uwyn.rife.database.queries.CreateTable;
13: import java.io.IOException;
14: import java.io.OutputStream;
15: import java.io.Reader;
16: import java.sql.Clob;
17: import java.sql.ResultSet;
18: import java.sql.SQLException;
19:
20: public class org_apache_derby_jdbc_EmbeddedDriver extends generic {
21: public org_apache_derby_jdbc_EmbeddedDriver(Datasource datasource) {
22: super (datasource);
23:
24: mCreateTableContent = new CreateTable(getDatasource()).table(
25: RifeConfig.Cmf.getTableContentStoreText()).column(
26: "contentId", int.class, CreateTable.NOTNULL).column(
27: getContentSizeColumnName(), int.class,
28: CreateTable.NOTNULL).column("content", Clob.class)
29: .primaryKey("PK_CONTENTTEXT", "contentId").foreignKey(
30: "FK_CONTENTTEXT",
31: RifeConfig.Cmf.getTableContentInfo(),
32: "contentId", "contentId");
33: }
34:
35: protected void outputContentColumn(ResultSet resultSet,
36: OutputStream os) throws SQLException {
37: Clob clob = resultSet.getClob("content");
38: Reader text_reader = clob.getCharacterStream();
39: char[] buffer = new char[512];
40: int size = 0;
41: try {
42: while ((size = text_reader.read(buffer)) != -1) {
43: os.write(new String(buffer).getBytes("UTF-8"), 0, size);
44: }
45:
46: os.flush();
47: } catch (IOException e) {
48: // don't do anything, the client has probably disconnected
49: }
50: }
51: }
|