私はswingアプリケーションに取り組んでおり、パフォーマンスのためにHibernateを選択したデータを処理しています。今、私は仕事の80%をしました。アプリケーションが遅すぎることがわかりました。まるで永遠に待っているようです。私はそれをグーグルで調べたところ、多くのデータがある場合、Hibernate は最良の選択ではないことがわかりました。私はそれを知りませんでした。問題は、私のデータベースが多くの関連付け、結合、セットで複雑であることです...最初からやり直す時間がありません! 助けてください
これがコードのスニペットです。これは、すべてのエンティティが同様のクラスを持つデータを取得する方法です
public class CoursCrud {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session ;
public ArrayList<Object> findCoursByCoursId( int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findCoursByCoursId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findLastCours(){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findLastCours");
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findAllCours(){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findAllCours");
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findProfByCoursId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findProfByCoursId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findGroupeByCoursId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findGroupeByCoursId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findGroupeByCreneauId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findGroupeByCoursId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findSalleByCreneauId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findSalleByCreneauId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findProfByCreneauId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findProfByCreneauId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findCreneauFromCoursByCreneauId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findCreneauFromCoursByCreneauId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findCoursByCreneauId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findCoursByCreneauId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findSalleByCoursId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findSalleByCoursId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findCreneauByCoursId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findCreneauByCoursId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findCoursByGroupeId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findCoursByGroupeId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findCoursBySalleId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findCoursBySalleId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findProfBySalleId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findProfBySalleId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public int findIndex(int id){
CoursCrud C= new CoursCrud();
ArrayList<Object> cours =C.findAllCours();
int i=0;
for(Object cu: cours){
i++;
if(((Cours) cu).getId() == id){
break;
}
}
return --i;
}
public void createData( Object p){
session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
session.save(p);
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}
}
public void updateData( Object p){
session = sessionFactory.openSession();
session.beginTransaction();
session.update(p);
session.getTransaction().commit();
session.close();
}
public void CoursEmpty(){
CoursCrud C= new CoursCrud();
List<Object> cc = C.findAllCours();
for(Object c: cc){
C.deleteCoursByCoursId(((Cours)c).getId());
}
}
public void deleteCoursByCoursId(int id){
session = HibernateUtil.getSessionFactory().openSession();
CoursCrud C= new CoursCrud();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
Cours c = (Cours) C.findCoursByCoursId(id).get(0);
session.delete(c);
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}
}
public void deleteCoursCreneauByCoursId(int id){
session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
Query Q = session.getNamedQuery("deleteCoursCreneauByCoursId");
Q.setLong("id", id).executeUpdate();
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
System.out.println("Not succ !! \n");
} finally {
session.close();
}
}
public ArrayList<Object> findCreneauIndisponibiliteByCoursId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findCreneauIndisponibiliteByCoursId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findCoursIndisponibleByCreneauId(int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findCoursIndisponibleByCreneauId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findCoursByClassCoursId( int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findCoursByClassCoursId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public void deleteCoursByClassCours(int id){
CoursCrud C= new CoursCrud();
for(Object o: C.findCoursByClassCoursId(id)){
C.deleteCoursSeanceByCoursId(((Cours)o).getId());
C.deleteCoursCreneauByCoursId(((Cours)o).getId());
C.deleteCoursByCoursId(((Cours)o).getId());
}
}
public ArrayList<Object> findGroupeByClassCoursId( int id){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findGroupeByClassCoursId");
Q.setLong("id", id);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Integer> findIndexGroupebyClassCours(int id){
CoursCrud C= new CoursCrud();
GroupeCrud Gc= new GroupeCrud();
ArrayList<Object> groupeSelectedList= C.findGroupeByClassCoursId(id);
ArrayList<Object> groupeList= Gc.findAllGroupe();
ArrayList<Integer> indexSelectedList= new ArrayList<Integer>();
Alert a= new Alert();
for(Object m: groupeList){
for(Object ms: groupeSelectedList){
if(((Groupe) m).getId() == ((Groupe) ms).getId() ){
indexSelectedList.add(groupeList.indexOf(m));
}
}
}
return indexSelectedList;
}
public ArrayList<Integer> findIndexSeancebyClassCours(int id){
CoursCrud C= new CoursCrud();
SeanceCrud sC=new SeanceCrud();
ArrayList<Seance> SeanceSelectedList = new ArrayList<Seance>();
for(Object o: C.findCoursByClassCoursId(id)){
for(Object v: sC.findSeanceByCoursId(((Cours)o).getId())){
SeanceSelectedList.add((Seance)v);
}
}
ArrayList<Object> seanceList= sC.findAllSeance();
ArrayList<Integer> indexSelectedList= new ArrayList<Integer>();
Alert a= new Alert();
for(Object m: seanceList){
for(Seance ms: SeanceSelectedList){
if(((Seance) m).getId() == ms.getId() ){
indexSelectedList.add(seanceList.indexOf(m));
}
}
}
return indexSelectedList;
}
public void deleteCoursSeanceByCoursId(int id){
CoursCrud C= new CoursCrud();
session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
Cours c = (Cours) C.findCoursByCoursId(id).get(0);
c.getCoursSeance().clear();
session.update(c);
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}
}
public ArrayList<Integer> findIndexIndisponibilitebyCoursId(int id){
CoursCrud C= new CoursCrud();
CreneauCrud cC= new CreneauCrud();
ArrayList<Object> IndispoSelectedList= C.findCreneauIndisponibiliteByCoursId(id);
ArrayList<Object> creneauList= cC.findAllCreneau();
ArrayList<Integer> indexindispoSelectedList= new ArrayList<Integer>();
Alert a= new Alert();
for(Object m: creneauList){
for(Object ms: IndispoSelectedList){
if(((Creneau) m).getId() == ((Creneau) ms).getId() ){
indexindispoSelectedList.add(creneauList.indexOf(m));
}
}
}
return indexindispoSelectedList;
}
public ArrayList<Object> findCoursIndisponibleByCreneauIdAndCoursId(int idCreneau, int idCours){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findCoursIndisponibleByCreneauIdAndCoursId");
Q.setLong("idCours", idCours);
Q.setLong("idCreneau", idCreneau);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}
public ArrayList<Object> findCoursByCreneauIdAndGroupeId(int idCreneau, int idGroupe){
session = sessionFactory.openSession();
Query Q = session.getNamedQuery("findCoursByCreneauIdAndGroupeId");
Q.setLong("idGroupe", idGroupe);
Q.setLong("idCreneau", idCreneau);
List<Object> objet = Q.list();
session.close();
return (ArrayList<Object>) objet;
}