same
This commit is contained in:
parent
8e6d912eea
commit
0e4b1a9fe5
8 changed files with 99 additions and 22 deletions
|
@ -4,6 +4,7 @@
|
||||||
<data-source source="LOCAL" name="helios postgres" uuid="1d89802b-1b14-4f1f-bdf1-c835d25f1fd2">
|
<data-source source="LOCAL" name="helios postgres" uuid="1d89802b-1b14-4f1f-bdf1-c835d25f1fd2">
|
||||||
<driver-ref>postgresql</driver-ref>
|
<driver-ref>postgresql</driver-ref>
|
||||||
<synchronize>true</synchronize>
|
<synchronize>true</synchronize>
|
||||||
|
<configured-by-url>true</configured-by-url>
|
||||||
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
|
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
|
||||||
<jdbc-url>jdbc:postgresql://pg:5432/studs</jdbc-url>
|
<jdbc-url>jdbc:postgresql://pg:5432/studs</jdbc-url>
|
||||||
<working-dir>$ProjectFileDir$</working-dir>
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
|
|
@ -22,10 +22,11 @@ tasks.withType(JavaCompile) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly('javax.persistence:javax.persistence-api:2.2')
|
compileOnly 'javax.persistence:javax.persistence-api:2.2'
|
||||||
compileOnly('javax.faces:javax.faces-api:2.3')
|
compileOnly 'javax.enterprise:cdi-api:2.0.SP1'
|
||||||
compileOnly('javax.enterprise:cdi-api:2.0.SP1')
|
compileOnly 'javax.faces:javax.faces-api:2.3-pfd'
|
||||||
compileOnly('org.primefaces:primefaces:11.0.0')
|
compileOnly 'org.postgresql:postgresql:42.5.4'
|
||||||
|
compileOnly 'org.hibernate:hibernate-core:6.1.7.Final'
|
||||||
|
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
|
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
|
||||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
|
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
|
||||||
|
|
|
@ -1,12 +1,27 @@
|
||||||
package ru.erius.weblab3.data;
|
package ru.erius.weblab3.data;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Entity(name = "hit_info")
|
||||||
|
@Table(name = "hit_info", schema = "s316304")
|
||||||
|
@NamedQueries({
|
||||||
|
@NamedQuery(name = "load", query = "select h from hit_info h"),
|
||||||
|
@NamedQuery(name = "clear", query = "delete from hit_info")
|
||||||
|
})
|
||||||
public class HitInfo implements Serializable {
|
public class HitInfo implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id")
|
||||||
|
private long id;
|
||||||
|
@Column(name = "x")
|
||||||
private float x;
|
private float x;
|
||||||
|
@Column(name = "y")
|
||||||
private float y;
|
private float y;
|
||||||
|
@Column(name = "r")
|
||||||
private float r = 1;
|
private float r = 1;
|
||||||
|
@Column(name = "hit")
|
||||||
private boolean hit;
|
private boolean hit;
|
||||||
|
|
||||||
public HitInfo() {
|
public HitInfo() {
|
||||||
|
@ -57,4 +72,12 @@ public class HitInfo implements Serializable {
|
||||||
public void setHit(boolean hit) {
|
public void setHit(boolean hit) {
|
||||||
this.hit = hit;
|
this.hit = hit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ru.erius.weblab3.data;
|
||||||
|
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
import javax.enterprise.inject.Model;
|
import javax.enterprise.inject.Model;
|
||||||
|
import javax.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -9,24 +10,63 @@ import java.util.List;
|
||||||
@Model
|
@Model
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class HitInfoBean implements Serializable {
|
public class HitInfoBean implements Serializable {
|
||||||
|
private final EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("hit-info-unit");
|
||||||
private List<HitInfo> hitInfos = new ArrayList<>();
|
private List<HitInfo> hitInfos = new ArrayList<>();
|
||||||
private HitInfo latest = new HitInfo();
|
private HitInfo latest = new HitInfo();
|
||||||
private HitInfo plotLatest = new HitInfo();
|
private HitInfo plotLatest = new HitInfo();
|
||||||
|
|
||||||
public void plotAdd() {
|
public HitInfoBean() {
|
||||||
plotLatest.hitCheck();
|
load();
|
||||||
HitInfo toAdd = new HitInfo(plotLatest.getX(), plotLatest.getY(), plotLatest.getR(), plotLatest.isHit());
|
|
||||||
hitInfos.add(toAdd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add() {
|
public void plotAdd() {
|
||||||
|
plotLatest.hitCheck();
|
||||||
|
HitInfo hitInfo = new HitInfo(plotLatest.getX(), plotLatest.getY(), plotLatest.getR(), plotLatest.isHit());
|
||||||
|
add(hitInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void btnAdd() {
|
||||||
latest.hitCheck();
|
latest.hitCheck();
|
||||||
HitInfo toAdd = new HitInfo(latest.getX(), latest.getY(), latest.getR(), latest.isHit());
|
HitInfo hitInfo = new HitInfo(latest.getX(), latest.getY(), latest.getR(), latest.isHit());
|
||||||
hitInfos.add(toAdd);
|
add(hitInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void add(HitInfo hitInfo) {
|
||||||
|
hitInfos.add(hitInfo);
|
||||||
|
EntityManager entityManager = entityManagerFactory.createEntityManager();
|
||||||
|
try {
|
||||||
|
entityManager.getTransaction().begin();
|
||||||
|
entityManager.persist(hitInfo);
|
||||||
|
entityManager.getTransaction().commit();
|
||||||
|
} finally {
|
||||||
|
entityManager.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load() {
|
||||||
|
EntityManager entityManager = entityManagerFactory.createEntityManager();
|
||||||
|
try {
|
||||||
|
entityManager.getTransaction().begin();
|
||||||
|
|
||||||
|
TypedQuery<HitInfo> loadAllQuery = entityManager.createNamedQuery("load", HitInfo.class);
|
||||||
|
hitInfos = loadAllQuery.getResultList();
|
||||||
|
entityManager.getTransaction().commit();
|
||||||
|
} finally {
|
||||||
|
entityManager.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
hitInfos.clear();
|
hitInfos.clear();
|
||||||
|
EntityManager entityManager = entityManagerFactory.createEntityManager();
|
||||||
|
try {
|
||||||
|
entityManager.getTransaction().begin();
|
||||||
|
Query clearAllQuery = entityManager.createNamedQuery("clear");
|
||||||
|
clearAllQuery.executeUpdate();
|
||||||
|
entityManager.getTransaction().commit();
|
||||||
|
} finally {
|
||||||
|
entityManager.close();
|
||||||
|
}
|
||||||
latest = new HitInfo();
|
latest = new HitInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
|
||||||
version="3.0">
|
version="3.0">
|
||||||
<persistence-unit name="default">
|
<persistence-unit name="hit-info-unit" transaction-type="JTA">
|
||||||
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
|
<jta-data-source>java:/PostgresDS</jta-data-source>
|
||||||
|
<class>ru.erius.weblab3.data.HitInfo</class>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
</persistence>
|
</persistence>
|
||||||
|
|
|
@ -4,12 +4,10 @@
|
||||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||||
<hibernate-configuration>
|
<hibernate-configuration>
|
||||||
<session-factory>
|
<session-factory>
|
||||||
<property name="connection.url"/>
|
<property name="connection.driver_class">org.postgresql.Driver</property>
|
||||||
<property name="connection.driver_class"/>
|
<property name="hibernate.jndi.url">java:/PostgresDS</property>
|
||||||
<!-- <property name="connection.username"/> -->
|
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
|
||||||
<!-- <property name="connection.password"/> -->
|
<property name="hibernate.hbm2ddl.auto">update</property>
|
||||||
|
<mapping class="ru.erius.weblab3.data.HitInfo"/>
|
||||||
<!-- DB schema will be updated if needed -->
|
|
||||||
<!-- <property name="hibernate.hbm2ddl.auto">update</property> -->
|
|
||||||
</session-factory>
|
</session-factory>
|
||||||
</hibernate-configuration>
|
</hibernate-configuration>
|
|
@ -3,5 +3,17 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||||
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
|
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
|
||||||
|
<navigation-rule>
|
||||||
|
<from-view-id>/check_hit.xhtml</from-view-id>
|
||||||
|
<navigation-case>
|
||||||
|
<from-outcome>index</from-outcome>
|
||||||
|
<to-view-id>/index.xhtml</to-view-id>
|
||||||
|
<redirect/>
|
||||||
|
</navigation-case>
|
||||||
|
<navigation-case>
|
||||||
|
<from-outcome>check_hit</from-outcome>
|
||||||
|
<to-view-id>/check_hit.xhtml</to-view-id>
|
||||||
|
<redirect/>
|
||||||
|
</navigation-case>
|
||||||
|
</navigation-rule>
|
||||||
</faces-config>
|
</faces-config>
|
|
@ -43,7 +43,7 @@
|
||||||
<f:selectItem itemValue="4" itemLabel="4"/>
|
<f:selectItem itemValue="4" itemLabel="4"/>
|
||||||
<f:selectItem itemValue="5" itemLabel="5"/>
|
<f:selectItem itemValue="5" itemLabel="5"/>
|
||||||
</h:selectOneRadio><br/>
|
</h:selectOneRadio><br/>
|
||||||
<h:commandButton id="submitBtn" value="Проверить" action="#{hitInfoBean.add()}">
|
<h:commandButton id="submitBtn" value="Проверить" action="#{hitInfoBean.btnAdd()}">
|
||||||
<f:ajax execute="inputForm" render="results"/>
|
<f:ajax execute="inputForm" render="results"/>
|
||||||
</h:commandButton>
|
</h:commandButton>
|
||||||
<h:commandButton value="Очистить" action="#{hitInfoBean.clear()}">
|
<h:commandButton value="Очистить" action="#{hitInfoBean.clear()}">
|
||||||
|
|
Loading…
Reference in a new issue