diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..cfca4ff --- /dev/null +++ b/pom.xml @@ -0,0 +1,195 @@ + + 4.0.0 + lottery + lottery + 0.0.1-SNAPSHOT + + src + + + resources + + **/*.java + + + + + + maven-compiler-plugin + 3.1 + + + + + + + + + + aopalliance + aopalliance + 1.0 + + + c3p0 + c3p0 + 0.9.1.2 + + + commons-beanutils + commons-beanutils + 1.9.2 + + + commons-codec + commons-codec + 1.9 + + + commons-collections + commons-collections + 3.2.1 + + + commons-fileupload + commons-fileupload + 1.3.1 + + + commons-io + commons-io + 2.4 + + + commons-lang + commons-lang + 2.6 + + + commons-logging + commons-logging + 1.2 + + + commons-net + commons-net + 3.3 + + + dom4j + dom4j + 1.6.1 + + + com.h2database + h2 + 1.4.181 + + + org.hibernate + hibernate-core + 3.6.10.Final + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + 1.0.1.Final + + + org.hibernate + hibernate-search-orm + 4.5.1.Final + + + org.hibernate + hibernate-validator + 4.3.2.Final + + + javax.transaction + jta + 1.1 + + + log4j + log4j + 1.2.17 + + + com.mchange + mchange-commons-java + 0.2.8 + + + org.slf4j + slf4j-api + 1.7.7 + + + org.slf4j + slf4j-log4j12 + 1.7.7 + + + org.springframework + spring-aop + 3.2.11.RELEASE + + + org.springframework + spring-beans + 3.2.11.RELEASE + + + org.springframework + spring-context + 3.2.11.RELEASE + + + org.springframework + spring-context-support + 3.2.11.RELEASE + + + org.springframework + spring-core + 3.2.11.RELEASE + + + org.springframework + spring-expression + 3.2.11.RELEASE + + + org.springframework + spring-jdbc + 3.2.11.RELEASE + + + org.springframework + spring-orm + 3.2.11.RELEASE + + + org.springframework + spring-test + 3.2.11.RELEASE + + + org.springframework + spring-tx + 3.2.11.RELEASE + + + org.springframework + spring-web + 3.2.11.RELEASE + + + org.springframework + spring-webmvc + 3.2.11.RELEASE + + + \ No newline at end of file diff --git a/src/com/lottery/Launcher.java b/src/com/lottery/Launcher.java index 297dd41..e4cd277 100644 --- a/src/com/lottery/Launcher.java +++ b/src/com/lottery/Launcher.java @@ -1,6 +1,5 @@ package com.lottery; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; /** @@ -8,7 +7,8 @@ */ public class Launcher { - public static void main(String[] args) { + @SuppressWarnings("resource") + public static void main(String[] args) { String contextPath[] = new String[]{"applicationContext.xml"}; new ClassPathXmlApplicationContext(contextPath); diff --git a/src/com/lottery/dao/LotteryAllDao.java b/src/com/lottery/dao/LotteryAllDao.java new file mode 100644 index 0000000..89003b9 --- /dev/null +++ b/src/com/lottery/dao/LotteryAllDao.java @@ -0,0 +1,15 @@ +package com.lottery.dao; + +import org.springframework.stereotype.Repository; + +import com.lottery.dao.hibernate3.SimpleHibernateDao; +import com.lottery.model.LotteryAny; + +/** + * @author houyi + * + */ +@Repository +public class LotteryAllDao extends SimpleHibernateDao { + +} diff --git a/src/com/lottery/dao/LotteryAnyDao.java b/src/com/lottery/dao/LotteryAnyDao.java new file mode 100644 index 0000000..a1c4a86 --- /dev/null +++ b/src/com/lottery/dao/LotteryAnyDao.java @@ -0,0 +1,15 @@ +package com.lottery.dao; + +import org.springframework.stereotype.Repository; + +import com.lottery.dao.hibernate3.SimpleHibernateDao; +import com.lottery.model.LotteryAny; + +/** + * @author houyi + * + */ +@Repository +public class LotteryAnyDao extends SimpleHibernateDao { + +} diff --git a/src/com/lottery/dao/hibernate3/BussinessEntity.java b/src/com/lottery/dao/hibernate3/BussinessEntity.java new file mode 100644 index 0000000..a5d794b --- /dev/null +++ b/src/com/lottery/dao/hibernate3/BussinessEntity.java @@ -0,0 +1,28 @@ +package com.lottery.dao.hibernate3; + +import java.io.Serializable; +import java.lang.annotation.Annotation; + +import javax.persistence.MappedSuperclass; +import javax.persistence.Table; + +/** + * + * @author houyi + * + */ +@MappedSuperclass +public abstract class BussinessEntity extends IdEntity implements Serializable { + + private static final long serialVersionUID = 8102619269019476594L; + + public String getTableName() { + for (Annotation anno : this.getClass().getAnnotations()) { + if (anno.annotationType().equals(Table.class)) { + return ((Table) anno).name(); + } + } + return null; + } + +} diff --git a/src/com/lottery/dao/hibernate3/IdEntity.java b/src/com/lottery/dao/hibernate3/IdEntity.java new file mode 100644 index 0000000..d8a51f7 --- /dev/null +++ b/src/com/lottery/dao/hibernate3/IdEntity.java @@ -0,0 +1,35 @@ +package com.lottery.dao.hibernate3; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +import org.hibernate.annotations.GenericGenerator; + +/** + * + * @author houyi + * + */ +@MappedSuperclass +public abstract class IdEntity implements Serializable{ + + private static final long serialVersionUID = 8784608728898957320L; + + @Id + @GenericGenerator(name = "generator", strategy = "uuid.hex") + @GeneratedValue(generator = "generator") + @Column(name = "ID", length=64) + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/src/com/lottery/dao/hibernate3/SimpleHibernateDao.java b/src/com/lottery/dao/hibernate3/SimpleHibernateDao.java new file mode 100644 index 0000000..9092c01 --- /dev/null +++ b/src/com/lottery/dao/hibernate3/SimpleHibernateDao.java @@ -0,0 +1,203 @@ +package com.lottery.dao.hibernate3; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +import org.hibernate.Criteria; +import org.hibernate.Hibernate; +import org.hibernate.Query; +import org.hibernate.SessionFactory; +import org.hibernate.criterion.CriteriaSpecification; +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Order; +import org.hibernate.criterion.Restrictions; +import org.hibernate.metadata.ClassMetadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.orm.hibernate3.support.HibernateDaoSupport; +import org.springframework.util.Assert; + +@SuppressWarnings("unchecked") +public class SimpleHibernateDao extends HibernateDaoSupport { + + protected Logger logger = LoggerFactory.getLogger(getClass()); + protected Class entityClass; + + @Autowired + public void init(SessionFactory sessionFactory) { + setSessionFactory(sessionFactory); + } + + public SimpleHibernateDao() { + this.entityClass = (Class) Object.class; + } + + public SimpleHibernateDao(final SessionFactory sessionFactory, final Class entityClass) { + setSessionFactory(sessionFactory); + this.entityClass = entityClass; + } + + public Serializable save(final T entity) { + logger.debug("save entity: {}", entity); + BussinessEntity bussinessEntity = (BussinessEntity) entity; + return getHibernateTemplate().save(bussinessEntity); + } + + public void saveOrUpdate(final T entity) { + Assert.notNull(entity, "entity can't be null"); + BussinessEntity bussinessEntity = (BussinessEntity) entity; + getHibernateTemplate().saveOrUpdate(bussinessEntity); + logger.debug("saveOrUpdate entity: {}", entity); + } + + public Object merge(final T entity) { + Assert.notNull(entity, "entity can't be null"); + logger.debug("merge entity: {}", entity); + return getHibernateTemplate().merge(entity); + } + + public void update(final T entity) { + Assert.notNull(entity, "entity can't be null"); + BussinessEntity bussinessEntity = (BussinessEntity) entity; + getHibernateTemplate().update(bussinessEntity); + logger.debug("update entity: {}", entity); + } + + public void delete(final T entity) { + Assert.notNull(entity, "entity can't be null"); + getHibernateTemplate().delete(entity); + logger.debug("delete entity: {}", entity); + } + + public void delete(final PK id) { + Assert.notNull(id, "id can't be null"); + delete(get(id)); + logger.debug("delete entity {},id is {}", entityClass.getSimpleName(), id); + } + + public T get(final PK id) { + Assert.notNull(id, "id can't be null"); + return (T) getHibernateTemplate().load(entityClass, id); + } + + public List getAll() { + return find(); + } + + public List getAll(String orderBy, boolean isAsc) { + Criteria c = createCriteria(); + if (isAsc) { + c.addOrder(Order.asc(orderBy)); + } else { + c.addOrder(Order.desc(orderBy)); + } + return c.list(); + } + + public List findBy(final String propertyName, final Object value) { + Assert.hasText(propertyName, "propertyName can't be null"); + Criterion criterion = Restrictions.eq(propertyName, value); + return find(criterion); + } + + public T findUniqueBy(final String propertyName, final Object value) { + Assert.hasText(propertyName, "propertyName can't be null"); + Criterion criterion = Restrictions.eq(propertyName, value); + return (T) createCriteria(criterion).uniqueResult(); + } + + public List findByIds(List ids) { + return find(Restrictions.in(getIdName(), ids)); + } + + public List find(final String hql, final Object... values) { + return createQuery(hql, values).list(); + } + + public List find(final String hql, final Map values) { + return createQuery(hql, values).list(); + } + + public X findUnique(final String hql, final Object... values) { + return (X) createQuery(hql, values).uniqueResult(); + } + + public X findUnique(final String hql, final Map values) { + return (X) createQuery(hql, values).uniqueResult(); + } + + public int batchExecute(final String hql, final Object... values) { + return createQuery(hql, values).executeUpdate(); + } + + public int batchExecute(final String hql, final Map values) { + return createQuery(hql, values).executeUpdate(); + } + + public Query createQuery(final String queryString, final Object... values) { + Assert.hasText(queryString, "queryString can't be null"); + Query query = getSessionFactory().getCurrentSession().createQuery(queryString); + if (values != null) { + int k = 0; + for (int i = 0; i < values.length; i++) { + if (!"".equals(values[i]) && null != values[i]) { + query.setParameter(k, values[i]); + k++; + } + } + } + return query; + } + + public Query createQuery(final String queryString, final Map values) { + Assert.hasText(queryString, "queryString can't be null"); + Query query = getSessionFactory().getCurrentSession().createQuery(queryString); + if (values != null) { + query.setProperties(values); + } + return query; + } + + public List find(final Criterion... criterions) { + return createCriteria(criterions).list(); + } + + public T findUnique(final Criterion... criterions) { + return (T) createCriteria(criterions).uniqueResult(); + } + + public Criteria createCriteria(final Criterion... criterions) { + Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(entityClass); + for (Criterion c : criterions) { + criteria.add(c); + } + return criteria; + } + + public void initEntity(T entity) { + Hibernate.initialize(entity); + } + + public void initEntity(List entityList) { + for (T entity : entityList) { + Hibernate.initialize(entity); + } + } + + public Query distinct(Query query) { + query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); + return query; + } + + public Criteria distinct(Criteria criteria) { + criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); + return criteria; + } + + public String getIdName() { + ClassMetadata meta = getSessionFactory().getClassMetadata(entityClass); + return meta.getIdentifierPropertyName(); + } +} \ No newline at end of file diff --git a/src/com/lottery/model/LotteryAll.java b/src/com/lottery/model/LotteryAll.java index e9e4a60..983f2e4 100644 --- a/src/com/lottery/model/LotteryAll.java +++ b/src/com/lottery/model/LotteryAll.java @@ -1,13 +1,90 @@ package com.lottery.model; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +import com.lottery.dao.hibernate3.BussinessEntity; + /** * Created by mmzz on 2014/10/7. */ +@Entity +@Table(name = "LOTTERY_ALL") +public class LotteryAll extends BussinessEntity{ + + private static final long serialVersionUID = 5934041630191412511L; + + @Column(name = "FRONT_ONE") + private Integer front_one; + + @Column(name = "FRONT_TWO") + private Integer front_two; + + @Column(name = "FRONT_THREE") + private Integer front_three; + + @Column(name = "FRONT_FOUR") + private Integer front_four; + + @Column(name = "FRONT_FIVE") + private Integer front_five; + + @Column(name = "STATUS") + private String status; + + @OneToMany(mappedBy = "lotteryAll") + private List lotteryAnys; + + public Integer getFront_one() { + return front_one; + } + + public void setFront_one(Integer front_one) { + this.front_one = front_one; + } + + public Integer getFront_two() { + return front_two; + } + + public void setFront_two(Integer front_two) { + this.front_two = front_two; + } + + public Integer getFront_three() { + return front_three; + } + + public void setFront_three(Integer front_three) { + this.front_three = front_three; + } + + public Integer getFront_four() { + return front_four; + } -public class LotteryAll { + public void setFront_four(Integer front_four) { + this.front_four = front_four; + } + public Integer getFront_five() { + return front_five; + } + public void setFront_five(Integer front_five) { + this.front_five = front_five; + } + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } } diff --git a/src/com/lottery/model/LotteryAny.java b/src/com/lottery/model/LotteryAny.java index e837c8b..c1dce88 100644 --- a/src/com/lottery/model/LotteryAny.java +++ b/src/com/lottery/model/LotteryAny.java @@ -1,7 +1,125 @@ package com.lottery.model; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import com.lottery.dao.hibernate3.BussinessEntity; + /** * Created by mmzz on 2014/10/7. */ -public class LotteryAny { +@Entity +@Table(name = "LOTTERY_ANY") +public class LotteryAny extends BussinessEntity { + + private static final long serialVersionUID = -2301485271595947726L; + + @Column(name = "NO") + private Integer no; + + @Column(name = "FRONT_ONE") + private Integer front_one; + + @Column(name = "FRONT_TWO") + private Integer front_two; + + @Column(name = "FRONT_THREE") + private Integer front_three; + + @Column(name = "FRONT_FOUR") + private Integer front_four; + + @Column(name = "FRONT_FIVE") + private Integer front_five; + + @Column(name = "BEHIND_ONE") + private Integer behind_one; + + @Column(name = "BEHIND_TWO") + private Integer behind_two; + + @Column(name = "CREATED_DATE") + private Date created_date; + + @ManyToOne + @JoinColumn(name = "LOTTERY_ID") + private LotteryAll lotteryAll; + + public Integer getNo() { + return no; + } + + public void setNo(Integer no) { + this.no = no; + } + + public Integer getFront_one() { + return front_one; + } + + public void setFront_one(Integer front_one) { + this.front_one = front_one; + } + + public Integer getFront_two() { + return front_two; + } + + public void setFront_two(Integer front_two) { + this.front_two = front_two; + } + + public Integer getFront_three() { + return front_three; + } + + public void setFront_three(Integer front_three) { + this.front_three = front_three; + } + + public Integer getFront_four() { + return front_four; + } + + public void setFront_four(Integer front_four) { + this.front_four = front_four; + } + + public Integer getFront_five() { + return front_five; + } + + public void setFront_five(Integer front_five) { + this.front_five = front_five; + } + + public Integer getBehind_one() { + return behind_one; + } + + public void setBehind_one(Integer behind_one) { + this.behind_one = behind_one; + } + + public Integer getBehind_two() { + return behind_two; + } + + public void setBehind_two(Integer behind_two) { + this.behind_two = behind_two; + } + + public Date getCreated_date() { + return created_date; + } + + public void setCreated_date(Date created_date) { + this.created_date = created_date; + } + } diff --git a/src/com/lottery/service/LotteryAllService.java b/src/com/lottery/service/LotteryAllService.java new file mode 100644 index 0000000..af17d5e --- /dev/null +++ b/src/com/lottery/service/LotteryAllService.java @@ -0,0 +1,16 @@ +package com.lottery.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.lottery.dao.LotteryAllDao; + +/** + * @author houyi + * + */ +@Service +public class LotteryAllService { + @Autowired + private LotteryAllDao lotteryAllDao; +} diff --git a/src/com/lottery/service/LotteryAnyService.java b/src/com/lottery/service/LotteryAnyService.java new file mode 100644 index 0000000..534d80d --- /dev/null +++ b/src/com/lottery/service/LotteryAnyService.java @@ -0,0 +1,16 @@ +package com.lottery.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.lottery.dao.LotteryAnyDao; + +/** + * @author houyi + * + */ +@Service +public class LotteryAnyService { + @Autowired + private LotteryAnyDao lotteryAnyDao; +} diff --git a/src/com/lottery/ui/MainUI.java b/src/com/lottery/ui/MainUI.java index da2da46..8ae72c8 100644 --- a/src/com/lottery/ui/MainUI.java +++ b/src/com/lottery/ui/MainUI.java @@ -9,7 +9,8 @@ public class MainUI extends JFrame { - private JPanel contentPane; + private static final long serialVersionUID = -2089179114014597392L; + private JPanel contentPane; /** * Launch the application. @@ -62,11 +63,11 @@ public MainUI() { importBtn.setPreferredSize(new Dimension(60, 30)); toolBar.add(importBtn); - JComboBox comboBox_1 = new JComboBox(); + JComboBox comboBox_1 = new JComboBox(); comboBox_1.setPreferredSize(new Dimension(400, 30)); toolBar.add(comboBox_1); - JComboBox comboBox = new JComboBox(); + JComboBox comboBox = new JComboBox(); comboBox.setPreferredSize(new Dimension(400, 30)); toolBar.add(comboBox); }