mirror of
https://github.com/skogaby/butterfly.git
synced 2026-04-25 07:59:02 -05:00
Make a model and DAO for PCBs on the network
This commit is contained in:
parent
d5275fd12d
commit
67f541c4f4
|
|
@ -34,6 +34,7 @@ dependencies {
|
|||
|
||||
// Hibernate, SQL support
|
||||
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.0.Final'
|
||||
compile group: 'org.hibernate', name: 'hibernate-java8', version: '5.4.0.Final'
|
||||
compile group: 'org.springframework', name: 'spring-orm', version: '5.1.3.RELEASE'
|
||||
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.25.2'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package com.buttongames.butterfly.hibernate.dao.impl;
|
||||
|
||||
import com.buttongames.butterfly.hibernate.dao.AbstractHibernateDao;
|
||||
import com.buttongames.butterfly.model.ButterflyPcb;
|
||||
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 <code>ButterflyPcb</code> objects in the database.
|
||||
* @author skogaby (skogabyskogaby@gmail.com)
|
||||
*/
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
@Repository
|
||||
public class ButterflyPcbDao extends AbstractHibernateDao<ButterflyPcb> {
|
||||
|
||||
@Autowired
|
||||
public ButterflyPcbDao(final SessionFactory sessionFactory) {
|
||||
super(sessionFactory);
|
||||
setClazz(ButterflyPcb.class);
|
||||
}
|
||||
}
|
||||
143
src/main/java/com/buttongames/butterfly/model/ButterflyPcb.java
Normal file
143
src/main/java/com/buttongames/butterfly/model/ButterflyPcb.java
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
package com.buttongames.butterfly.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Externalizable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* Model class that represents a machine / PCB on the network.
|
||||
* @author skogaby (skogabyskogaby@gmail.com)
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "machines")
|
||||
public class ButterflyPcb implements Externalizable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID of the machine, primary key.
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id")
|
||||
private long id;
|
||||
|
||||
/**
|
||||
* The user this machine belongs to.
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id")
|
||||
private ButterflyUser user;
|
||||
|
||||
/**
|
||||
* The PCBID string for this machine.
|
||||
*/
|
||||
@Column(name = "pcbid")
|
||||
private String pcbId;
|
||||
|
||||
/**
|
||||
* The date and time this machine was registered.
|
||||
*/
|
||||
@Column(name = "register_time")
|
||||
private LocalDateTime registerTime;
|
||||
|
||||
/**
|
||||
* Whether this machine is enabled.
|
||||
*/
|
||||
@Column(name = "enabled")
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* The port to use for this machine.
|
||||
*/
|
||||
@Column(name = "port")
|
||||
private int port;
|
||||
|
||||
public ButterflyPcb() { }
|
||||
|
||||
public ButterflyPcb(final ButterflyUser user, final String pcbId, final LocalDateTime registerTime,
|
||||
final boolean enabled, final int port) {
|
||||
this.user = user;
|
||||
this.pcbId = pcbId;
|
||||
this.registerTime = registerTime;
|
||||
this.enabled = enabled;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
out.writeLong(this.id);
|
||||
out.writeObject(this.user);
|
||||
out.writeUTF(this.pcbId);
|
||||
out.writeObject(this.registerTime);
|
||||
out.writeBoolean(this.enabled);
|
||||
out.writeInt(this.port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
|
||||
this.setId(in.readLong());
|
||||
this.setUser((ButterflyUser) in.readObject());
|
||||
this.setPcbId(in.readUTF());
|
||||
this.setRegisterTime((LocalDateTime) in.readObject());
|
||||
this.setEnabled(in.readBoolean());
|
||||
this.setPort(in.readInt());
|
||||
}
|
||||
|
||||
private void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ButterflyUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(ButterflyUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPcbId() {
|
||||
return pcbId;
|
||||
}
|
||||
|
||||
public void setPcbId(String pcbId) {
|
||||
this.pcbId = pcbId;
|
||||
}
|
||||
|
||||
public LocalDateTime getRegisterTime() {
|
||||
return registerTime;
|
||||
}
|
||||
|
||||
public void setRegisterTime(LocalDateTime registerTime) {
|
||||
this.registerTime = registerTime;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ public class ButterflyUser implements Externalizable {
|
|||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id")
|
||||
private long userId;
|
||||
private long id;
|
||||
|
||||
/**
|
||||
* The user's card PIN.
|
||||
|
|
@ -37,9 +37,7 @@ public class ButterflyUser implements Externalizable {
|
|||
@Column(name = "pin")
|
||||
private String pin;
|
||||
|
||||
public ButterflyUser() {
|
||||
|
||||
}
|
||||
public ButterflyUser() { }
|
||||
|
||||
public ButterflyUser(final String pin) {
|
||||
this.pin = pin;
|
||||
|
|
@ -47,18 +45,22 @@ public class ButterflyUser implements Externalizable {
|
|||
|
||||
@Override
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
out.writeLong(this.userId);
|
||||
out.writeLong(this.id);
|
||||
out.writeUTF(this.pin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
|
||||
this.userId = in.readLong();
|
||||
this.pin = in.readUTF();
|
||||
this.setId(in.readLong());
|
||||
this.setPin(in.readUTF());
|
||||
}
|
||||
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
private void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getPin() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.buttongames.butterfly.spring.configuration;
|
||||
|
||||
import com.buttongames.butterfly.hibernate.dao.impl.ButterflyPcbDao;
|
||||
import com.buttongames.butterfly.hibernate.dao.impl.ButterflyUserDao;
|
||||
import com.buttongames.butterfly.util.PathUtils;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
|
@ -80,4 +81,9 @@ public class HibernateConfiguration {
|
|||
public ButterflyUserDao butterflyUserDao(final SessionFactory sessionFactory) {
|
||||
return new ButterflyUserDao(sessionFactory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ButterflyPcbDao butterflyPcbDao(final SessionFactory sessionFactory) {
|
||||
return new ButterflyPcbDao(sessionFactory);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user