Skip to content

Commit

Permalink
Merge pull request #5 from dangthai121200/connectdatabase
Browse files Browse the repository at this point in the history
Connectdatabase
  • Loading branch information
dangthai121200 authored Dec 22, 2021
2 parents 0c00551 + 63d8a72 commit ec26cbc
Show file tree
Hide file tree
Showing 17 changed files with 930 additions and 0 deletions.
125 changes: 125 additions & 0 deletions src/java/dao/DaoAdmin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dao;

import model.Admin;
import imp.IAction;
import java.sql.ResultSet;
import java.util.List;
import org.hibernate.Session;
import util.HibernateMovie;
import imp.ICheckLogin;
import imp.ICheckName;
import imp.ICheckPassword;
import imp.IListName;
import java.util.Date;

/**
*
* @author gaone
*/
public class DaoAdmin implements ICheckLogin<Admin>, IAction<Admin>, IListName, ICheckName {

private Session session;

public DaoAdmin(Session session) {
this.session = session;
}

@Override
public Admin checkLogin(String username, String password) {
List<Admin> admins = null;
session.beginTransaction();
admins = session.createQuery("from Admin where username=:username").setParameter("username", username).list();
session.getTransaction().commit();
if (admins.size() > 0 && admins.get(0).getPassword().equals(password)) {
return admins.get(0);
}
return null;
}

@Override
public List<Admin> getAll() {
session.beginTransaction();
List<Admin> admins = session.createQuery("from Admin").list();
session.getTransaction().commit();
return admins;
}

@Override
public Admin findById(int id) {
session.beginTransaction();
Admin admin = (Admin) session.get(Admin.class, id);
session.getTransaction().commit();
return admin;
}

@Override
public void delete(Admin object) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void update(Admin object) {
session.beginTransaction();
session.update(object);
session.getTransaction().commit();
session.close();
}

public void update(int id, String fullName, String password, Date birthday, String gmail, Integer sdt) {
session.beginTransaction();
Admin admin = (Admin) session.get(Admin.class, id);
admin.setFullName(fullName);
if(password.length()>0){
admin.setPassword(password);
}
admin.setBirthday(birthday);
admin.setGmail(gmail);
admin.setSdt(sdt);
session.getTransaction().commit();
session.close();
}

@Override
public void add(Admin object) {
session.beginTransaction();
session.save(object);
session.getTransaction().commit();
session.close();
}

@Override
public List<String> getAllUserName() {
session.beginTransaction();
List<String> listUserNamse = session.createQuery("select username from Admin").list();
session.getTransaction().commit();
return listUserNamse;
}
// public static void main(String[] args) {
// List<String> admins=new DaoAdmin(HibernateMovie.openSession()).getAllUserName();
// System.out.println(admins.toString());
// }

@Override
public boolean checkUserName(String username) {
List<String> names = null;
session.beginTransaction();
names = session.createQuery("select username from Admin where username=:username").setParameter("username", username).list();
session.getTransaction().commit();
if (names.size() == 0) {
return false;
}
return true;
}
public int countAdmin() {
session.beginTransaction();
List countList = session.createSQLQuery("SELECT COUNT(id_admin) FROM `admin`").list();
session.getTransaction().commit();
int count = Integer.parseInt(countList.get(0).toString());
return count;
}
}
67 changes: 67 additions & 0 deletions src/java/dao/DaoCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dao;

import model.Category;
import imp.IAction;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hibernate.Session;
import util.HibernateMovie;

/**
*
* @author gaone
*/
public class DaoCategory implements IAction<Category> {

private Session session;

public DaoCategory(Session session) {
this.session = session;
}

@Override
public List<Category> getAll() {
session.beginTransaction();
List<Category> list = session.createQuery("from Category").list();
session.getTransaction().commit();
return list;
}

@Override
public Category findById(int id) {
session.beginTransaction();
Category category = (Category) session.get(Category.class, id);
session.getTransaction().commit();
return category;
}

@Override
public void delete(Category object) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void update(Category object) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void add(Category object) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

public Set getAllByListId(char[] lsitIdCategory) {
Set categorys = new HashSet(0);
for (int i = 0; i < lsitIdCategory.length; i++) {
int id=Integer.parseInt(String.valueOf(lsitIdCategory[i]));
categorys.add(findById(id));
}
return categorys;
}
}
52 changes: 52 additions & 0 deletions src/java/dao/DaoCategoryMovie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dao;

import imp.IAction;
import java.util.List;
import model.CategoryMoive;
import org.hibernate.Session;

/**
*
* @author gaone
*/
public class DaoCategoryMovie implements IAction<CategoryMoive> {

private Session session;

public DaoCategoryMovie(Session session) {
this.session = session;
}

@Override
public List<CategoryMoive> getAll() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public CategoryMoive findById(int id) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void delete(CategoryMoive object) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void update(CategoryMoive object) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void add(CategoryMoive object) {
session.beginTransaction();
session.save(object);
session.getTransaction().commit();
}

}
55 changes: 55 additions & 0 deletions src/java/dao/DaoFilmType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dao;

import model.Filmtype;
import imp.IAction;
import java.util.List;
import org.hibernate.Session;

/**
*
* @author gaone
*/
public class DaoFilmType implements IAction<Filmtype>{
private Session session;

public DaoFilmType(Session session) {
this.session = session;
}


@Override
public List<Filmtype> getAll() {
session.beginTransaction();
List<Filmtype> list=session.createQuery("from Filmtype").list();
session.getTransaction().commit();
return list;
}

@Override
public Filmtype findById(int id) {
session.beginTransaction();
Filmtype filmType=(Filmtype) session.get(Filmtype.class, id);
session.getTransaction().commit();
return filmType;
}

@Override
public void delete(Filmtype object) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void update(Filmtype object) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void add(Filmtype object) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
Loading

0 comments on commit ec26cbc

Please sign in to comment.