package com.ruanko_android.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.CacheMode;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.connection.ConnectionProvider;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.ruanko_android.entity.*;
public class UserDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(UserDAO.class);
public List login(String loginName, String loginPass) {
log.debug("finding all UserDAO instances");
try {
String queryString = "from User where userId='" + loginName
+ "' and password='" + loginPass + "'";
Session session = HibernateSessionFactory.getSession();
List lt = getSession().createQuery(queryString).list();
if (lt.isEmpty() == false) {
Transaction trans = session.beginTransaction();
User user=(User) lt.get(0);
user.setOnlineFlag(1);
session.update(user);
trans.commit();
lt=session.createQuery(queryString).list();
session.close();
// String queryString2 = "from User where onlineflag=1";
// Session session2 = HibernateSessionFactory.getSession();
// List lt2 = getSession().createQuery(queryString2).list();
// boolean bool=lt2.isEmpty();
}
return lt;
} catch (Exception err) {
err.printStackTrace();
}
return null;
}
public List regist(String loginName, String loginPass, String trueName,
String sex) {
// getSession().clear();
// getHibernateTemplate().clear();
log.debug("finding all AccountDAO instances");
List lt = null;
String queryString = "from User where userid='" + loginName + "'";
lt = getSession().createQuery(queryString).list();
if (lt.isEmpty() == true) {
try {
// String registString = "insert into user values ('" + loginName
// + "','" + loginPass + "','" + trueName + "','" + sex
// + "',0,0,null)";
Session session =(Session) this.getSession();
Transaction trans=session.beginTransaction();
User user = new User();
user.setUserId(loginName);
user.setPassword(loginPass);
user.setUserName(trueName);
user.setSex(sex);
user.setOnlineFlag(0);
user.setDeleteFlag(0);
session.save(user);
trans.commit();
lt = getSession().createQuery(queryString).list();
session.close();
return lt;
} catch (Exception err) {
err.printStackTrace();
}
}
return null;
}
public void logout(String loginName) {
log.debug("finding all UserDAO instances");
try {
String queryString = "from User where userId='" + loginName
+ "'";
Session session = HibernateSessionFactory.getSession();
List lt = getSession().createQuery(queryString).list();
if (lt.isEmpty() == false) {
Transaction trans = session.beginTransaction();
User user=(User) lt.get(0);
user.setOnlineFlag(0);
session.update(user);
trans.commit();
// String queryString2 = "from User where onlineflag=1";
// Session session2 = HibernateSessionFactory.getSession();
// List lt2 = getSession().createQuery(queryString2).list();
// boolean bool=lt2.isEmpty();
session.clear();
session.close();
}
} catch (Exception err) {
err.printStackTrace();
}
}
}
- 1
- 2
前往页