mirror of
https://github.com/svek95/WST_Labs.git
synced 2026-05-17 18:44:02 +03:00
add gitignore
This commit is contained in:
+31
-19
@@ -4,17 +4,17 @@ import java.util.Date;
|
||||
|
||||
public class Car {
|
||||
private String name;
|
||||
private Date dateOfStart;
|
||||
private Date dateOfSales;
|
||||
private String country;
|
||||
private double duration;
|
||||
private String director;
|
||||
private double power;
|
||||
private String model;
|
||||
|
||||
public Car(String name, Date date, String country, double duration, String director) {
|
||||
public Car(String name, Date date, String country, double power, String model) {
|
||||
this.name = name;
|
||||
this.dateOfStart = date;
|
||||
this.dateOfSales = date;
|
||||
this.country = country;
|
||||
this.duration = duration;
|
||||
this.director = director;
|
||||
this.power = power;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -25,12 +25,12 @@ public class Car {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Date getDateOfStart() {
|
||||
return dateOfStart;
|
||||
public Date getdateOfSales() {
|
||||
return dateOfSales;
|
||||
}
|
||||
|
||||
public void setDateOfStart(Date dateOfStart) {
|
||||
this.dateOfStart = dateOfStart;
|
||||
public void setdateOfSales(Date dateOfSales) {
|
||||
this.dateOfSales = dateOfSales;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
@@ -41,19 +41,31 @@ public class Car {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public double getDuration() {
|
||||
return duration;
|
||||
public double getpower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public void setDuration(double duration) {
|
||||
this.duration = duration;
|
||||
public void setpower(double power) {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
public String getDirector() {
|
||||
return director;
|
||||
public String getmodel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setDirector(String director) {
|
||||
this.director = director;
|
||||
public void setmodel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Car{" + "name=" + name +
|
||||
", model=" + model +
|
||||
", dateOfSales=" + dateOfSales +
|
||||
", country=" + country +
|
||||
", power=" + power +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.logging.Logger;
|
||||
|
||||
public abstract class CarDAO {
|
||||
|
||||
private Boolean addChecking(Object value, String fieldName, Boolean isNotFirst, StringBuilder query) {
|
||||
private Boolean CheckIN(Object value, String fieldName, Boolean isNotFirst, StringBuilder query) {
|
||||
if (value != null) {
|
||||
if (isNotFirst) {
|
||||
query.append(" and ");
|
||||
@@ -27,39 +27,39 @@ public abstract class CarDAO {
|
||||
|
||||
public abstract Connection getConnection();
|
||||
|
||||
public List<Car> getDataByFields(String name, String director, String country, Date dateOfStart, Double duration) {
|
||||
public List<Car> getDataByFields(String name, String model, String country, String dateOfSales, int power) {
|
||||
List<Car> cars = Collections.emptyList();
|
||||
try (Connection connection = getConnection()) {
|
||||
StringBuilder query = new StringBuilder("select * from cars");
|
||||
boolean notFirstField = false;
|
||||
if (name != null || director != null || country != null && dateOfStart != null || duration != null) {
|
||||
if (name != null || model != null || country != null && dateOfSales != null || power != 0) {
|
||||
query.append(" where ");
|
||||
}
|
||||
notFirstField = addChecking(name, "name", notFirstField, query);
|
||||
notFirstField = addChecking(director, "director", notFirstField, query);
|
||||
notFirstField = addChecking(country, "country", notFirstField, query);
|
||||
notFirstField = addChecking(dateOfStart, "dateOfStart", notFirstField, query);
|
||||
addChecking(duration, "duration", notFirstField, query);
|
||||
notFirstField = CheckIN(name, "name", notFirstField, query);
|
||||
notFirstField = CheckIN(model, "model", notFirstField, query);
|
||||
notFirstField = CheckIN(country, "country", notFirstField, query);
|
||||
notFirstField = CheckIN(dateOfSales, "dateOfSales", notFirstField, query);
|
||||
CheckIN(power, "power", notFirstField, query);
|
||||
|
||||
PreparedStatement stmt = connection.prepareStatement(query.toString());
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
cars = extractFilmsFromResultSet(rs);
|
||||
cars = extractCarsFromResult(rs);
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(CarDAO.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return cars;
|
||||
}
|
||||
|
||||
private List<Car> extractFilmsFromResultSet(ResultSet rs) throws SQLException{
|
||||
private List<Car> extractCarsFromResult(ResultSet rs) throws SQLException{
|
||||
List<Car> cars = new ArrayList<Car>();
|
||||
while (rs.next()) {
|
||||
String name = rs.getString("name");
|
||||
Date date = rs.getDate("dateOfStart");
|
||||
String director = rs.getString("director");
|
||||
Date date = rs.getDate("dateOfSales");
|
||||
String model = rs.getString("model");
|
||||
String country = rs.getString("country");
|
||||
double duration = rs.getDouble("duration");
|
||||
double power = rs.getDouble("power");
|
||||
|
||||
Car car = new Car(name, date, country, duration, director);
|
||||
Car car = new Car(name, date, country, power, model);
|
||||
cars.add(car);
|
||||
} return cars;
|
||||
}
|
||||
|
||||
@@ -3,20 +3,46 @@ package Lab1;
|
||||
import javax.jws.WebMethod;
|
||||
import javax.jws.WebParam;
|
||||
import javax.jws.WebService;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@WebService(name = "FilmService")
|
||||
@WebService(name = "CarService")
|
||||
public class CarWebService {
|
||||
|
||||
private final static CarDAO filmDao = new StandaloneCarDAO();
|
||||
private final static CarDAO carDao = new StandaloneCarDAO();
|
||||
|
||||
@WebMethod
|
||||
public List<Car> getFilmsByFields(@WebParam(name = "filmName") String name,
|
||||
@WebParam(name = "director") String director,
|
||||
@WebMethod(operationName = "getCars")
|
||||
public List<Car> getCars(@WebParam(name = "CarBrand") String name,
|
||||
@WebParam(name = "model") String model,
|
||||
@WebParam(name = "country") String country,
|
||||
@WebParam(name = "dateOfStart") Date date,
|
||||
@WebParam(name = "duration") Double duration) {
|
||||
return filmDao.getDataByFields(name, director, country, date, duration);
|
||||
@WebParam(name = "dateOfSales") String date,
|
||||
@WebParam(name = "power") int power) {
|
||||
return carDao.getDataByFields(name, model, country, date, power);
|
||||
}
|
||||
|
||||
@WebMethod(operationName = "searchCars")
|
||||
public List<Car> searchCars(String term) {
|
||||
CarDAO dao = new StandaloneCarDAO();
|
||||
String name = "", model = "", country = "", date = "";
|
||||
int power = -1;
|
||||
for (String arg : term.split(";")) {
|
||||
if (arg.split("=")[0].equals("CarBrand")) {
|
||||
name = arg.split("=")[1];
|
||||
}
|
||||
if (arg.split("=")[0].equals("model")) {
|
||||
model = arg.split("=")[1];
|
||||
}
|
||||
if (arg.split("=")[0].equals("country")) {
|
||||
country = arg.split("=")[1];
|
||||
}
|
||||
if (arg.split("=")[0].equals("dateOfSales")) {
|
||||
date = arg.split("=")[1];
|
||||
}
|
||||
if (arg.split("=")[0].equals("power")) {
|
||||
power = Integer.parseInt(arg.split("=")[1]);
|
||||
}
|
||||
}
|
||||
List<Car> cars = dao.getDataByFields(name, model, country, date, power);
|
||||
|
||||
return cars;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user