-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from dangthai121200/connectdatabase
Connectdatabase
- Loading branch information
Showing
17 changed files
with
930 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
Oops, something went wrong.