/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.ssh.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.ssh.struts.form.LoginForm;
/**
* MyEclipse Struts
* Creation date: 09-30-2009
*
* XDoclet definition:
* @struts.action path="/login" name="loginForm" input="/login.jsp" validate="true"
*/
public class LoginAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
return null;
}
}
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.ssh.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.web.struts.ActionSupport;
import com.ssh.hibernate.TabClient;
import com.ssh.hibernate.TabClientDAO;
import com.ssh.struts.form.RegisterForm;
/**
* MyEclipse Struts Creation date: 09-30-2009
*
* XDoclet definition:
*
* @struts.action path="/register" name="registerForm" input="/register.jsp"
* validate="true"
*/
public class RegisterAction extends ActionSupport {
/*
* Generated Methods
*/
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
RegisterForm registerForm = (RegisterForm) form;
int flag = 0;
String userid = registerForm.getUserid();
String username = registerForm.getUsername();
String password = registerForm.getPassword();
Integer role = registerForm.getRole();
Integer system_user = registerForm.getSystem_use();
String email = registerForm.getEmail();
ApplicationContext ac = getWebApplicationContext();
TabClientDAO clientDAO = (TabClientDAO) ac.getBean("clientDAO");
TabClient client = (TabClient) ac.getBean("client");
client.setUserid(userid);
client.setUsername(username);
client.setPassword(password);
client.setRole(role);
client.setSystemUse(system_user);
client.setEmail(email);
try {
clientDAO.save(client);
flag = 1;
} catch (Exception e) {
e.printStackTrace();
}
if (flag == 1) {
return mapping.findForward("success");
} else {
return mapping.findForward("failure");
}
}
}
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.ssh.struts.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* MyEclipse Struts
* Creation date: 09-30-2009
*
* XDoclet definition:
* @struts.form name="loginForm"
*/
public class LoginForm extends ActionForm {
/*
* Generated fields
*/
/** password property */
private String password;
/** userid property */
private String userid;
/*
* Generated Methods
*/
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
/**
* Returns the password.
* @return String
*/
public String getPassword() {
return password;
}
/**
* Set the password.
* @param password The password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* Returns the userid.
* @return String
*/
public String getUserid() {
return userid;
}
/**
* Set the userid.
* @param userid The userid to set
*/
public void setUserid(String userid) {
this.userid = userid;
}
}
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.ssh.struts.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* MyEclipse Struts Creation date: 09-30-2009
*
* XDoclet definition:
*
* @struts.form name="registerForm"
*/
public class RegisterForm extends ActionForm {
/*
* Generated fields
*/
/** system_use property */
private Integer system_use;
/** password property */
private String password;
/** userid property */
private String userid;
/** username property */
private String username;
/** email property */
private String email;
/** role property */
private Integer role;
/*
* Generated Methods
*/
/**
* Method validate
*
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
/**
* Method reset
*
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
/**
* Returns the system_use.
*
* @return Integer
*/
public Integer getSystem_use() {
return system_use;
}
/**
* Set the system_use.
*
* @param system_use
* The system_use to set
*/
public void setSystem_use(Integer system_use) {
this.system_use = system_use;
}
/**
* Returns the password.
*
* @return String
*/
public String getPassword() {
return password;
}
/**
* Set the password.
*
* @param password
* The password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* Returns the userid.
*
* @return String
*/
public String getUserid() {
return userid;
}
/**
* Set the userid.
*
* @param userid
* The userid to set
*/
public void setUserid(String userid) {
this.userid = userid;
}
/**
* Returns the username.
*
* @return String
*/
public String getUsername() {
return username;
}
/**
* Set the username.
*
* @param username
* The username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* Returns the email.
*
* @return String
*/
public String getEmail() {
return email;
}
/**
* Set the email.
*
* @param email
* The email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* Returns the role.
*
* @return Integer
*/
public Integer getRole() {
return role;
}
/**
* Set the role.
*
* @param role
* The role to set
*/
public void setRole(Integer role) {
this.role = role;
}
}
package com.ssh.hibernate.factory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.AnnotationConfiguration;
/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html }.
*/
public class HibernateSessionFactory {
/**
* Location of hibernate.cfg.xml file.
* Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is
* in the default package. Use #setConfigFile() to update
* the location of the configuration file for the current session.
*/
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static Configuration configuration = new AnnotationConfiguration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
return session;
}
/**
* Rebuild hibernate session factory
*
*/
public static void rebuildSessionFactory() {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
/**
* return session factory
*
*/
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* return session factory
*
* session factory will be rebuilded in the next call
*/
public static void setConfigFile(String configFile) {
HibernateSessionFactory.configFile = configFile;
sessionFactory = null;
}
/**
* return hibernate configuration
*
*/
public static Configuration getConfiguration() {
return configuration;
}
}
package com.ssh.hibernate;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
/**
* AbstractTabClient entity provides the base persistence definition of the
* TabClient entity. @author MyEclipse Persistence Tools
*/
@MappedSuperclass
public abstract class AbstractTabClient implements java.io.Serializable {
// Fields
private String userid;
private String username;
private String password;
private Integer role;
private Integer systemUse;
private String email;
// Constructors
/** default constructor */
public AbstractTabClient() {
}
/** full constructor */
public AbstractTabClient(String userid, String username, String password,
Integer role, Integer systemUse, String email) {
this.userid = userid;
this.username = username;
this.password = password;
this.role = role;
this.systemUse = systemUse;
this.email = email;
}
// Property accessors
@Id
@Column(name = "userid", unique = true, nullable = false, length = 20)
public String getUserid() {
return this.userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
@Column(name = "username", nullable = false, length = 30)
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name = "password", nullable = false, length = 30)
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name = "role", nullable = false)
public Integer getRole() {
return this.role;
}
public void setRole(Integer role) {
this.role = role;
}
@Column(name = "system_use", nullable = false)
public Integer getSystemUse() {
return this.systemUse;
}
public void setSystemUse(Integer systemUse) {
this.systemUse = systemUse;
}
@Column(name = "email", nullable = false, length = 30)
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
}
package com.ssh.hibernate;
/**
* AbstractTUser entity provides the base persistence definition of the TUser
* entity. @author MyEclipse Persistence Tools
*/
public abstract class AbstractTUser implements java.io.Serializable {
// Fields
private String userid;
private String password;
// Constructors
/** default constructor */
public AbstractTUser() {
}
/** minimal constructor */
public AbstractTUser(String userid) {
this.userid = userid;
}
/** full constructor */
public AbstractTUser(String userid, String password) {
this.userid = userid;
this.password = password;
}
// Property accessors
public String getUserid() {
return this.userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.ssh.hibernate;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* TabClient entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "tab_client", schema = "dbo", catalog = "sql_client")
public class TabClient extends AbstractTabClient implements
java.io.Serializable {
// Constructors
/** default constructor */
public TabClient() {
}
/** full constructor */
public TabClient(String userid, String username, String password,
Integer role, Integer systemUse, String email) {
super(userid, username, password, role, systemUse, email);
}
}
package com.ssh.hibernate;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* A data access object (DAO) providing persistence and search support for
* TabClient entities. Transaction control of the save(), update() and delete()
* operations can directly support Spring container-managed transactions or they
* can be augmented to handle user-managed Spring transactions. Each of these
* methods provides additional information for how to configure it for the
* desired type of transaction control.
*
* @see com.ssh.hibernate.TabClient
* @author MyEclipse Persistence Tools
*/
public class TabClientDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(TabClientDAO.class);
// property constants
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public static final String ROLE = "role";
public static final String SYSTEM_USE = "systemUse";
public static final String EMAIL = "email";
protected void initDao() {
// do nothing
}
public void save(TabClient transientInstance) {
log.debug("saving TabClient instance");
try {
Transaction t = getSession().beginTransaction();
getHibernateTemplate().save(transientInstance);
t.commit();
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(TabClient persistentInstance) {
log.debug("deleting TabClient instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public TabClient findById(java.lang.String id) {
log.debug("getting TabClient instance with id: " + id);
try {
TabClient instance = (TabClient) getHibernateTemplate().get(
"com.ssh.hibernate.TabClient", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List<TabClient> findByExample(TabClient instance) {
log.debug("finding TabClient instance by example");
try {
List<TabClient> results = (List<TabClient>) getHibernateTemplate()
.findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding TabClient instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from TabClient as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List<TabClient> findByUsername(Object username) {
return findByProperty(USERNAME, username);
}
public List<TabClient> findByPassword(Object password) {
return findByProperty(PASSWORD, password);
}
public List<TabClient> findByRole(Object role) {
return findByProperty(ROLE, role);
}
public List<TabClient> findBySystemUse(Object systemUse) {
return findByProperty(SYSTEM_USE, systemUse);
}
public List<TabClient> findByEmail(Object email) {
return findByProperty(EMAIL, email);
}
public List findAll() {
log.debug("finding all TabClient instances");
try {
String queryString = "from TabClient";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public TabClient merge(TabClient detachedInstance) {
log.debug("merging TabClient instance");
try {
TabClient result = (TabClient) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(TabClient instance) {
log.debug("attaching dirty TabClient instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(TabClient instance) {
log.debug("attaching clean TabClient instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static TabClientDAO getFromApplicationContext(ApplicationContext ctx) {
return (TabClientDAO) ctx.getBean("TabClientDAO");
}
}
package com.ssh.hibernate;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* A data access object (DAO) providing persistence and search support for TUser
* entities. Transaction control of the save(), update() and delete() operations
* can directly support Spring container-managed transactions or they can be
* augmented to handle user-managed Spring transactions. Each of these methods
* provides additional information for how to configure it for the desired type
* of transaction control.
*
* @see com.ssh.hibernate.TUser
* @author MyEclipse Persistence Tools
*/
public class TUserDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(TUserDAO.class);
// property constants
public static final String PASSWORD = "password";
protected void initDao() {
// do nothing
}
public void save(TUser transientInstance) {
log.debug("saving TUser instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(TUser persistentInstance) {
log.debug("deleting TUser instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public TUser findById(java.lang.String id) {
log.debug("getting TUser instance with id: " + id);
try {
TUser instance = (TUser) getHibernateTemplate().get(
"com.ssh.hibernate.TUser", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(TUser instance) {
log.debug("finding TUser instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding TUser instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from TUser as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByPassword(Object password) {
return findByProperty(PASSWORD, password);
}
public List findAll() {
log.debug("finding all TUser instances");
try {
String queryString = "from TUser";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public TUser merge(TUser detachedInstance) {
log.debug("merging TUser instance");
try {
TUser result = (TUser) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(TUser instance) {
log.debug("attaching dirty TUser instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(TUser instance) {
log.debug("attaching clean TUser instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static TUserDAO getFromApplicationContext(ApplicationContext ctx) {
return (TUserDAO) ctx.getBean("TUserDAO");
}
}
package com.ssh.hibernate;
/**
* TUser entity. @author MyEclipse Persistence Tools
*/
public class TUser extends AbstractTUser implements java.io.Serializable {
// Constructors
/** default constructor */
public TUser() {
}
/** minimal constructor */
public TUser(String userid) {
super(userid);
}
/** full constructor */
public TUser(String userid, String password) {
super(userid, password);
}
}
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="SessionFactoryID"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="TabClientDAO" class="com.ssh.hibernate.TabClientDAO">
<property name="sessionFactory">
<ref bean="SessionFactoryID" />
</property>
</bean>
<bean id="client" class="com.ssh.hibernate.TabClient" abstract="false"
lazy-init="default" autowire="default" dependency-check="default">
</bean>
<bean id="clientDAO" class="com.ssh.hibernate.TabClientDAO"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="sessionFactory">
<ref bean="SessionFactoryID" />
</property>
</bean>
</beans>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
" http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<property name="connection.username">sa</property>
<property name="connection.url">
jdbc:sqlserver://localhost:1433;databaseName=sql_client
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="myeclipse.connection.profile">
SQL Server2005
</property>
<property name="hbm2ddl.auto">update</property>
<property name="connection.password">123</property>
<property name="connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<mapping class="com.ssh.hibernate.TabClient" />
</session-factory>