From: idfx Date: Wed, 5 Mar 2003 19:16:50 +0000 (+0000) Subject: some coding style cleanup X-Git-Tag: BEFORE_MERGE_1_1~244 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=7fac0ba44e0920e847b453f597ffff280247fdeb;p=mir.git some coding style cleanup --- diff --git a/source/mircoders/entity/EntityImages.java b/source/mircoders/entity/EntityImages.java index c139b340..21c2c75a 100755 --- a/source/mircoders/entity/EntityImages.java +++ b/source/mircoders/entity/EntityImages.java @@ -34,8 +34,10 @@ package mircoders.entity; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; import org.postgresql.largeobject.BlobInputStream; @@ -53,7 +55,7 @@ import mir.storage.StorageObjectFailure; * Diese Klasse enth?lt die Daten eines MetaObjekts * * @author RK, mh, mir-coders - * @version $Id: EntityImages.java,v 1.16 2003/02/28 18:27:08 idfx Exp $ + * @version $Id: EntityImages.java,v 1.17 2003/03/05 19:16:50 idfx Exp $ */ @@ -76,12 +78,12 @@ public class EntityImages extends EntityUploadedMedia // methods - public InputStream getImage() throws StorageObjectFailure - { + public InputStream getImage() throws StorageObjectFailure { logger.debug("EntityImages.getimage started"); - java.sql.Connection con=null;Statement stmt=null; - BlobInputStream in; InputStream img_in = null; - + java.sql.Connection con=null; + Statement stmt=null; + BlobInputStream in; + InputStream img_in = null; try { con = theStorageObject.getPooledCon(); con.setAutoCommit(false); @@ -101,35 +103,33 @@ public class EntityImages extends EntityUploadedMedia } rs.close(); } - } - catch (Exception e) { - logger.error("EntityImages.getImage failed: "+e.toString()); + } catch (SQLException e) { + logger.error("EntityImages.getImage failed: " + e.toString()); e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); - try { - con.setAutoCommit(true); - } - catch (Exception e2) { - logger.error("EntityImages.getImage reseting transaction mode failed: " + e2.toString()); - e2.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); - } - - try { - theStorageObject.freeConnection(con, stmt); - } - catch (Throwable t) { - } - throwStorageObjectFailure(e, "EntityImages -- getImage failed: "); - } - //} + } finally { + try { + con.setAutoCommit(true); + } catch (SQLException e) { + logger.error("EntityImages.getIcon resetting transaction mode failed: " + e.toString()); + e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); + throwStorageObjectFailure(e, "EntityImages -- resetting transaction mode failed:"); + } + try { + theStorageObject.freeConnection(con, stmt); + } catch (Throwable e) { + throwStorageObjectFailure(e, "EntityImages -- freeing connection failed:"); + } + } return img_in; } public void setImage(InputStream in, String type) - throws StorageObjectFailure { + throws StorageObjectFailure { - if (in!=null) { - java.sql.Connection con=null;PreparedStatement pstmt=null; + if (in != null) { + Connection con = null; + PreparedStatement pstmt = null; File f = null; try { logger.debug("EntityImages.settimage :: making internal representation of image"); @@ -168,20 +168,17 @@ public class EntityImages extends EntityUploadedMedia setValueForProperty("image_data", new Integer(oidImage).toString()); setValueForProperty("icon_data", new Integer(oidIcon).toString()); update(); - } - catch (Exception e) { + } catch (Exception e) { throwStorageObjectFailure(e, "settimage :: setImage gescheitert: "); - } - finally { + } finally { try { if (con!=null) con.setAutoCommit(true); // get rid of the temp. file f.delete(); + } catch (SQLException e) { + throwStorageObjectFailure(e,"Resetting transaction-mode failed"); } - catch (Exception e) { - } - if (con!=null) theStorageObject.freeConnection(con,pstmt); } @@ -194,11 +191,12 @@ public class EntityImages extends EntityUploadedMedia * * It will also take care of closing the OutputStream. */ - public InputStream getIcon() throws StorageObjectFailure - { - java.sql.Connection con=null;Statement stmt=null; - BlobInputStream in=null;ImageInputStream img_in=null; - + public InputStream getIcon() throws StorageObjectFailure { + Connection con=null; + Statement stmt=null; + BlobInputStream in=null; + ImageInputStream img_in=null; + try { con = theStorageObject.getPooledCon(); con.setAutoCommit(false); @@ -218,27 +216,24 @@ public class EntityImages extends EntityUploadedMedia } rs.close(); } - } - catch (Throwable e) { + } catch (SQLException e) { logger.error("EntityImages.getIcon failed: "+e.toString()); e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); + throwStorageObjectFailure(e, "EntityImages -- getIcon failed:"); + } finally { try { con.setAutoCommit(true); + } catch (SQLException e) { + logger.error("EntityImages.getIcon resetting transaction mode failed: " + e.toString()); + e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); + throwStorageObjectFailure(e, "EntityImages -- resetting transaction mode failed:"); } - catch (Throwable e2) { - logger.error("EntityImages.getIcon reseting transaction mode failed: " + e2.toString()); - e2.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); - } - - try { + try { theStorageObject.freeConnection(con, stmt); + } catch (Throwable e) { + throwStorageObjectFailure(e, "EntityImages -- freeing connection failed:"); } - catch (Throwable t) { - } - - throwStorageObjectFailure(e, "EntityImages -- getIcon failed:"); } - return img_in; } @@ -249,12 +244,11 @@ public class EntityImages extends EntityUploadedMedia private class ImageInputStream extends InputStream { InputStream _in; - java.sql.Connection _con; + Connection _con; Statement _stmt; - public ImageInputStream(BlobInputStream in, java.sql.Connection con, - Statement stmt ) - { + public ImageInputStream(BlobInputStream in, Connection con, + Statement stmt ) { _in = in; _con = con; _stmt = stmt; @@ -262,12 +256,10 @@ public class EntityImages extends EntityUploadedMedia public void close () throws IOException { _in.close(); - try { _con.setAutoCommit(true); theStorageObject.freeConnection(_con,_stmt); - } - catch (Exception e) { + } catch (Exception e) { throw new IOException("close(): "+e.toString()); } } @@ -275,6 +267,5 @@ public class EntityImages extends EntityUploadedMedia public int read() throws IOException { return _in.read(); } - } }