import java.io.File;\r
import java.io.IOException;\r
import java.io.InputStream;\r
+import java.sql.Connection;\r
import java.sql.PreparedStatement;\r
import java.sql.ResultSet;\r
+import java.sql.SQLException;\r
import java.sql.Statement;\r
\r
import org.postgresql.largeobject.BlobInputStream;\r
* Diese Klasse enth?lt die Daten eines MetaObjekts\r
*\r
* @author RK, mh, mir-coders\r
- * @version $Id: EntityImages.java,v 1.16 2003/02/28 18:27:08 idfx Exp $\r
+ * @version $Id: EntityImages.java,v 1.17 2003/03/05 19:16:50 idfx Exp $\r
*/\r
\r
\r
// methods\r
\r
\r
- public InputStream getImage() throws StorageObjectFailure\r
- {\r
+ public InputStream getImage() throws StorageObjectFailure {\r
logger.debug("EntityImages.getimage started");\r
- java.sql.Connection con=null;Statement stmt=null;\r
- BlobInputStream in; InputStream img_in = null;\r
-\r
+ java.sql.Connection con=null;\r
+ Statement stmt=null;\r
+ BlobInputStream in; \r
+ InputStream img_in = null;\r
try {\r
con = theStorageObject.getPooledCon();\r
con.setAutoCommit(false);\r
}\r
rs.close();\r
}\r
- }\r
- catch (Exception e) {\r
- logger.error("EntityImages.getImage failed: "+e.toString());\r
+ } catch (SQLException e) {\r
+ logger.error("EntityImages.getImage failed: " + e.toString());\r
e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));\r
- try {\r
- con.setAutoCommit(true);\r
- }\r
- catch (Exception e2) {\r
- logger.error("EntityImages.getImage reseting transaction mode failed: " + e2.toString());\r
- e2.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));\r
- }\r
-\r
- try {\r
- theStorageObject.freeConnection(con, stmt);\r
- }\r
- catch (Throwable t) {\r
- }\r
-\r
throwStorageObjectFailure(e, "EntityImages -- getImage failed: ");\r
- }\r
- //}\r
+ } finally {\r
+ try {\r
+ con.setAutoCommit(true);\r
+ } catch (SQLException e) {\r
+ logger.error("EntityImages.getIcon resetting transaction mode failed: " + e.toString());\r
+ e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));\r
+ throwStorageObjectFailure(e, "EntityImages -- resetting transaction mode failed:");\r
+ }\r
+ try {\r
+ theStorageObject.freeConnection(con, stmt);\r
+ } catch (Throwable e) {\r
+ throwStorageObjectFailure(e, "EntityImages -- freeing connection failed:");\r
+ }\r
+ }\r
return img_in;\r
}\r
\r
public void setImage(InputStream in, String type)\r
- throws StorageObjectFailure {\r
+ throws StorageObjectFailure {\r
\r
- if (in!=null) {\r
- java.sql.Connection con=null;PreparedStatement pstmt=null;\r
+ if (in != null) {\r
+ Connection con = null;\r
+ PreparedStatement pstmt = null;\r
File f = null;\r
try {\r
logger.debug("EntityImages.settimage :: making internal representation of image");\r
setValueForProperty("image_data", new Integer(oidImage).toString());\r
setValueForProperty("icon_data", new Integer(oidIcon).toString());\r
update();\r
- }\r
- catch (Exception e) {\r
+ } catch (Exception e) {\r
throwStorageObjectFailure(e, "settimage :: setImage gescheitert: ");\r
- }\r
- finally {\r
+ } finally {\r
try {\r
if (con!=null)\r
con.setAutoCommit(true);\r
// get rid of the temp. file\r
f.delete();\r
+ } catch (SQLException e) {\r
+ throwStorageObjectFailure(e,"Resetting transaction-mode failed");\r
}\r
- catch (Exception e) {\r
- }\r
-\r
if (con!=null)\r
theStorageObject.freeConnection(con,pstmt);\r
}\r
*\r
* It will also take care of closing the OutputStream.\r
*/\r
- public InputStream getIcon() throws StorageObjectFailure\r
- {\r
- java.sql.Connection con=null;Statement stmt=null;\r
- BlobInputStream in=null;ImageInputStream img_in=null;\r
-\r
+ public InputStream getIcon() throws StorageObjectFailure {\r
+ Connection con=null;\r
+ Statement stmt=null;\r
+ BlobInputStream in=null;\r
+ ImageInputStream img_in=null;\r
+ \r
try {\r
con = theStorageObject.getPooledCon();\r
con.setAutoCommit(false);\r
}\r
rs.close();\r
}\r
- }\r
- catch (Throwable e) {\r
+ } catch (SQLException e) {\r
logger.error("EntityImages.getIcon failed: "+e.toString());\r
e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));\r
+ throwStorageObjectFailure(e, "EntityImages -- getIcon failed:");\r
+ } finally {\r
try {\r
con.setAutoCommit(true);\r
+ } catch (SQLException e) {\r
+ logger.error("EntityImages.getIcon resetting transaction mode failed: " + e.toString());\r
+ e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));\r
+ throwStorageObjectFailure(e, "EntityImages -- resetting transaction mode failed:");\r
}\r
- catch (Throwable e2) {\r
- logger.error("EntityImages.getIcon reseting transaction mode failed: " + e2.toString());\r
- e2.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));\r
- }\r
-\r
- try {\r
+ try {\r
theStorageObject.freeConnection(con, stmt);\r
+ } catch (Throwable e) {\r
+ throwStorageObjectFailure(e, "EntityImages -- freeing connection failed:");\r
}\r
- catch (Throwable t) {\r
- }\r
-\r
- throwStorageObjectFailure(e, "EntityImages -- getIcon failed:");\r
}\r
-\r
return img_in;\r
}\r
\r
private class ImageInputStream extends InputStream {\r
\r
InputStream _in;\r
- java.sql.Connection _con;\r
+ Connection _con;\r
Statement _stmt;\r
\r
- public ImageInputStream(BlobInputStream in, java.sql.Connection con,\r
- Statement stmt )\r
- {\r
+ public ImageInputStream(BlobInputStream in, Connection con,\r
+ Statement stmt ) {\r
_in = in;\r
_con = con;\r
_stmt = stmt;\r
\r
public void close () throws IOException {\r
_in.close();\r
-\r
try {\r
_con.setAutoCommit(true);\r
theStorageObject.freeConnection(_con,_stmt);\r
- }\r
- catch (Exception e) {\r
+ } catch (Exception e) {\r
throw new IOException("close(): "+e.toString());\r
}\r
}\r
public int read() throws IOException {\r
return _in.read();\r
}\r
-\r
}\r
}\r