/** {@inheritDoc} */ public <T> void createProperty(Property<T> ap) { Util.assertNotNull(ap); Connection sqlConn = null; PreparedStatement ps = null; try { sqlConn = getDataSource().getConnection(); if (existProperty(ap.getName())) { throw new PropertyAlreadyExistException(ap.getName()); } ps = sqlConn.prepareStatement(getQueryBuilder().createProperty()); ps.setString(1, ap.getName()); ps.setString(2, ap.getType()); ps.setString(3, ap.asString()); ps.setString(4, ap.getDescription()); if (ap.getFixedValues() != null && !ap.getFixedValues().isEmpty()) { String fixedValues = ap.getFixedValues().toString(); ps.setString(5, fixedValues.substring(1, fixedValues.length() - 1)); } else { ps.setString(5, null); } ps.executeUpdate(); } catch (SQLException sqlEX) { throw new PropertyAccessException("Cannot update properties database, SQL ERROR", sqlEX); } finally { // Connection is closed alse here within clos statement closeStatement(ps); closeConnection(sqlConn); } }
/** {@inheritDoc} */ public void deleteProperty(String name) { Util.assertHasLength(name); Connection sqlConn = null; PreparedStatement ps = null; try { sqlConn = getDataSource().getConnection(); if (!existProperty(name)) { throw new PropertyNotFoundException(name); } ps = buildStatement(sqlConn, getQueryBuilder().deleteProperty(), name); ps.executeUpdate(); } catch (SQLException sqlEX) { throw new PropertyAccessException("Cannot delete property database, SQL ERROR", sqlEX); } finally { closeStatement(ps); closeConnection(sqlConn); } }
/** {@inheritDoc} */ public Property<?> readProperty(String name) { Util.assertHasLength(name); Connection sqlConn = null; PreparedStatement ps = null; ResultSet rs = null; try { sqlConn = getDataSource().getConnection(); if (!existProperty(name)) { throw new PropertyNotFoundException(name); } // Returns features ps = buildStatement(sqlConn, getQueryBuilder().getProperty(), name); rs = ps.executeQuery(); rs.next(); return JDBC_MAPPER.map(rs); } catch (SQLException sqlEX) { throw new PropertyAccessException("Cannot check property existence, error related to database", sqlEX); } finally { closeResultSet(rs); closeStatement(ps); closeConnection(sqlConn); } }