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.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="library" name="Maven: jakarta.jws:jakarta.jws-api:1.1.1" level="project" />
|
||||||
<orderEntry type="module" module-name="MoviesCommon" />
|
<orderEntry type="module" module-name="MoviesCommon" />
|
||||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.10" level="project" />
|
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -3,6 +3,8 @@ package at.technikumwien.movies;
|
|||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import javax.xml.bind.annotation.XmlAttribute;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ -11,7 +13,17 @@ import java.time.LocalDate;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "t_actors")
|
@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 {
|
public class Actors {
|
||||||
|
@XmlAttribute(name = "id")
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -25,13 +37,10 @@ public class Actors {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Sex sex;
|
private Sex sex;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
private LocalDate birthdate;
|
private LocalDate birthdate;
|
||||||
|
|
||||||
public Actors(String firstname, String lastname, Sex sex, LocalDate birthdate) {
|
public Actors(String firstname, String lastname, Sex sex, LocalDate birthdate) {
|
||||||
this(null, firstname, lastname, sex, 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
|
@Entity
|
||||||
@Table(name = "t_movies")
|
@Table(name = "t_movies")
|
||||||
@NamedQueries({
|
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "Movies.selectAll",
|
name = "Movies.selectAll",
|
||||||
query = "SELECT n FROM Movies n"
|
query = "SELECT n FROM Movies n"
|
||||||
),
|
)
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "Movies.selectByTitle",
|
name = "Movies.selectByTitle",
|
||||||
query = "SELECT n FROM Movies n WHERE n.title LIKE :title"
|
query = "SELECT n FROM Movies n WHERE n.title LIKE :title"
|
||||||
)
|
)
|
||||||
})
|
|
||||||
@XmlRootElement
|
@XmlRootElement
|
||||||
public class Movies {
|
public class Movies {
|
||||||
// TODO: XmlAttributes may need different names
|
// TODO: XmlAttributes may need different names
|
||||||
@ -37,6 +35,7 @@ public class Movies {
|
|||||||
@XmlAttribute
|
@XmlAttribute
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
|
@Column(length = 2048)
|
||||||
@XmlAttribute
|
@XmlAttribute
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@ -11,6 +11,16 @@
|
|||||||
</webroots>
|
</webroots>
|
||||||
</configuration>
|
</configuration>
|
||||||
</facet>
|
</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>
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_9">
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_9">
|
||||||
<output url="file://$MODULE_DIR$/target/classes" />
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
@ -5,6 +5,7 @@ import javax.ejb.*;
|
|||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityNotFoundException;
|
import javax.persistence.EntityNotFoundException;
|
||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.PersistenceContext;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -52,19 +53,17 @@ public class MoviesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save(Movies movies) {
|
public void save(Movies movies) {
|
||||||
// TODO: Search for actors, studio based on fields we get
|
// // TODO
|
||||||
// If exists -> Replace by found ID
|
// for (Actors actor : movies.getActors()) {
|
||||||
// Else -> Error!
|
// 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);
|
LOGGER.info("save() >> movies" + movies);
|
||||||
|
|
||||||
if (movies.getId() == null) {
|
|
||||||
em.persist(movies);
|
|
||||||
} else {
|
|
||||||
findById(movies.getId()); //checks if movies exists
|
|
||||||
em.merge(movies);
|
em.merge(movies);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: On error: context.setRollbackOnly();
|
|
||||||
// or: throw new EJBException("Can't save ...")
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -5,8 +5,7 @@
|
|||||||
version="2.2">
|
version="2.2">
|
||||||
<persistence-unit name="MoviesPU">
|
<persistence-unit name="MoviesPU">
|
||||||
<jta-data-source>java:jboss/datasources/MoviesDS</jta-data-source>
|
<jta-data-source>java:jboss/datasources/MoviesDS</jta-data-source>
|
||||||
<jar-file>lib/NewsCommon-1.0.0-SNAPSHOT.jar</jar-file>
|
<!-- <jar-file>lib/MoviesCommon-1.0.0-SNAPSHOT.jar</jar-file> -->
|
||||||
<exclude-unlisted-classes>false</exclude-unlisted-classes>
|
|
||||||
<properties>
|
<properties>
|
||||||
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect"/>
|
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect"/>
|
||||||
<property name="hibernate.show_sql" value="true" />
|
<property name="hibernate.show_sql" value="true" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user