add gitignore

This commit is contained in:
2019-02-26 15:22:09 +03:00
parent 1b7aaf3635
commit 67ac4941e6
3 changed files with 80 additions and 42 deletions
+31 -19
View File
@@ -4,17 +4,17 @@ import java.util.Date;
public class Car { public class Car {
private String name; private String name;
private Date dateOfStart; private Date dateOfSales;
private String country; private String country;
private double duration; private double power;
private String director; 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.name = name;
this.dateOfStart = date; this.dateOfSales = date;
this.country = country; this.country = country;
this.duration = duration; this.power = power;
this.director = director; this.model = model;
} }
public String getName() { public String getName() {
@@ -25,12 +25,12 @@ public class Car {
this.name = name; this.name = name;
} }
public Date getDateOfStart() { public Date getdateOfSales() {
return dateOfStart; return dateOfSales;
} }
public void setDateOfStart(Date dateOfStart) { public void setdateOfSales(Date dateOfSales) {
this.dateOfStart = dateOfStart; this.dateOfSales = dateOfSales;
} }
public String getCountry() { public String getCountry() {
@@ -41,19 +41,31 @@ public class Car {
this.country = country; this.country = country;
} }
public double getDuration() { public double getpower() {
return duration; return power;
} }
public void setDuration(double duration) { public void setpower(double power) {
this.duration = duration; this.power = power;
} }
public String getDirector() { public String getmodel() {
return director; return model;
} }
public void setDirector(String director) { public void setmodel(String model) {
this.director = director; this.model = model;
} }
@Override
public String toString() {
return "Car{" + "name=" + name +
", model=" + model +
", dateOfSales=" + dateOfSales +
", country=" + country +
", power=" + power +
'}';
}
} }
+14 -14
View File
@@ -8,7 +8,7 @@ import java.util.logging.Logger;
public abstract class CarDAO { 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 (value != null) {
if (isNotFirst) { if (isNotFirst) {
query.append(" and "); query.append(" and ");
@@ -27,39 +27,39 @@ public abstract class CarDAO {
public abstract Connection getConnection(); 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(); List<Car> cars = Collections.emptyList();
try (Connection connection = getConnection()) { try (Connection connection = getConnection()) {
StringBuilder query = new StringBuilder("select * from cars"); StringBuilder query = new StringBuilder("select * from cars");
boolean notFirstField = false; 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 "); query.append(" where ");
} }
notFirstField = addChecking(name, "name", notFirstField, query); notFirstField = CheckIN(name, "name", notFirstField, query);
notFirstField = addChecking(director, "director", notFirstField, query); notFirstField = CheckIN(model, "model", notFirstField, query);
notFirstField = addChecking(country, "country", notFirstField, query); notFirstField = CheckIN(country, "country", notFirstField, query);
notFirstField = addChecking(dateOfStart, "dateOfStart", notFirstField, query); notFirstField = CheckIN(dateOfSales, "dateOfSales", notFirstField, query);
addChecking(duration, "duration", notFirstField, query); CheckIN(power, "power", notFirstField, query);
PreparedStatement stmt = connection.prepareStatement(query.toString()); PreparedStatement stmt = connection.prepareStatement(query.toString());
ResultSet rs = stmt.executeQuery(); ResultSet rs = stmt.executeQuery();
cars = extractFilmsFromResultSet(rs); cars = extractCarsFromResult(rs);
} catch (SQLException ex) { } catch (SQLException ex) {
Logger.getLogger(CarDAO.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(CarDAO.class.getName()).log(Level.SEVERE, null, ex);
} }
return cars; return cars;
} }
private List<Car> extractFilmsFromResultSet(ResultSet rs) throws SQLException{ private List<Car> extractCarsFromResult(ResultSet rs) throws SQLException{
List<Car> cars = new ArrayList<Car>(); List<Car> cars = new ArrayList<Car>();
while (rs.next()) { while (rs.next()) {
String name = rs.getString("name"); String name = rs.getString("name");
Date date = rs.getDate("dateOfStart"); Date date = rs.getDate("dateOfSales");
String director = rs.getString("director"); String model = rs.getString("model");
String country = rs.getString("country"); 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); cars.add(car);
} return cars; } return cars;
} }
+35 -9
View File
@@ -3,20 +3,46 @@ package Lab1;
import javax.jws.WebMethod; import javax.jws.WebMethod;
import javax.jws.WebParam; import javax.jws.WebParam;
import javax.jws.WebService; import javax.jws.WebService;
import java.util.Date;
import java.util.List; import java.util.List;
@WebService(name = "FilmService") @WebService(name = "CarService")
public class CarWebService { public class CarWebService {
private final static CarDAO filmDao = new StandaloneCarDAO(); private final static CarDAO carDao = new StandaloneCarDAO();
@WebMethod @WebMethod(operationName = "getCars")
public List<Car> getFilmsByFields(@WebParam(name = "filmName") String name, public List<Car> getCars(@WebParam(name = "CarBrand") String name,
@WebParam(name = "director") String director, @WebParam(name = "model") String model,
@WebParam(name = "country") String country, @WebParam(name = "country") String country,
@WebParam(name = "dateOfStart") Date date, @WebParam(name = "dateOfSales") String date,
@WebParam(name = "duration") Double duration) { @WebParam(name = "power") int power) {
return filmDao.getDataByFields(name, director, country, date, duration); 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;
} }
} }