Minor changes, remarks for future work
This commit is contained in:
parent
44a674cba4
commit
5b3f7a7c4e
@ -59,6 +59,5 @@
|
||||
<orderEntry type="library" name="Maven: jakarta.xml.soap:jakarta.xml.soap-api:1.4.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: jakarta.jws:jakarta.jws-api:1.1.1" level="project" />
|
||||
<orderEntry type="module" module-name="MoviesCommon" />
|
||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.10" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -3,6 +3,8 @@ package at.technikumwien.movies;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
@ -11,7 +13,17 @@ import java.time.LocalDate;
|
||||
|
||||
@Entity
|
||||
@Table(name = "t_actors")
|
||||
@NamedQuery(
|
||||
name = "Actors.getIdByProperties",
|
||||
query = "SELECT a.id FROM Actors a WHERE " +
|
||||
"a.firstname LIKE :firstname AND " +
|
||||
"a.lastname LIKE :lastname AND " +
|
||||
"a.sex = :sex AND " +
|
||||
"a.birthdate = :birthdate"
|
||||
)
|
||||
@XmlRootElement
|
||||
public class Actors {
|
||||
@XmlAttribute(name = "id")
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
@ -25,13 +37,10 @@ public class Actors {
|
||||
@Column(nullable = false)
|
||||
private Sex sex;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDate birthdate;
|
||||
|
||||
public Actors(String firstname, String lastname, Sex sex, LocalDate birthdate) {
|
||||
this(null, firstname, lastname, sex, birthdate);
|
||||
}
|
||||
|
||||
//TODO consider using
|
||||
//@ManyToMany(mappedBy = 'actors')
|
||||
//private List<at.technikumwien.movies.Movies> movies
|
||||
}
|
||||
|
@ -14,16 +14,14 @@ import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "t_movies")
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
@NamedQuery(
|
||||
name = "Movies.selectAll",
|
||||
query = "SELECT n FROM Movies n"
|
||||
),
|
||||
@NamedQuery(
|
||||
)
|
||||
@NamedQuery(
|
||||
name = "Movies.selectByTitle",
|
||||
query = "SELECT n FROM Movies n WHERE n.title LIKE :title"
|
||||
)
|
||||
})
|
||||
)
|
||||
@XmlRootElement
|
||||
public class Movies {
|
||||
// TODO: XmlAttributes may need different names
|
||||
@ -37,6 +35,7 @@ public class Movies {
|
||||
@XmlAttribute
|
||||
private String title;
|
||||
|
||||
@Column(length = 2048)
|
||||
@XmlAttribute
|
||||
private String description;
|
||||
|
||||
|
@ -11,6 +11,16 @@
|
||||
</webroots>
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="jpa" name="JPA">
|
||||
<configuration>
|
||||
<setting name="validation-enabled" value="true" />
|
||||
<datasource-mapping>
|
||||
<factory-entry name="MoviesPU" />
|
||||
</datasource-mapping>
|
||||
<naming-strategy-map />
|
||||
<deploymentDescriptor name="persistence.xml" url="file://$MODULE_DIR$/src/main/resources/META-INF/persistence.xml" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_9">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
|
@ -5,6 +5,7 @@ import javax.ejb.*;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -52,19 +53,17 @@ public class MoviesService {
|
||||
}
|
||||
|
||||
public void save(Movies movies) {
|
||||
// TODO: Search for actors, studio based on fields we get
|
||||
// If exists -> Replace by found ID
|
||||
// Else -> Error!
|
||||
// // TODO
|
||||
// for (Actors actor : movies.getActors()) {
|
||||
// ResultSet rs = em.createNamedQuery("Actors.getIdByParameters", Actors.class)
|
||||
// .setParameter() // TODO
|
||||
// .getResultList();
|
||||
//
|
||||
// // Check if we have a result, if yes -> take first, actor.id = resultID
|
||||
// // If no result: context.setRollbackOnly();
|
||||
// }
|
||||
LOGGER.info("save() >> movies" + movies);
|
||||
|
||||
if (movies.getId() == null) {
|
||||
em.persist(movies);
|
||||
} else {
|
||||
findById(movies.getId()); //checks if movies exists
|
||||
em.merge(movies);
|
||||
}
|
||||
|
||||
// TODO: On error: context.setRollbackOnly();
|
||||
// or: throw new EJBException("Can't save ...")
|
||||
}
|
||||
}
|
@ -5,8 +5,7 @@
|
||||
version="2.2">
|
||||
<persistence-unit name="MoviesPU">
|
||||
<jta-data-source>java:jboss/datasources/MoviesDS</jta-data-source>
|
||||
<jar-file>lib/NewsCommon-1.0.0-SNAPSHOT.jar</jar-file>
|
||||
<exclude-unlisted-classes>false</exclude-unlisted-classes>
|
||||
<!-- <jar-file>lib/MoviesCommon-1.0.0-SNAPSHOT.jar</jar-file> -->
|
||||
<properties>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect"/>
|
||||
<property name="hibernate.show_sql" value="true" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user