Question
PLEASE WRITE THIS IN COMPUTER, NOT BY THE HAND OR SCREENSHOT. Java IDE: Netbeans Database: Derby DATABASE package edu.pupr.entities; import java.io.Serializable; import javax.persistence.*; import java.sql.Timestamp;
PLEASE WRITE THIS IN COMPUTER, NOT BY THE HAND OR SCREENSHOT.
Java
IDE: Netbeans
Database: Derby
DATABASE
package edu.pupr.entities;
import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;
/**
* The persistent class for the visitors database table.
*
*/
@Entity
@Table(name="visitors")
@NamedQueries({
@NamedQuery(name="Visitor.findAll", query="SELECT v FROM Visitor v"),
@NamedQuery(name="Visitor.findVisitor", query="SELECT v FROM Visitor v "
+ " where v.lastName = :lastName"
+ " and v.firstName = :firstName"),
@NamedQuery(name="Visitor.findTodayList", query="SELECT v FROM Visitor v "
+ " where function('date', CURRENT_TIMESTAMP) = function('date', v.dateBegin)")
})
public class Visitor implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@Column(name="company_from")
private String companyFrom;
@Column(name="date_begin")
private Timestamp dateBegin;
@Column(name="date_end")
private Timestamp dateEnd;
private String firstName;
private String lastName;
@Column(name="office_visiting")
private String officeVisiting;
private String photo;
@Column(name="staff_visiting")
private String staffVisiting;
@Column(name="visitor_ID")
private String visitorID;
public Visitor() {
}
public Visitor(int id, String companyFrom, Timestamp dateBegin, Timestamp dateEnd, String firstName,
String lastName, String officeVisiting, String photo, String staffVisiting, String visitorID) {
this.id = id;
this.companyFrom = companyFrom;
this.dateBegin = dateBegin;
this.dateEnd = dateEnd;
this.firstName = firstName;
this.lastName = lastName;
this.officeVisiting = officeVisiting;
this.photo = photo;
this.staffVisiting = staffVisiting;
this.visitorID = visitorID;
}
public Visitor(String companyFrom, Timestamp dateBegin, Timestamp dateEnd, String firstName,
String lastName, String officeVisiting, String photo, String staffVisiting, String visitorID) {
this.companyFrom = companyFrom;
this.dateBegin = dateBegin;
this.dateEnd = dateEnd;
this.firstName = firstName;
this.lastName = lastName;
this.officeVisiting = officeVisiting;
this.photo = photo;
this.staffVisiting = staffVisiting;
this.visitorID = visitorID;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getCompanyFrom() {
return this.companyFrom;
}
public void setCompanyFrom(String companyFrom) {
this.companyFrom = companyFrom;
}
public Timestamp getDateBegin() {
return this.dateBegin;
}
public void setDateBegin(Timestamp dateBegin) {
this.dateBegin = dateBegin;
}
public Timestamp getDateEnd() {
return this.dateEnd;
}
public void setDateEnd(Timestamp dateEnd) {
this.dateEnd = dateEnd;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getOfficeVisiting() {
return this.officeVisiting;
}
public void setOfficeVisiting(String officeVisiting) {
this.officeVisiting = officeVisiting;
}
public String getPhoto() {
return this.photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public String getStaffVisiting() {
return this.staffVisiting;
}
public void setStaffVisiting(String staffVisiting) {
this.staffVisiting = staffVisiting;
}
public String getVisitorID() {
return this.visitorID;
}
public void setVisitorID(String visitorID) {
this.visitorID = visitorID;
}
@Override
public String toString() {
return "Visitor [id=" + id + ", companyFrom=" + companyFrom + ", dateBegin=" + dateBegin + ", dateEnd="
+ dateEnd + ", firstName=" + firstName + ", lastName=" + lastName + ", officeVisiting=" + officeVisiting
+ ", photo=" + photo + ", staffVisiting=" + staffVisiting + ", visitorID=" + visitorID + "]";
}
}
--------------------------------------------------------------------------------------------------------------------
package edu.pupr.entities;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
public class VisitorSQL {
private EntityManagerFactory emfactory = null;
private EntityManager entitymanager = null;
public VisitorSQL() {
try {
emfactory = Persistence.createEntityManagerFactory("Visitors");
entitymanager = emfactory.createEntityManager();
} catch (PersistenceException persistenceException) {
System.err.println("Error: " + persistenceException.getMessage());
System.exit(1);
}
}
public Visitor getID(int id) {
Visitor visitor = entitymanager.find(Visitor.class, id);
return visitor;
}
public Visitor findVisitor(String lastName, String firstName) {
Query query = entitymanager.createNamedQuery("Visitor.findVisitor");
query.setParameter("lastName", lastName);
query.setParameter("firstName", firstName);
Visitor visitor = (Visitor) query.getResultList().get(0);
return visitor;
}
public List
Query query = entitymanager.createNamedQuery("Visitor.findAll");
List
return visitors;
}
public List
Query query = entitymanager.createNamedQuery("Visitor.findTodayList");
List
return visitors;
}
public void add(String companyFrom, Timestamp dateBegin, Timestamp dateEnd, String firstName,
String lastName, String officeVisiting, String photo, String staffVisiting, String visitorID) {
Visitor visitor = new Visitor(companyFrom, dateBegin, dateEnd, firstName, lastName, officeVisiting, photo, staffVisiting, visitorID);
entitymanager.getTransaction().begin();
entitymanager.persist(visitor);
entitymanager.getTransaction().commit( );
}
public void update(Visitor visitor) {
entitymanager.getTransaction().begin();
entitymanager.merge(visitor);
entitymanager.getTransaction().commit();
}
public void update(int id, String companyFrom, Timestamp dateBegin, Timestamp dateEnd, String firstName,
String lastName, String officeVisiting, String photo, String staffVisiting, String visitorID) {
update(new Visitor(companyFrom, dateBegin, dateEnd, firstName, lastName, officeVisiting, photo, staffVisiting, visitorID));
}
public void disconnect() {
entitymanager.close();
emfactory.close();
}
}
------------------------------------------------------------------------------
package edu.pupr.services;
import java.sql.Timestamp;
import java.util.List;
import edu.pupr.entities.*;
public class TestGet {
public static void main(String[] args) {
VisitorSQL visitorSQL = new VisitorSQL();
// Buscar record #1
Visitor visitor = visitorSQL.getID(1);
System.out.println(visitor.getFirstName());
System.out.println(visitor.getLastName());
System.out.println(visitor.getDateBegin());
// Actualizar la fecha de salida
visitor.setDateEnd(Timestamp.valueOf("2018-09-26 20:47:00.0"));
visitorSQL.update(visitor);
// Anadir un nuevo record
//visitorSQL.add("Molina Health", Timestamp.valueOf("2018-09-27 09:10:34.0"), null, "Jasmine", "Arrieta", "L100", "sae231.jpg", "Jose Rodriguez", "1800694");
// Obtener la lista de visitantes
List
System.out.println();
System.out.println("Print List:");
for (Visitor guest : visitors) {
System.out.println(guest);
}
// Buscar un visitante por su nombre y apellido
visitor = visitorSQL.findVisitor("Arrieta", "Jasmine");
System.out.printf("Id: %d%n", visitor.getId());
// Traer todos los records de hoy dia
visitors = visitorSQL.getTodayList();
System.out.println();
System.out.println("Print List of Today:");
for (Visitor guest : visitors) {
System.out.println(guest);
}
visitorSQL.disconnect();
}
}
Project #1 Objectives: To write a program that implements the following Advanced Programming concepts 1. Data encapsulation 2. Instantiate classes 3. Inheritance 4. Graphical User Interface concepts 5. Inner classes 6. Database 7. Java Persistence API Project Name: Company Reception The program will have the following private attributes 1. Visitor's first name 2. Visitor's last name 3. Company from 4. Visitor's ID (like license No., electoral card, etc.) 5. Photo (path where photo is) 6. staff visiting name 7. Office no. 8. Date time in (timestamp) 9. Date time out (timestamp) Project #1 Objectives: To write a program that implements the following Advanced Programming concepts 1. Data encapsulation 2. Instantiate classes 3. Inheritance 4. Graphical User Interface concepts 5. Inner classes 6. Database 7. Java Persistence API Project Name: Company Reception The program will have the following private attributes 1. Visitor's first name 2. Visitor's last name 3. Company from 4. Visitor's ID (like license No., electoral card, etc.) 5. Photo (path where photo is) 6. staff visiting name 7. Office no. 8. Date time in (timestamp) 9. Date time out (timestamp)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started