Java EE and MVC Design Pattern Implementation

Verified

Added on  2020/05/11

|14
|2362
|90
AI Summary
This solved assignment focuses on practical application of Java EE technologies within an MVC framework. It includes tasks related to EJB creation (for database operations), JPA entity mapping, and controller implementation. The assignment emphasizes understanding how these components interact in a real-world scenario.

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Enterprise Software Development
Question 1
(1a)
i. Java-Database-Connectivity ( JDBC )
The java Database Connectivity is a programming application interface that is majorly
used for the java language to create database applications. This determines how the user
can now access the database. It is Java access technology and used for Java database
connectivity. It was created by Oracle corporation to be used by Java Standard
Application platform. JDBC uses JDBC drivers with connect to the database.
ii. Serialization
Serialization simply is a process that entails changing object of a memory to make
stream of bytes in order that the stuff such as store can be on a disk or maybe send the
bytes over a network.
Only thing to understand now is how those stream of bytes are interpreted or manipulated
so that we get the exact same Object/ same state. There are various ways to achieve that.
Some of them are -
1. XML : Convert Object to XML, transfer it over a network or store it in a file/db.
Retrieve it and convert it back to the object with same state. In Java we use
JAXB(Java architecture for XML binding) library.(From java 6 it comes bundled
with JDK).
2. JSON :Same can be done by converting the Object to JSON (Javascript Object
notation). Again there is GSON library that can be used for this.
3. Or we can use the Serialization that is provided by the OOP language itself. For
eg. in Java you can serialize an Object my making it implement serializable
interface and writing to Object Stream.

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
(1b)
Components contained in>
1. Application client container contains Java classes and Libraries
2. Web container contains JSP pages and servlets as components.
3. EJB Containers contains Enterprise bean
(1c)
The role of Java EE.
Jave Enterprise edition is used to extend the specifications of Java SE with specification
for enterprise features.
Services provided by JEE
1. JEE has libraries that provide the functionality that can deploy a fault-tolerant
and distributed module components that are running on the application server.
2. JEE provides remote method invocation (RMI)
(1d)
Hibernate entity manager
(1e) benefits of using Object-Relational Mapping (ORM) to access data that is not
possible through
(JDBC).
Reuse of code, under this if class library is created it generate totally separate DLL file
that ORM data access code uses, the data objects will be re-used on a variety of
applications. This way applications need no data access.
Document Page
Question 2
(2a)
@ entity
@ table ( nam ="tblPatient")
public class Patient {
@ Id
@ GeneratedValue( strategy = GenerationType.IDENTITY)
private Long idd;
String Name = null;
String gender = null;
String dateOfBirth = null;
String age = null;
private Long get_Idd(){
return idd;
}
private void set_Idd(int idd){
this.idd = idd;
}
private String getNam(){
return Nam;
}
Private void setName(String Nam){
this.Nam = Nam;
}
private String getGende() is not null{
gende.getLength(length<=6) ;
return gende;
}
private void setGende(String gende){
this.gende = gende;
}
private String getdateOfBirth (){
return dateOfBirth;
}
Document Page
private void setdateOfBirth (String dateOfBirth){
this. dateOfBirth = dateOfBirth;
}
}
2b.
i.@JoinColumn (name = id) in User entity
ii. @OneToOne (mapped by= password) UserProfile entity.
2c.
In Table-per-class strategy in JPA, Each of the concrete classes gets still mapped to its
own database table. This mapping allows you to use polymorphic queries and to define
relationships to the superclass. Table-per-class has a superclass as and entity, that’s how is
different from mapped superclass strategy.
Below is a JPA notation to implement the above strategy:
@Inheritance(strategy=InheritanceType.JOINED)
2d.
@Entity
Public class Student(){
@ManyToMany(mappedBy="course")
}
@Entity
Public class course(){
@ManyToMany(mappedBy="Student")
}

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Question 3
3.
package au.edu.cqu.course;
import javax.persistence.*;
@Entity
@NamedQueries({
//Write a JPQL statement to retrieve the list of all courses from the table Course)
@NamedQuery(name=findAllCourses", query = "Select (courses) from
CoursePu”),
//You must implement the sequence parameter in the WHERE clause below. (Tips: a
sequence parameter starts with ?)
@NamedQuery(name="findCourseDetailsById",query="
SELECT courses FROM coursePu WHERE id=’+?+’"),
})
public class Course{
@Idy
@GeneratedValueprivate Long idy;
private string courseCode;
private string courseName;
public course () {
}
public Course (String courseCode, String courseName, Long idy) {
this.idy = idy;
Document Page
this.courseCode = courseCode; this.courseName = courseName;
}
public Long getIdy() {
return idy; }
public void setIdy(Long idy) {
this.idy = idy;
}
public String getCourseCode () {
return courseCode;
}
public void setCourseCode (String courseCode) {
this.courseCode = courseCode;
}
public String getCourseName () {
return courseName;
}
public void setCourseName (String courseName) {
this.courseName = courseName; }
}
//Driver program to test about entity
package au.edu.cqu.course;
import java.util.Iterator;
Document Page
import java.util.List;
import javax.persistence.*;
public class TestCourse{
public static void main(String[] args) {
EntityManagerFactory emfy=
Persistence.createEntityManagerFactory(”Eliclipse_link
");
EntityManager emi=emfy.createEntityManager();
EntityTransaction txi=emi.getTransaction(); txi.begin();findCourseDetailsById
Query query = emi.createQuery(""Select (courses) from CoursePu”");
query.setParameter();
List courseList=query.getResultList(); Iterator courseIterator=stList.iterator();
while(courseIterator.hasNext()){
Course cf=(Course) courseIterator.next(); System.out.print("idy:"+cf.getIdy());
System.out.print(cf.getCourseCode()); System.out.print(cf.getCourseName ());
System.out.println();
}
tx.commit();
emi.close(); }
}
}
}

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
(3b ) Persistent context , this is a set of all entities in which in any persisting identity
there will be a unique entity to instance. And within the same context there always
managers which control lifecycle that might access data store resources altogether.
(3c) Native Query
This are the queries that concise and are based on the open source object database.
It can be used has follows
PersonEntity p = em.find(PersonEntity.class, 1L);
log.info("Detach PersonEntity");
em.flush();
em.detach(p);
em.createNativeQuery("UPDATE person p SET firstname = firstname || '-
changed'").executeUpdate();
p = em.find(PersonEntity.class, 1L);
(3d) Dynamic Queries
This are the queries that carry bout a huge task of getting the data from the
database.An example of a dynamic code can be as below
DECLARE @country varchar(75)
SET @countyr = 'kenya'
SELECT * FROM kenya WHERE City = @country
Document Page
Question 4
(4a)
1. Message-driven EJBs
The message-driven bean always takes the role as consumer of asynchronous type
of messages and also it cannot in any way be called just directly by the clients, it
istherefore activated by container when message eventually arrives. EJBs interacts
with clients by allowing to send messages to topics that are listening. it can also
be called by other EJBs itself.
2. Session EJBs
This type of session is a non-persistent object, the lifetime of the session EJBs is
in between its interaction with the EJB and the client. At this point, the client calls
the methods after creating the EJB and avoids the methods. If the methods are not
removed by the clients, they will be removed by the EJB container at a point
when the it is failed to be removed by the client.
This session EJB is divided into two; this includes stateful and stateless.
Stateless session is said to be shared amongst several clients but stateful is
normally formed specifically for one client and a specific one and not others, it is
also not used by other clients.
3. Entity EJBs
This type of EJB represents the persistent objects, this type of EJB is
synchronized by the database type called relational databases to achieve its
persistence. The entity EJB is always shared by all clients because the client
cannot achieve this entity by itself . This is used as a mapping tool for relational
database.
Document Page
(4b)
A situation of analysis of strategic Marketing
(4c)
JPA: _persistence layer
JSF: _Presentation layer
EJB: _Business layer
(4d)
(i) Concurrency
When each service is presented by one instance, this makes only one client
to access the resources given at a time. By doing so, it therefore becomes
so difficult to access data where a centralized server is place to serve
simultaneous requests. Problems such as deadlocks may arise where the
threads may be competing for shared resources, concurrency therefore as a
service provided by EJB, makes the developer to sidestep the mentioned
problem.
(ii) Transaction
Transaction ensure that the application’s state preserves the integrity while
under loading from concurrent use. EJB give us a declarative syntax to
guard our business methods and, by associating resources such
enitymanager.
(iii) Pooling
Because of the strict concurrency rules enforced by the Container, there is
an introduction of intentional bottleneck available for processing request.
If the is restricted to a singular instance, all subsequent requests would
have to queue up until their turn was reached

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Question 5
(5a)
@Entity
public class Movie{
@Idy @GeneratedValue long idy;
private String movieTitle;
private String directorName;
private String movieDuration;
private String yearReleased;
public Movie(String movieTitle, directorName, movieDuration, yearReleased, Long id){
this.idy=idy;
this. movieTitle= movieTitle;
this. directorName= directorName;
this. movieDuration= movieDuration;
this. yearReleased= yearReleased;
}
public final String getmovieTitle ()
{
return movieTitle;
}
public final String getdirectorName ()
{
return directorName;
}
public final String getmovieDuration ()
{
return movieDuration;
}
public final String getyearReleased ()
{
return yearReleased;
}
public String setmovieTitle (getmovieTitle)
{
movieTitle;
}
public String setdirectorName (getdirectorName)
{
directorName;
}
Document Page
public String setmovieDuration (getmovieDuration)
{
movieDuration;
}
public String setyearReleased (getyearReleased)
{
yearReleased;
}
}
(5b)
package MovieRemoteEJB;
public interface MovieRemoteEJB extends java.rmi.Remote {
public createMovie(Movie){
Movie movie=new Movie();
return movie;}}
(5c)
@Stateless
public class MovieEJB implements MovieRemoteEJB() {
//pass persistence unit to entityManager.
@PersistenceContext(unitName="moviePU")
private EntityManager entityManager;
public void mov(Movie movie){
entityManager.persist(movie);
}
}
(5d)
Document Page
Public class test extends Movie(){
Public mov{
Private Long id;
private String movieTitle;
private String directorName;
private String movieDuration;
private String yearReleased;
}
Public static void main (String[] args){
Movie movie=new Movie(mov);
mov.getTransaction().begin();
mov.persist(movie);
mov.getTransaction().commit();
}
}
Question 6
6a)
@Stateless
public class GameEJB {
//pass persistence unit to entityManager.
@PersistenceContext(unitName="GamePU")

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
private EntityManager entityManager;
public void createGame(String newGame){
newGame newgame=new newGame();
return newgame;
}
}
b.
<managed-bean eager="true">
<managed-bean-name> GameController</managed-bean-name>
<managed-property>
<property-name>Rating</property-name>
<value>"#{gameController.game.rating}"</value>
</managed-property>
<managed-property>
<property-name>Title</property-name>
<value>"#{gameController.game.title}"</value>
</managed-property>
<managed-property>
<property-name>coords</property-name>
<value>"#{gameController.doCreateGame}"</value>
</managed-property>
</managed-bean>
c.
Model-View-Controller MVC design pattern is used to build enterprise applications
because of its security; the security is placed inside controller object and the interface for
customers is then driven through the controller object, in the controller object, there are a
single location point and a single entity in order for the security check be performed.
Advantages of Model-View-Controller MVC design pattern
a) Simultaneous development of applications. Meaning that more than one
developer is able to can work on the model, controller and views.
b) High cohesion , this is logging of the operations in a logical manner.
c) Low coupling. low coupling among models, views or controllers and this is the
very nature of MVC framework
d) Ease modification this due to the separation of responsibilities for modification.
Java EE technology that uses MVC is the Java servlets pages JSP
d.
USES SEES
CLIENT
1 out of 14
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]