📄 postgisgeometrydaoimpl.java
字号:
pstm.setInt(1, pk.intValue()); result = pstm.executeQuery(); if (result.next()) { ejb.setId(pk); ejb.setGeometry(((PGgeometry) result.getObject("geometry")).getGeometry()); ejb.setDescription((String) result.getString("description")); } else { throw new EJBException("ejbLoad unable to load EJB."); } } catch (SQLException se) { throw new EJBException(se); } finally { try { if (result != null) { result.close(); } } catch (Exception e) {} try { if (pstm != null) { pstm.close(); } } catch (Exception e) {} try { if (con != null) { con.close(); } } catch (Exception e) {} } } /** * PostGIS implementation of the entity bean's lifecicle method * <code>ejbStore()</code>. * * @param ejb the ejb whose data must be stored. * @throws javax.ejb.EJBException launched if a generic EJB error is encountered. */ public void store(com.geodetix.geo.ejb.GeometryBean ejb) throws javax.ejb.EJBException { PreparedStatement pstm = null; Connection con = null; try { con = this.dataSource.getConnection(); pstm = con.prepareStatement(PostGisGeometryDAO.EJB_STORE_STATEMENT); pstm.setObject(1, new PGgeometry(ejb.getGeometry())); pstm.setString(2,ejb.getDescription()); pstm.setInt(3, ejb.getId().intValue()); if (pstm.executeUpdate() != 1) { throw new EJBException("ejbStore unable to update EJB."); } } catch (SQLException se) { throw new EJBException(se); } finally { try { if (pstm != null) { pstm.close(); } } catch (Exception e) {} try { if (con != null) { con.close(); } } catch (Exception e) {} } } /** * PostGIS implementation of the entity bean's lifecicle method * <code>ejbRemove()</code>. * * * @param pk primary key of the bean that must be removed . * @throws javax.ejb.RemoveException launched if an error during * EJB remove operation is encountered. * @throws javax.ejb.EJBException launched if a generic EJB error is encountered. */ public void remove(java.lang.Integer pk) throws javax.ejb.RemoveException, javax.ejb.EJBException { PreparedStatement pstm = null; Connection con = null; try { con = this.dataSource.getConnection(); pstm = con.prepareStatement(PostGisGeometryDAO.EJB_REMOVE_STATEMENT); pstm.setInt(1, pk.intValue()); if (pstm.executeUpdate() != 1) { throw new EJBException("ejbRemove unable to remove EJB."); } } catch (SQLException se) { throw new EJBException(se); } finally { try { if (pstm != null) { pstm.close(); } } catch (Exception e) {} try { if (con != null) { con.close(); } } catch (Exception e) {} } } /* =========== Home Interface Utility Methods ============ */ /** * PostGIS implementation of the * {@link com.geodetix.geo.interfaces.GeometryLocalHome#makeDbTable(java.lang.String, int, int)} * method creating a NON-OpenGis compliant table in the PostGIS database. * The table will contain the geometry EJBs. */ public void makeDbTable() { PreparedStatement pstm = null; Connection con = null; try { con = this.dataSource.getConnection(); System.out.println("Creating non-OpenGIG Bean table... "); pstm = con.prepareStatement(PostGisGeometryDAO.HOME_CREATE_NON_OPENGIS_TABLE_STATEMENT); pstm.execute(); System.out.println("...done!"); } catch (SQLException e) { throw new EJBException(e); } finally { try { if (pstm != null) { pstm.close(); } } catch (Exception e) {} try { if (con != null) { con.close(); } } catch (Exception e) {} } } /** * PostGIS implementation of the * {@link com.geodetix.geo.interfaces.GeometryLocalHome#makeDbTable(java.lang.String, int, int)} * method creating an OpenGIS compliant table in the PostGIS database. * The table will contain the geometry EJBs. * * @param gemetryType the string that rapresent a valid PostGIS * geometry type (i.e.: POINT, LINESTRING, POLYGON etc.). * @param srid the SRID of the geometry. * @param geometryDimension the dimension of the geometry. */ public void makeDbTable(String gemetryType, int srid, int geometryDimension) { PreparedStatement pstm = null; Connection con = null; try { con = this.dataSource.getConnection(); System.out.println("Creating OpenGIS Bean table..."); pstm = con.prepareStatement(PostGisGeometryDAO.HOME_CREATE_OPENGIS_TABLE_STATEMENT); pstm.execute(); pstm = con.prepareStatement(PostGisGeometryDAO.ADD_OPEN_GIS_GEOMETRY_COLUMN_STATEMENT); pstm.setInt(1,srid); pstm.setString(2,gemetryType); pstm.setInt(3,geometryDimension); pstm.execute(); System.out.println("...done!"); } catch (SQLException e) { throw new EJBException(e); } finally { try { if (pstm != null) { pstm.close(); } } catch (Exception e) {} try { if (con != null) { con.close(); } } catch (Exception e) {} } } /** * PostGIS implementation of the * {@link com.geodetix.geo.interfaces.GeometryLocalHome#dropDbTable()} * method removing the table related to the EJBs. */ public void dropDbTable() { PreparedStatement pstm = null; Connection con = null; try { con = this.dataSource.getConnection(); System.out.println("Dropping Bean Table... "); pstm = con.prepareStatement(PostGisGeometryDAO.DROP_TABLE_STATEMENT); pstm.execute(); System.out.println("...done!"); } catch (SQLException e) { throw new EJBException(e); } finally { try { if (pstm != null) { pstm.close(); } } catch (Exception e) {} try { if (con != null) { con.close(); } } catch (Exception e) {} } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -