FileDocCategorySizeDatePackage
DatabaseOutputStream.javaAPI DocGlassfish v2 API4903Fri May 04 22:34:40 BST 2007com.sun.jdo.spi.persistence.generator.database

DatabaseOutputStream

public class DatabaseOutputStream extends OutputStream

Fields Summary
private static final com.sun.jdo.spi.persistence.utility.logging.Logger
logger
The logger
private static final ResourceBundle
messages
I18N message handler
private Connection
conn_
Connection to the database.
Constructors Summary
public DatabaseOutputStream(Connection conn)


    // XXX FIXME Assert conn != null and directly set the value of conn;
    // remove setConnection (below)
       
        super();
        setConnection(conn);
    
public DatabaseOutputStream()

        super();
    
Methods Summary
public voidclose()
Closes the database connection.

        try {
            // XXX test is not necessary once we assert not null in constructor
            if (conn_ != null) {
                conn_.commit();
                // Close the connection
                conn_.close();
            }

        } catch (SQLException e) {
        if (logger.isLoggable(Logger.FINE))
            logger.fine("Exception in cleanup", e); // NOI18N
        }
    
public voidflush()
Commits the database connection.

        try {
            // XXX test is not necessary once we assert not null in constructor
            if (conn_ != null) {
                conn_.commit();
            }
        } catch (SQLException e) {
            if (logger.isLoggable(Logger.FINE))
               logger.fine("Exception in cleanup", e); // NOI18N
        }
    
public voidsetConnection(java.sql.Connection conn)

        conn_ = conn;
    
public voidwrite(int b)
This method is not supported in DatabaseOutputStream because it doesn't make sense to write a single int to a database stream. So always throws UnsupportedOperationException.

throws
UnsupportedOperationException

        throw new UnsupportedOperationException(); 
    
public voidwrite(java.lang.String stmt)
Executes the given statement in the database.

param
stmt SQL to be executed
throws
SQLException Thrown if there is a problem preparing stmt as a statement, or in executing it.

        PreparedStatement pstmt = conn_.prepareStatement(stmt);
        pstmt.execute();