private List<StrasseDTO> findStreetsByPoint( Long startPunktId, boolean isMautAllowed, String query) throws SQLException { List<StrasseDTO> retVal = new ArrayList<StrasseDTO>(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; Connection connection = daoFactory.getConnection(); if (isMautAllowed) { preparedStatement = DaoUtil.prepareStatement(connection, query, false, new Object[] {startPunktId}); } else { preparedStatement = DaoUtil.prepareStatement( connection, query + " AND Toll=?", false, new Object[] {startPunktId, 0}); } resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { StrasseDTO s = new StrasseDTO(); s.setStartPunktId(resultSet.getLong("StartPoint")); s.setEndPunktId(resultSet.getLong("EndPoint")); s.setDistanz(resultSet.getLong("Distance")); s.setSpeed(resultSet.getInt("Speed")); s.setMaut(resultSet.getBoolean("Toll")); retVal.add(s); } return retVal; }
@Override public void deletePoint(OrtDTO dto) throws SQLException { PreparedStatement preparedStatement = null; Connection connection = daoFactory.getConnection(); preparedStatement = DaoUtil.prepareStatement( connection, DELETEPOINTBYID, false, new Object[] {dto.getPointId()}); preparedStatement.executeUpdate(); }
@Override public void deleteStrasse(StrasseDTO dto) throws SQLException { PreparedStatement preparedStatement = null; Connection connection = daoFactory.getConnection(); preparedStatement = DaoUtil.prepareStatement( connection, DELETESTREET, false, new Object[] {dto.getStartPunktId(), dto.getEndPunktId()}); preparedStatement.executeUpdate(); }
@Override public OrtDTO createPoint(OrtDTO dto) throws SQLException { PreparedStatement preparedStatement = null; Connection connection = daoFactory.getConnection(); preparedStatement = DaoUtil.prepareStatement( connection, CREATEPOINT, false, new Object[] {dto.getPointX(), dto.getPointY(), dto.getDescription()}); preparedStatement.executeUpdate(); return findPointByAxis(dto.getPointX(), dto.getPointY()); }
@Override public Map<Integer, StrasseComponentDTO> deleteStreetsByPointId(Long pointId) throws SQLException { Map<Integer, StrasseComponentDTO> deletedMap = findStreets( ALLSTREETSTODISPLAY + "WHERE Startpoint=? OR Endpoint=?", new Object[] {pointId, pointId}); Connection connection = daoFactory.getConnection(); PreparedStatement preparedStatement = DaoUtil.prepareStatement( connection, DELETESTREETBYPOINT, false, new Object[] {pointId, pointId}); preparedStatement.executeUpdate(); return deletedMap; }
@Override public Long findPointIdByName(String name) throws SQLException { PreparedStatement preparedStatement = null; Connection connection = daoFactory.getConnection(); preparedStatement = DaoUtil.prepareStatement(connection, FINDPOINTBYNAME, false, new Object[] {name}); ResultSet rs = preparedStatement.executeQuery(); Long retVal = null; while (rs.next()) { retVal = rs.getLong("id"); } return retVal; }
@Override public OrtDTO findPointByAxis(int punktX, int punktY) throws SQLException { OrtDTO ort = new OrtDTO(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; Connection connection = daoFactory.getConnection(); preparedStatement = DaoUtil.prepareStatement(connection, FINDPOINTBYAXIS, false, new Object[] {punktX, punktY}); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { ort.setPointId(resultSet.getLong("id")); ort.setPointX(resultSet.getInt("xAxis")); ort.setPointY(resultSet.getInt("yAxis")); ort.setDescription(resultSet.getString("name")); } return ort; }
@Override public List<OrtDTO> findAllPoints() throws SQLException { List<OrtDTO> retVal = new ArrayList<OrtDTO>(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; Connection connection = daoFactory.getConnection(); preparedStatement = DaoUtil.prepareStatement(connection, FINDALLPOINTS, false, new Object[0]); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { OrtDTO ort = new OrtDTO(); ort.setPointId(resultSet.getLong("id")); ort.setPointX(resultSet.getInt("xAxis")); ort.setPointY(resultSet.getInt("yAxis")); ort.setDescription(resultSet.getString("name")); retVal.add(ort); } return retVal; }
private Map<Integer, StrasseComponentDTO> findStreets(String query, Object[] args) throws SQLException { Connection connection = daoFactory.getConnection(); PreparedStatement preparedStatement = DaoUtil.prepareStatement(connection, query, false, args); ResultSet resultSet = preparedStatement.executeQuery(); Map<Integer, StrasseComponentDTO> map = new HashMap<Integer, StrasseComponentDTO>(); while (resultSet.next()) { StrasseComponentDTO s = new StrasseComponentDTO(); s.setStartId(resultSet.getLong("StartId")); s.setEndId(resultSet.getLong("EndId")); s.setxStart(resultSet.getInt("startX")); s.setyStart(resultSet.getInt("startY")); s.setxEnd(resultSet.getInt("endX")); s.setyEnd(resultSet.getInt("endY")); s.setDistanz(resultSet.getDouble("Distance")); s.setSpeed(resultSet.getInt("Speed")); s.setMaut(resultSet.getBoolean("Toll")); map.put(s.hashCode(), s); } return map; }