mirror of
https://github.com/svek95/WST_Labs.git
synced 2026-05-18 02:51:45 +03:00
Initial commit
This commit is contained in:
Generated
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="WST" />
|
||||
<module name="WST_Lab1" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||
</project>
|
||||
Generated
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.7" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+127
@@ -0,0 +1,127 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
<component name="uidesigner-configuration">
|
||||
<option name="INSTRUMENT_CLASSES" value="false" />
|
||||
</component>
|
||||
</project>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
create table cars (
|
||||
brand varchar(100) primary key,
|
||||
model varchar(100),
|
||||
dateOfSales date,
|
||||
country varchar(50),
|
||||
power numeric
|
||||
)
|
||||
|
||||
insert into cars values('Dodge', 'RAM', to_date('27-09-2019', 'DD-MM-yyyy'), 'USA', 395);
|
||||
insert into cars values('LADA', 'XRay', to_date('18-04-2018', 'DD-MM-yyyy'), 'Russia', 122);
|
||||
insert into cars values('Nissan', 'Pathfinder', to_date('01-06-2010', 'DD-MM-yyyy'), 'Japan', 170);
|
||||
insert into cars values('Cadillac', 'Escalade', to_date('21-03-2005', 'DD-MM-yyyy'), 'USA', 362);
|
||||
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4" />
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>WST</groupId>
|
||||
<artifactId>WST</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.2.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>7</source>
|
||||
<target>7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
<configuration>
|
||||
<packagingExcludes>WEB-INF/classes/**</packagingExcludes>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
|
||||
import Lab1.CarWebService;
|
||||
|
||||
import javax.xml.ws.Endpoint;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
String url = "http://localhost:8081/CarService";
|
||||
Endpoint.publish(url, new CarWebService());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package Lab1;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Car {
|
||||
private String name;
|
||||
private Date dateOfStart;
|
||||
private String country;
|
||||
private double duration;
|
||||
private String director;
|
||||
|
||||
public Car(String name, Date date, String country, double duration, String director) {
|
||||
this.name = name;
|
||||
this.dateOfStart = date;
|
||||
this.country = country;
|
||||
this.duration = duration;
|
||||
this.director = director;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Date getDateOfStart() {
|
||||
return dateOfStart;
|
||||
}
|
||||
|
||||
public void setDateOfStart(Date dateOfStart) {
|
||||
this.dateOfStart = dateOfStart;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public double getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(double duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public String getDirector() {
|
||||
return director;
|
||||
}
|
||||
|
||||
public void setDirector(String director) {
|
||||
this.director = director;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package Lab1;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class CarDAO {
|
||||
|
||||
private Boolean addChecking(Object value, String fieldName, Boolean isNotFirst, StringBuilder query) {
|
||||
if (value != null) {
|
||||
if (isNotFirst) {
|
||||
query.append(" and ");
|
||||
}
|
||||
if (value instanceof String) {
|
||||
query.append(fieldName).append(" = '").append(value).append("'");
|
||||
} else {
|
||||
query.append(fieldName).append(" = ").append(value);
|
||||
}
|
||||
if (!isNotFirst) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return isNotFirst;
|
||||
}
|
||||
|
||||
public abstract Connection getConnection();
|
||||
|
||||
public List<Car> getDataByFields(String name, String director, String country, Date dateOfStart, Double duration) {
|
||||
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) {
|
||||
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);
|
||||
|
||||
PreparedStatement stmt = connection.prepareStatement(query.toString());
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
cars = extractFilmsFromResultSet(rs);
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(CarDAO.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return cars;
|
||||
}
|
||||
|
||||
private List<Car> extractFilmsFromResultSet(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");
|
||||
String country = rs.getString("country");
|
||||
double duration = rs.getDouble("duration");
|
||||
|
||||
Car car = new Car(name, date, country, duration, director);
|
||||
cars.add(car);
|
||||
} return cars;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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")
|
||||
public class CarWebService {
|
||||
|
||||
private final static CarDAO filmDao = new StandaloneCarDAO();
|
||||
|
||||
@WebMethod
|
||||
public List<Car> getFilmsByFields(@WebParam(name = "filmName") String name,
|
||||
@WebParam(name = "director") String director,
|
||||
@WebParam(name = "country") String country,
|
||||
@WebParam(name = "dateOfStart") Date date,
|
||||
@WebParam(name = "duration") Double duration) {
|
||||
return filmDao.getDataByFields(name, director, country, date, duration);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package Lab1;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ConnectionUtil {
|
||||
private static final String JDBC_URL = "jdbc:postgresql://192.168.1.119:5432/";
|
||||
private static final String JDBC_USER = "postgres";
|
||||
private static final String JDBC_PASSWORD = "qwerty";
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("org.postgresql.Driver");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
Logger.getLogger(CarDAO.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
public static Connection getConnection() {
|
||||
Connection connection = null;
|
||||
try {
|
||||
connection = DriverManager.getConnection(JDBC_URL, JDBC_USER,
|
||||
JDBC_PASSWORD);
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(ConnectionUtil.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package Lab1;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
public class StandaloneCarDAO extends CarDAO {
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return ConnectionUtil.getConnection();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user