1 23 24 29 30 31 package com.sun.jdo.spi.persistence.generator.database; 32 33 import java.io.*; 34 import java.sql.*; 35 import java.util.ResourceBundle ; 36 import com.sun.jdo.spi.persistence.utility.I18NHelper; 37 import com.sun.jdo.spi.persistence.utility.logging.Logger; 38 39 40 45 public class DatabaseOutputStream extends OutputStream { 46 47 private static final Logger logger = 48 LogHelperDatabaseGenerator.getLogger(); 49 50 51 private final static ResourceBundle messages = 52 I18NHelper.loadBundle(DatabaseOutputStream.class); 53 54 55 private Connection conn_ = null; 57 58 public DatabaseOutputStream(Connection conn) { 61 super(); 62 setConnection(conn); 63 } 64 65 public DatabaseOutputStream() { 67 super(); 68 } 69 70 73 public void close() { 74 try { 75 if (conn_ != null) { 77 conn_.commit(); 78 conn_.close(); 80 } 81 82 } catch (SQLException e) { 83 if (logger.isLoggable(Logger.FINE)) 84 logger.fine("Exception in cleanup", e); } 86 } 87 88 91 public void flush() { 92 try { 93 if (conn_ != null) { 95 conn_.commit(); 96 } 97 } catch (SQLException e) { 98 if (logger.isLoggable(Logger.FINE)) 99 logger.fine("Exception in cleanup", e); } 101 } 102 103 109 public void write(int b) { 110 throw new UnsupportedOperationException (); 111 } 112 113 119 public void write(String stmt) throws SQLException { 120 PreparedStatement pstmt = conn_.prepareStatement(stmt); 121 pstmt.execute(); 122 } 123 124 public void setConnection(Connection conn) { 126 conn_ = conn; 127 } 128 } 129 | Popular Tags |