Skip to content

Commit

Permalink
Missing test sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxouwell committed Dec 8, 2023
1 parent 840fe95 commit 0504f75
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package de.elnarion.test.sequence.t0003jakarta;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "MOVIE")
public class Movie {

@Id
private Long id;

private String movieName;

private Integer releaseYear;

private String language;


public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getMovieName() {
return movieName;
}

public void setMovieName(String movieName) {
this.movieName = movieName;
}

public Integer getReleaseYear() {
return releaseYear;
}

public void setReleaseYear(Integer releaseYear) {
this.releaseYear = releaseYear;
}

public String getLanguage() {
return language;
}

public void setLanguage(String language) {
this.language = language;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package de.elnarion.test.sequence.t0003jakarta;

import java.util.List;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;

public class MovieDAO {

@PersistenceContext
private
EntityManager entityManager;


public void saveMovie(de.elnarion.test.sequence.t0003jakarta.Movie paramMovie) {
EntityManager em = getEntityManager();

em.getTransaction().begin();

em.persist(paramMovie);
em.getTransaction().commit();
}

public de.elnarion.test.sequence.t0003jakarta.Movie getMovie(Long movieId) {
EntityManager em = getEntityManager();
de.elnarion.test.sequence.t0003jakarta.Movie movie = em.find(de.elnarion.test.sequence.t0003jakarta.Movie.class, Long.valueOf(movieId));
em.detach(movie);
return movie;
}

public void changeMovieLanguage(Long paramId, String paramLanguage) {
EntityManager em = getEntityManager();
de.elnarion.test.sequence.t0003jakarta.Movie movie = getMovie(paramId);
em.detach(movie);
movie.setLanguage(paramLanguage);
em.getTransaction().begin();
em.merge(movie);
em.getTransaction().commit();
}

public List<?> queryForMovies() {
EntityManager em = getEntityManager();
List<?> movies = em.createQuery("SELECT movie from Movie movie where movie.language = ?1")
.setParameter(1, "English")
.getResultList();
return movies;
}

public void removeMovie() {
EntityManager em = getEntityManager();
em.getTransaction().begin();
de.elnarion.test.sequence.t0003jakarta.Movie movie = em.find(de.elnarion.test.sequence.t0003jakarta.Movie.class, Long.valueOf(1L));
em.remove(movie);
em.getTransaction().commit();
}

public EntityManager getEntityManager() {
return entityManager;
}


public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.elnarion.test.sequence.t0003jakarta;

import de.elnarion.test.sequence.t0003.Movie;
import de.elnarion.test.sequence.t0003.MovieDAO;

public class MovieService {

MovieDAO movieDAO;

public void doSomeBusiness() {
Movie movie = movieDAO.getMovie((long) 111);
movie.setMovieName("asdfasdfasdf");
movieDAO.saveMovie(movie);
}

}

0 comments on commit 0504f75

Please sign in to comment.