deleting hibernate
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
package ch.progetto152.crud;
|
||||
|
||||
import ch.progetto152.entity.Location;
|
||||
import ch.progetto152.utils.HibernateUtils;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class crudLocation {
|
||||
|
||||
private Session session;
|
||||
|
||||
public crudLocation(Session session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public void create(Location Location) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(Location);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public Location read(int index) {
|
||||
Session asd = HibernateUtils.getSessionFactory().openSession();
|
||||
Location Location = asd.get(Location.class, index);
|
||||
return Location;
|
||||
}
|
||||
|
||||
public Location readLocationByName(String name) {
|
||||
Session asd = HibernateUtils.getSessionFactory().openSession();
|
||||
Location Location = (Location) asd.createQuery("from Location where name = :name").setParameter("name", name).uniqueResult();
|
||||
return Location;
|
||||
}
|
||||
|
||||
public void update(int id, Location location) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
Location Location = session.get(Location.class, id);
|
||||
session.evict(Location);
|
||||
Location.setId(location.getId());
|
||||
Location.setLocation(location.getLocation());
|
||||
Location.setRegion(location.getRegion());
|
||||
Location.setLat(location.getLat());
|
||||
Location.setLon(location.getLon());
|
||||
session.update(Location);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
Location Location = session.get(Location.class, id);
|
||||
session.delete(Location);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public List<Location> readAll() {
|
||||
return session.createQuery("from Location").list();
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package ch.progetto152.crud;
|
||||
|
||||
import ch.progetto152.entity.LocationVisited;
|
||||
import ch.progetto152.utils.HibernateUtils;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class crudLocationVisited {
|
||||
|
||||
private Session session;
|
||||
|
||||
public crudLocationVisited(Session session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public void create(LocationVisited LocationVisited) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(LocationVisited);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public LocationVisited read(int index) {
|
||||
Session asd = HibernateUtils.getSessionFactory().openSession();
|
||||
LocationVisited LocationVisited = asd.get(LocationVisited.class, index);
|
||||
return LocationVisited;
|
||||
}
|
||||
|
||||
public LocationVisited readLocationVisitedByName(String name) {
|
||||
Session asd = HibernateUtils.getSessionFactory().openSession();
|
||||
LocationVisited LocationVisited = (LocationVisited) asd.createQuery("from LocationVisited where name = :name").setParameter("name", name).uniqueResult();
|
||||
return LocationVisited;
|
||||
}
|
||||
|
||||
public void update(int id, LocationVisited locationVisited) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
LocationVisited LocationVisited = session.get(LocationVisited.class, id);
|
||||
session.evict(LocationVisited);
|
||||
LocationVisited.setId(locationVisited.getId());
|
||||
LocationVisited.setLocationid(locationVisited.getLocationid());
|
||||
LocationVisited.setUserId(locationVisited.getUserId());
|
||||
session.update(LocationVisited);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
LocationVisited LocationVisited = session.get(LocationVisited.class, id);
|
||||
session.delete(LocationVisited);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public List<LocationVisited> readAll() {
|
||||
return session.createQuery("from LocationVisited").list();
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package ch.progetto152.crud;
|
||||
|
||||
import ch.progetto152.entity.User;
|
||||
import ch.progetto152.utils.HibernateUtils;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class crudUser {
|
||||
|
||||
private Session session;
|
||||
|
||||
public crudUser(Session session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public void create(User User) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(User);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public User read(int index) {
|
||||
Session asd = HibernateUtils.getSessionFactory().openSession();
|
||||
User User = asd.get(User.class, index);
|
||||
return User;
|
||||
}
|
||||
|
||||
public User readUserByName(String name) {
|
||||
Session asd = HibernateUtils.getSessionFactory().openSession();
|
||||
User User = (User) asd.createQuery("from User where name = :name").setParameter("name", name).uniqueResult();
|
||||
return User;
|
||||
}
|
||||
|
||||
public void update(int id, User user) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
User User = session.get(User.class, id);
|
||||
session.evict(User);
|
||||
User.setId(user.getId());
|
||||
User.setName(user.getName());
|
||||
User.setUsername(user.getUsername());
|
||||
User.setPassword(user.getPassword());
|
||||
session.update(User);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
User User = session.get(User.class, id);
|
||||
session.delete(User);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public List<User> readAll() {
|
||||
return session.createQuery("from User").list();
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package ch.progetto152.crud;
|
||||
|
||||
import ch.progetto152.entity.Waypoints;
|
||||
import ch.progetto152.utils.HibernateUtils;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class crudWaypoints {
|
||||
|
||||
private Session session;
|
||||
|
||||
public crudWaypoints(Session session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public void create(Waypoints Waypoints) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(Waypoints);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public Waypoints read(int index) {
|
||||
Session asd = HibernateUtils.getSessionFactory().openSession();
|
||||
Waypoints Waypoints = asd.get(Waypoints.class, index);
|
||||
return Waypoints;
|
||||
}
|
||||
|
||||
public Waypoints readWaypointsByName(String name) {
|
||||
Session asd = HibernateUtils.getSessionFactory().openSession();
|
||||
Waypoints Waypoints = (Waypoints) asd.createQuery("from Waypoints where name = :name").setParameter("name", name).uniqueResult();
|
||||
return Waypoints;
|
||||
}
|
||||
|
||||
public void update(int id, Waypoints waypoints) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
Waypoints Waypoints = session.get(Waypoints.class, id);
|
||||
session.evict(Waypoints);
|
||||
Waypoints.setId(waypoints.getId());
|
||||
Waypoints.setName(waypoints.getName());
|
||||
Waypoints.setLat(waypoints.getLat());
|
||||
Waypoints.setLon(waypoints.getLon());
|
||||
Waypoints.setDescription(waypoints.getDescription());
|
||||
Waypoints.setImg(waypoints.getImg());
|
||||
session.update(Waypoints);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
Transaction tx = session.beginTransaction();
|
||||
Waypoints Waypoints = session.get(Waypoints.class, id);
|
||||
session.delete(Waypoints);
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public List<Waypoints> readAll() {
|
||||
return session.createQuery("from Waypoints").list();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package ch.progetto152.utils;
|
||||
|
||||
import ch.progetto152.entity.*;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
public class HibernateUtils {
|
||||
|
||||
private static SessionFactory sessionFactory = null;
|
||||
|
||||
public static SessionFactory getSessionFactory() {
|
||||
if (sessionFactory == null) {
|
||||
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
|
||||
configuration.addAnnotatedClass(Location.class);
|
||||
configuration.addAnnotatedClass(LocationVisited.class);
|
||||
configuration.addAnnotatedClass(User.class);
|
||||
configuration.addAnnotatedClass(Waypoints.class);
|
||||
sessionFactory = configuration.buildSessionFactory();
|
||||
}
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user