📄 pointbasecatalogdao.java
字号:
ArrayList activities = new ArrayList(); // Getting the activites stmt2 = dbConnection.prepareStatement(SELECT_ACTIVITYLIST_QUERY_STR); stmt2.setString(1, packageId); stmt2.setString(2, locale.toString().trim()); result2 = stmt2.executeQuery(); while (result2.next()) { String activityId = result2.getString(1).trim(); activities.add(activityId); } AdventurePackage ap = new AdventurePackage(packageId, name, description, location, lodgingId, price, activities); return(ap); } catch(SQLException se) { throw new DAOSystemException("SQLException while getting " + "AdventurePackage details; origin = " + packageId +", and locale = "+locale.toString()+" \n", se); } finally { DAOUtils.closeResultSet(result); DAOUtils.closeStatement(stmt); DAOUtils.closeResultSet(result2); DAOUtils.closeStatement(stmt2); DAOUtils.closeConnection(dbConnection); } } public ArrayList getTransportations(String origin, String destination, Locale locale) throws CatalogDAOException, DAOSystemException { PreparedStatement stmt = null; ResultSet result = null; Connection dbConnection = null; ArrayList transportations = new ArrayList(); try { dbConnection = DAOUtils.getDBConnection(JNDINames.CATALOG_DATASOURCE); stmt = dbConnection.prepareStatement(SELECT_TRANSPORTATIONS_QUERY_STR); stmt.setString(1, origin.trim()); stmt.setString(2, destination.trim()); stmt.setString(3, locale.toString().trim()); result = stmt.executeQuery(); if ( !result.next() ) throw new CatalogDAOException( "No data found for " + origin +" , "+ destination +" , "+locale.toString()); do { int i = 1; String transportId = result.getString(i++); String name = result.getString(i++); String description = result.getString(i++); String imageURI = result.getString(i++); double price = result.getDouble(i++); origin = result.getString(i++); destination = result.getString(i++); String carrier = result.getString(i++); String departureTime = result.getString(i++); String arrivalTime = result.getString(i++); String travelClass = result.getString(i++); transportations.add(new Transportation(transportId , name, description, imageURI, price,origin,destination,carrier,departureTime,arrivalTime,travelClass)); } while(result.next()); return(transportations); } catch(SQLException se) { throw new DAOSystemException("SQLException while getting " + "Transportation details; origin = " + origin +" , "+"destination = "+destination+" and locale = "+locale.toString()+" \n", se); } finally { DAOUtils.closeResultSet(result); DAOUtils.closeStatement(stmt); DAOUtils.closeConnection(dbConnection); } } public Transportation getTransportation(String id, Locale locale) throws CatalogDAOException, DAOSystemException { PreparedStatement stmt = null; ResultSet result = null; Connection dbConnection = null; try { dbConnection = DAOUtils.getDBConnection(JNDINames.CATALOG_DATASOURCE); stmt = dbConnection.prepareStatement(SELECT_TRANSPORTATION_QUERY_STR); stmt.setString(1, id.trim()); stmt.setString(2, locale.toString().trim()); result = stmt.executeQuery(); if ( !result.next() ) throw new CatalogDAOException( "No data found for " + id +" , "+locale.toString()); int i = 1; String transportId = result.getString(i++); String name = result.getString(i++); String description = result.getString(i++); String imageURI = result.getString(i++); double price = result.getDouble(i++); String origin = result.getString(i++); String destination = result.getString(i++); String carrier = result.getString(i++); String departureTime = result.getString(i++); String arrivalTime = result.getString(i++); String travelClass = result.getString(i++); return new Transportation(transportId , name, description, imageURI, price, origin, destination, carrier, departureTime, arrivalTime, travelClass); } catch(SQLException se) { throw new DAOSystemException("SQLException while getting " + "Transportation details; id = " + id +" and locale = "+locale.toString()+" \n", se); } finally { DAOUtils.closeResultSet(result); DAOUtils.closeStatement(stmt); DAOUtils.closeConnection(dbConnection); } } public ArrayList getActivities(String location, Locale locale) throws CatalogDAOException, DAOSystemException { PreparedStatement stmt = null; ResultSet result = null; Connection dbConnection = null; ArrayList activities = new ArrayList(); try { dbConnection = DAOUtils.getDBConnection(JNDINames.CATALOG_DATASOURCE); stmt = dbConnection.prepareStatement(SELECT_ACTIVITIES_QUERY_STR); stmt.setString(1, location.trim()); stmt.setString(2, locale.toString().trim()); result = stmt.executeQuery(); if ( !result.next() ) throw new CatalogDAOException( "No data dound for " + location +" , "+locale.toString()); do { int i = 1; String activityId = result.getString(i++); String name = result.getString(i++); String description = result.getString(i++); double price = result.getDouble(i++); location = result.getString(i++); activities.add(new Activity(activityId , name, description, price,location)); } while(result.next()); return(activities); } catch(SQLException se) { throw new DAOSystemException("SQLException while getting " + "Activity details; location = " + location +" and locale = "+locale.toString()+" \n", se); } finally { DAOUtils.closeResultSet(result); DAOUtils.closeStatement(stmt); DAOUtils.closeConnection(dbConnection); } } public Activity getActivity(String id, Locale locale) throws CatalogDAOException, DAOSystemException { PreparedStatement stmt = null; ResultSet result = null; Connection dbConnection = null; try { dbConnection = DAOUtils.getDBConnection(JNDINames.CATALOG_DATASOURCE); stmt = dbConnection.prepareStatement(SELECT_ACTIVITY_QUERY_STR); stmt.setString(1, id.trim()); stmt.setString(2, locale.toString().trim()); result = stmt.executeQuery(); if ( !result.next() ) throw new CatalogDAOException( "No data dound for " + id +" , "+locale.toString()); int i = 1; String activityId = result.getString(i++); String name = result.getString(i++); String description = result.getString(i++); double price = result.getDouble(i++); String location = result.getString(i++); return new Activity(activityId , name, description, price,location); } catch(SQLException se) { throw new DAOSystemException("SQLException while getting " + "Activity details; id = " + id +" and locale = "+locale.toString()+" \n", se); } finally { DAOUtils.closeResultSet(result); DAOUtils.closeStatement(stmt); DAOUtils.closeConnection(dbConnection); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -