public static WheelsBCD createEntity(ResultSet resultSet) throws SQLException { WheelsBCD entity = new WheelsBCD(); Integer id = resultSet.getInt(ID_COLUMN); String value = resultSet.getString(VALUE_COLUMN); entity.setId(id); entity.setValue(value); return entity; }
public Integer add(WheelsBCD entity) { Integer generatedId = null; ResultSet resultSet = null; Connection connection = null; PreparedStatement preparedStatement = null; if (checkEntity(entity)) { try { connection = connectionPool.getConnection(); preparedStatement = (PreparedStatement) connection.prepareStatement(addRequest, PreparedStatement.RETURN_GENERATED_KEYS); preparedStatement.setString(1, entity.getValue()); preparedStatement.execute(); resultSet = preparedStatement.getGeneratedKeys(); if (resultSet.next()) { generatedId = resultSet.getInt(1); } } catch (SQLException ex) { generatedId = null; } finally { closeAll(resultSet, preparedStatement, connection); } } return generatedId; }
private boolean checkEntity(WheelsBCD entity) { boolean checked = true; if (entity == null || entity.getValue() == null) { checked = false; } return checked; }