diff --git a/.gitignore b/.gitignore index 1420ed0..9787819 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ gradle-app.setting !gradle-wrapper.jar .gradletasknamecache /bin/ +.DS_Store # vscode stuff .project diff --git a/src/main/java/com/buttongames/butterfly/hibernate/dao/impl/ButterflyUserDao.java b/src/main/java/com/buttongames/butterfly/hibernate/dao/impl/ButterflyUserDao.java new file mode 100644 index 0000000..7367b1a --- /dev/null +++ b/src/main/java/com/buttongames/butterfly/hibernate/dao/impl/ButterflyUserDao.java @@ -0,0 +1,24 @@ +package com.buttongames.butterfly.hibernate.dao.impl; + +import com.buttongames.butterfly.hibernate.dao.AbstractHibernateDao; +import com.buttongames.butterfly.model.ButterflyUser; +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Repository; + +/** + * DAO for interacting with ButterflyUser objects in the database. + * @author skogaby (skogabyskogaby@gmail.com) + */ +@Scope(BeanDefinition.SCOPE_PROTOTYPE) +@Repository +public class ButterflyUserDao extends AbstractHibernateDao { + + @Autowired + public ButterflyUserDao(final SessionFactory sessionFactory) { + super(sessionFactory); + setClazz(ButterflyUser.class); + } +} diff --git a/src/main/java/com/buttongames/butterfly/model/ButterflyUser.java b/src/main/java/com/buttongames/butterfly/model/ButterflyUser.java new file mode 100644 index 0000000..9cdc5ab --- /dev/null +++ b/src/main/java/com/buttongames/butterfly/model/ButterflyUser.java @@ -0,0 +1,54 @@ +package com.buttongames.butterfly.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; + +/** + * Model class for a user within the server. This user is tied to a person -- email + * address, password, etc. This user also has a PIN, which is applied across any + * and all cards they possess. ButterflyUser does *NOT* represent a profile for any + * particular game. + * @author skogaby (skogabyskogaby@gmail.com) + */ +@Entity +@Table(name = "users") +public class ButterflyUser implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * The integer user ID for this user. Serves as the primary key in the database. + */ + @Id + @GeneratedValue + @Column(name = "id") + private long userId; + + /** + * The user's card PIN. + */ + @Column(name = "pin") + private String pin; + + public ButterflyUser() { } + + public long getUserId() { + return userId; + } + + public void setUserId(int userId) { + this.userId = userId; + } + + public String getPin() { + return pin; + } + + public void setPin(String pin) { + this.pin = pin; + } +} diff --git a/src/main/java/com/buttongames/butterfly/spring/configuration/HibernateConfiguration.java b/src/main/java/com/buttongames/butterfly/spring/configuration/HibernateConfiguration.java index 406e531..482591c 100644 --- a/src/main/java/com/buttongames/butterfly/spring/configuration/HibernateConfiguration.java +++ b/src/main/java/com/buttongames/butterfly/spring/configuration/HibernateConfiguration.java @@ -1,6 +1,8 @@ package com.buttongames.butterfly.spring.configuration; +import com.buttongames.butterfly.hibernate.dao.impl.ButterflyUserDao; import com.buttongames.butterfly.util.PathUtils; +import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -73,4 +75,9 @@ public class HibernateConfiguration { return source; } + + @Bean + public ButterflyUserDao butterflyUserDao(final SessionFactory sessionFactory) { + return new ButterflyUserDao(sessionFactory); + } }