Skip to content

Commit

Permalink
Fixes #78.
Browse files Browse the repository at this point in the history
Attribute tables have been changed, no more messy multi-column primary keys. Attrid = primary key, and there's a unique index on
the fields I want.
Queries changed.
  • Loading branch information
maartenl committed Jan 29, 2019
1 parent b7f390c commit 0ffa4d8
Show file tree
Hide file tree
Showing 12 changed files with 396 additions and 715 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ public void setAttribute(String name, String value)
Charattribute attr = getCharattribute(name);
if (attr == null)
{
attr = new Charattribute(name, getName());
attr = new Charattribute(name, this);
attr.setPerson(this);
}
attr.setValue(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@

/**
* An attribute interface, containing name, value, value type.
*
* @author maartenl
*/
public interface Attribute
{
public String getName();

public String getValue();
public Long getAttributeId();

public String getName();

public String getValue();

public void setValue(String value);
public void setValue(String value);

public String getValueType();
public String getValueType();

public void setValueType(String valueType);
public void setValueType(String valueType);
}
241 changes: 120 additions & 121 deletions karchangame/src/main/java/mmud/database/entities/game/Charattribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
Expand All @@ -38,128 +38,127 @@
@Entity
@Table(name = "mm_charattributes")
@NamedQueries(
{
@NamedQuery(name = "Charattribute.findAll", query = "SELECT c FROM Charattribute c"),
@NamedQuery(name = "Charattribute.findByName", query = "SELECT c FROM Charattribute c WHERE c.charattributePK.name = :name"),
@NamedQuery(name = "Charattribute.findByValueType", query = "SELECT c FROM Charattribute c WHERE c.valueType = :valueType"),
@NamedQuery(name = "Charattribute.findByCharname", query = "SELECT c FROM Charattribute c WHERE c.charattributePK.charname = :charname")
})
{
@NamedQuery(name = "Charattribute.findAll", query = "SELECT c FROM Charattribute c"),
@NamedQuery(name = "Charattribute.findByName", query = "SELECT c FROM Charattribute c WHERE c.name = :name"),
@NamedQuery(name = "Charattribute.findByValueType", query = "SELECT c FROM Charattribute c WHERE c.valueType = :valueType")
})
public class Charattribute implements Serializable, Attribute
{
private static final long serialVersionUID = 1L;
@EmbeddedId
protected CharattributePK charattributePK;
@Lob
@Size(max = 65535)
@Column(name = "value")
private String value;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 20)
@Column(name = "value_type")
private String valueType;
@JoinColumn(name = "charname", referencedColumnName = "name", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Person person;

public Charattribute()
{
}

public Charattribute(CharattributePK charattributePK)
{
this.charattributePK = charattributePK;
}

public Charattribute(CharattributePK charattributePK, String valueType)
{
this.charattributePK = charattributePK;
this.valueType = valueType;
}

public Charattribute(String name, String charname)
{
this.charattributePK = new CharattributePK(name, charname);
}

public CharattributePK getCharattributePK()
{
return charattributePK;
}

public void setCharattributePK(CharattributePK charattributePK)
{
this.charattributePK = charattributePK;
}

@Override
public String getName()
{
return charattributePK.getName();
}

@Override
public String getValue()
{
return value;
}

@Override
public void setValue(String value)
{
this.value = value;
}

@Override
public String getValueType()
{
return valueType;
}

@Override
public void setValueType(String valueType)
{
this.valueType = valueType;
}

public Person getPerson()
{
return person;
}

public void setPerson(Person person)
{
this.person = person;
}

@Override
public int hashCode()
{
int hash = 0;
hash += (charattributePK != null ? charattributePK.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object)
{
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Charattribute))
{
return false;
}
Charattribute other = (Charattribute) object;
if ((this.charattributePK == null && other.charattributePK != null) || (this.charattributePK != null && !this.charattributePK.equals(other.charattributePK)))
{
return false;
}
return true;
}

@Override
public String toString()
{
return "mmud.database.entities.game.Charattribute[ charattributePK=" + charattributePK + " ]";
}
private static final long serialVersionUID = 1L;

@Id
@Basic(optional = false)
@NotNull
@Column(name = "attrid")
private Long attributeId;

@Basic(optional = false)
@NotNull
@Size(min = 1, max = 32)
@Column(name = "name")
private String name;

@Lob
@Size(max = 65535)
@Column(name = "value")
private String value;

@Basic(optional = false)
@NotNull
@Size(min = 1, max = 20)
@Column(name = "value_type")
private String valueType;

@JoinColumn(name = "charname", referencedColumnName = "name", nullable = false)
@ManyToOne(optional = false)
private Person person;

public Charattribute()
{
}

public Charattribute(String name, Person person)
{
this.name = name;
this.person = person;
}

@Override
public Long getAttributeId()
{
return attributeId;
}

@Override
public String getName()
{
return name;
}

@Override
public String getValue()
{
return value;
}

@Override
public void setValue(String value)
{
this.value = value;
}

@Override
public String getValueType()
{
return valueType;
}

@Override
public void setValueType(String valueType)
{
this.valueType = valueType;
}

public Person getPerson()
{
return person;
}

public void setPerson(Person person)
{
this.person = person;
}

@Override
public int hashCode()
{
int hash = 0;
hash += (attributeId != null ? attributeId.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object)
{
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Charattribute))
{
return false;
}
Charattribute other = (Charattribute) object;
if ((this.attributeId == null && other.attributeId != null) || (this.attributeId != null && !this.attributeId.equals(other.attributeId)))
{
return false;
}
return true;
}

@Override
public String toString()
{
return "mmud.database.entities.game.Charattribute[ attributeId=" + attributeId + " ]";
}

}
Loading

0 comments on commit 0ffa4d8

Please sign in to comment.