[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model ...
Christian Bauer
christian at hibernate.org
Wed Mar 7 13:37:35 EST 2007
User: cbauer
Date: 07/03/07 13:37:35
Added: examples/wiki/src/main/org/jboss/seam/wiki/core/model
UserImage.java Directory.java ImageMetaInfo.java
GlobalPreferences.java Document.java File.java
HistoricalNode.hbm.xml User.java Role.java
Node.java
Log:
Moved to hot-redeploy WAR build structure
Revision Changes Path
1.1 date: 2007/03/07 18:37:35; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/UserImage.java
Index: UserImage.java
===================================================================
package org.jboss.seam.wiki.core.model;
import org.jboss.seam.annotations.Name;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "USER_IMAGE")
@Name("userImage")
public class UserImage implements Serializable {
@Id
@GeneratedValue
@Column(name = "USER_IMAGE_ID")
private Long id;
@Version
@Column(name = "OBJ_VERSION")
protected Integer version;
@ManyToOne
@JoinColumn(name = "USER_ID")
private User user;
@Lob
@Column(name = "IMAGE_DATA")
private byte[] data;
@Column(name = "CONTENT_TYPE")
private String contentType;
@Column(name = "CREATED_ON", nullable = false, updatable = false)
private Date createdOn = new Date();
private UserImage() {}
public UserImage(User user, byte[] data, String contentType) {
this.user = user;
this.data = data;
this.contentType = contentType;
}
// Immutable properties
public Long getId() { return id; }
public Integer getVersion() { return version; }
public Date getCreatedOn() { return createdOn; }
public User getUser() { return user; }
public void setUser(User user) { this.user = user; }
public byte[] getData() { return data; }
public void setData(byte[] data) { this.data = data; }
public String getContentType() { return contentType; }
public void setContentType(String contentType) { this.contentType = contentType; }
}
1.1 date: 2007/03/07 18:37:35; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Directory.java
Index: Directory.java
===================================================================
package org.jboss.seam.wiki.core.model;
import javax.persistence.*;
@Entity
@DiscriminatorValue("DIRECTORY")
public class Directory extends Node {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DEFAULT_DOCUMENT_ID", nullable = true)
private Document defaultDocument;
public Directory() { super("New Directory"); }
public Directory(String name) {
super(name);
}
// Mutable properties
public Document getDefaultDocument() {
return defaultDocument;
}
public void setDefaultDocument(Document defaultDocument) {
this.defaultDocument = defaultDocument;
makeDirty();
}
public String toString() {
return getName();
}
public Directory getParent() {
return (Directory)super.getParent();
}
}
1.1 date: 2007/03/07 18:37:35; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/ImageMetaInfo.java
Index: ImageMetaInfo.java
===================================================================
package org.jboss.seam.wiki.core.model;
import javax.persistence.Embeddable;
import javax.persistence.Column;
@Embeddable
public class ImageMetaInfo {
@Column(name = "IMAGE_SIZE_X")
private int sizeX;
@Column(name = "IMAGE_SIZE_Y")
private int sizeY;
@Column(name = "IMAGE_THUMBNAIL")
private char thumbnail = 'A'; // Disable embedding by default, attach
public ImageMetaInfo() {}
public ImageMetaInfo(int sizeX, int sizeY, boolean embeddable, char thumbnail) {
this.sizeX = sizeX;
this.sizeY = sizeY;
this.thumbnail = thumbnail;
}
public int getSizeX() {
return sizeX;
}
public void setSizeX(int sizeX) {
this.sizeX = sizeX;
}
public int getSizeY() {
return sizeY;
}
public void setSizeY(int sizeY) {
this.sizeY = sizeY;
}
public char getThumbnail() {
return thumbnail;
}
public void setThumbnail(char thumbnail) {
this.thumbnail = thumbnail;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ImageMetaInfo that = (ImageMetaInfo) o;
if (sizeX != that.sizeX) return false;
if (sizeY != that.sizeY) return false;
if (thumbnail != that.thumbnail) return false;
return true;
}
public int hashCode() {
int result;
result = sizeX;
result = 31 * result + sizeY;
result = 31 * result + (int) thumbnail;
return result;
}
}
1.1 date: 2007/03/07 18:37:35; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/GlobalPreferences.java
Index: GlobalPreferences.java
===================================================================
package org.jboss.seam.wiki.core.model;
public class GlobalPreferences {
private String baseURL;
private URLRendering defaultURLRendering;
private String permlinkSuffix;
private String themeName;
private String newUserInRole;
private String passwordRegex;
private String activationCodeSalt;
private boolean defaultNewRevisionForEditedDocument;
public String getBaseURL() {
return baseURL;
}
public void setBaseURL(String baseURL) {
this.baseURL = baseURL;
}
public URLRendering getDefaultURLRendering() {
return defaultURLRendering;
}
public void setDefaultURLRendering(String enumName) {
defaultURLRendering = URLRendering.valueOf(enumName);
}
public String getPermlinkSuffix() {
return permlinkSuffix;
}
public void setPermlinkSuffix(String permlinkSuffix) {
this.permlinkSuffix = permlinkSuffix;
}
public String getThemeName() {
return themeName;
}
public void setThemeName(String themeName) {
this.themeName = themeName;
}
public String getNewUserInRole() {
return newUserInRole;
}
public void setNewUserInRole(String newUserInRole) {
this.newUserInRole = newUserInRole;
}
public String getPasswordRegex() {
return passwordRegex;
}
public void setPasswordRegex(String passwordRegex) {
this.passwordRegex = passwordRegex;
}
public String getActivationCodeSalt() {
return activationCodeSalt;
}
public void setActivationCodeSalt(String activationCodeSalt) {
this.activationCodeSalt = activationCodeSalt;
}
public boolean isDefaultNewRevisionForEditedDocument() {
return defaultNewRevisionForEditedDocument;
}
public void setDefaultNewRevisionForEditedDocument(boolean defaultNewRevisionForEditedDocument) {
this.defaultNewRevisionForEditedDocument = defaultNewRevisionForEditedDocument;
}
public enum URLRendering {
PERMLINK, WIKILINK
}
}
1.1 date: 2007/03/07 18:37:35; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Document.java
Index: Document.java
===================================================================
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Length;
import javax.persistence.*;
@Entity
@DiscriminatorValue("DOCUMENT")
public class Document extends Node {
@Column(name = "CONTENT")
@Length(min = 1, max = 32768)
private String content;
public Document() { super("New Document"); }
public Document(String name) {
super(name);
}
public Document(Document original) {
super(original);
this.content = original.content;
}
// Mutable properties
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
makeDirty();
}
public Directory getParent() {
return (Directory)super.getParent();
}
public void addChild(Node child) {
throw new UnsupportedOperationException("Documents can't have children");
}
public void removeChild(Node child) {
throw new UnsupportedOperationException("Documents can't have children");
}
public String toString() {
return getName();
}
public void rollback(Node revision) {
super.rollback(revision);
this.content = ((Document)revision).content;
}
}
1.1 date: 2007/03/07 18:37:35; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/File.java
Index: File.java
===================================================================
package org.jboss.seam.wiki.core.model;
import javax.persistence.Entity;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Column;
import javax.persistence.Lob;
import java.math.BigDecimal;
@Entity
@DiscriminatorValue("FILE")
public class File extends Node {
@Column(name = "FILENAME", length = 255)
private String filename;
@Column(name = "FILESIZE")
private int filesize;
@Lob
@Column(name = "FILEDATA")
private byte[] data;
@Column(name = "CONTENT_TYPE", length = 255)
private String contentType;
private ImageMetaInfo imageMetaInfo;
public File() { super("New File"); }
public File(String name) {
super(name);
}
// Mutable properties
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public int getFilesize() {
return filesize;
}
public void setFilesize(int filesize) {
this.filesize = filesize;
}
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
makeDirty();
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
makeDirty();
}
public ImageMetaInfo getImageMetaInfo() {
return imageMetaInfo;
}
public void setImageMetaInfo(ImageMetaInfo imageMetaInfo) {
this.imageMetaInfo = imageMetaInfo;
makeDirty();
}
public Directory getParent() {
return (Directory)super.getParent();
}
public void addChild(Node child) {
throw new UnsupportedOperationException("Files can't have children");
}
public void removeChild(Node child) {
throw new UnsupportedOperationException("Files can't have children");
}
public String toString() {
return getName();
}
public String getHumanReadableFilesize() {
// TODO: Yeah, that could be done smarter..
if (getFilesize() >= 1073741824) {
return new BigDecimal(getFilesize() / 1024 / 1024 / 1024) + " GiB";
}else if (getFilesize() >= 1048576) {
return new BigDecimal(getFilesize() / 1024 / 1024) + "MiB";
} else if (getFilesize() >= 1024) {
return new BigDecimal(getFilesize() / 1024) + " KiB";
} else {
return new BigDecimal(getFilesize()) + " Bytes";
}
}
}
1.1 date: 2007/03/07 18:37:35; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/HistoricalNode.hbm.xml
Index: HistoricalNode.hbm.xml
===================================================================
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Maps only properties we want to keep a history of.
-->
<hibernate-mapping package="org.jboss.seam.wiki.core.model" default-access="field">
<class name="Node" entity-name="HistoricalNode" abstract="true" table="NODE_HISTORY" polymorphism="explicit">
<id name="historicalNodeId" column="NODE_HISTORY_ID">
<generator class="native"/>
</id>
<discriminator column="NODE_TYPE" length="255"/>
<!-- Actual historical revision property -->
<property name="nodeId" column="NODE_ID" not-null="true" unique-key="unique_revision_per_node_id"/>
<property name="revision" column="NODE_REVISION" not-null="true" unique-key="unique_revision_per_node_id"/>
<property name="name" length="255" not-null="true" column="NAME"/>
<property name="wikiname" length="255" not-null="true" column="WIKINAME"/>
<property name="lastModifiedOn" column="LAST_MODIFIED_ON" type="timestamp" not-null="true"/>
<subclass name="Document" entity-name="HistoricalDocument" discriminator-value="DOCUMENT">
<property name="content" column="CONTENT" length="32768"/>
</subclass>
<subclass name="File" entity-name="HistoricalFile" discriminator-value="FILE">
<property name="filename" length="255" column="FILENAME"/>
<property name="filesize" column="FILESIZE"/>
<property name="data" type="binary" column="FILEDATA"/>
<property name="contentType" column="CONTENT_TYPE" length="255"/>
<component name="imageMetaInfo" class="ImageMetaInfo">
<property name="sizeX" column="IMAGE_SIZE_X"/>
<property name="sizeY" column="IMAGE_SIZE_Y"/>
<property name="thumbnail" column="IMAGE_THUMBNAIL"/>
</component>
</subclass>
</class>
</hibernate-mapping>
1.1 date: 2007/03/07 18:37:35; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/User.java
Index: User.java
===================================================================
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Pattern;
import org.hibernate.validator.Length;
import org.hibernate.validator.Email;
import javax.persistence.*;
import java.io.Serializable;
import java.util.*;
@Entity
@Table(name = "USERS")
public class User implements Serializable {
@Id @GeneratedValue
@Column(name = "USER_ID")
private Long id = null;
@Version
@Column(name = "OBJ_VERSION")
private int version = 0;
@Column(name = "FIRSTNAME", length = 63, nullable = false)
@NotNull
@Length(min = 3, max = 63)
@Pattern(regex="[a-zA-Z]+", message="First name must only contain letters")
private String firstname;
@Column(name = "LASTNAME", length = 63, nullable = false)
@NotNull
@Length(min = 3, max = 63)
@Pattern(regex="[a-zA-Z]+", message="Last name must only contain letters")
private String lastname;
@Column(name = "USERNAME", length = 16, nullable = false, unique = true)
@NotNull
@Length(min = 3, max = 16)
@Pattern(regex="[a-zA-Z]?[a-zA-Z0-9_]+",
message="Member name must start with a letter, and only contain letters, numbers or underscores")
private String username; // Unique and immutable
@Column(name = "PASSWORDHASH", length = 255, nullable = false)
private String passwordHash;
@Column(name = "EMAIL", length = 255, nullable = false)
@NotNull @Email
private String email;
@Column(name = "ACTIVATED", nullable = false)
private boolean activated = false;
@Column(name = "ACTIVATION_CODE", length = 255, nullable = true)
private String activationCode;
@Column(name = "CREATED_ON", nullable = false, updatable = false)
private Date createdOn = new Date();
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "USER_ROLE",
joinColumns = @JoinColumn(name = "USER_ID"),
inverseJoinColumns = @JoinColumn(name = "ROLE_ID")
)
@org.hibernate.annotations.Sort(type = org.hibernate.annotations.SortType.NATURAL)
private SortedSet<Role> roles = new TreeSet<Role>();
public User() {}
public User(String firstname, String lastname,
String username, String passwordHash, String email) {
this.firstname = firstname;
this.lastname = lastname;
this.username = username;
this.passwordHash = passwordHash;
this.email = email;
}
// Immutable properties
public Long getId() { return id; }
public Integer getVersion() { return version; }
public Date getCreatedOn() { return createdOn; }
// Mutable properties
public String getFirstname() { return firstname; }
public void setFirstname(String firstname) { this.firstname = firstname; }
public String getLastname() { return lastname; }
public void setLastname(String lastname) { this.lastname = lastname; }
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public String getPasswordHash() { return passwordHash; }
public void setPasswordHash(String passwordHash) { this.passwordHash = passwordHash; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
public boolean isActivated() { return activated; }
public void setActivated(boolean activated) { this.activated = activated; }
public String getActivationCode() { return activationCode; }
public void setActivationCode(String activationCode) { this.activationCode = activationCode; }
public SortedSet<Role> getRoles() {
return Collections.unmodifiableSortedSet(roles);
}
public void addRole(Role role) {
this.roles.add(role);
}
public void removeRole(Role role) {
this.roles.remove(role);
}
// Misc methods
public String toString() {
return "User ('" + getId() + "'), " +
"Username: '" + getUsername() + "'";
}
public Role getHighestRole() {
Role highestRole = roles.iterator().next();
for (Role role : roles)
if (role.getAccessLevel() > highestRole.getAccessLevel()) highestRole = role;
return highestRole;
}
}
1.1 date: 2007/03/07 18:37:35; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Role.java
Index: Role.java
===================================================================
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Length;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "ROLE")
public class Role implements Serializable, Comparable {
@Id
@GeneratedValue
@Column(name = "ROLE_ID")
private Long id = null;
@Version
@Column(name = "OBJ_VERSION")
private int version = 0;
@Column(name = "NAME", length = 255, nullable = false, unique = true)
private String name;
@Column(name = "DISPLAY_NAME", length = 255, nullable = false, unique = true)
@Length(min = 3, max = 40)
private String displayName;
@Column(name = "ACCESS_LEVEL", nullable = false, unique = true)
@org.hibernate.annotations.Check(
constraints = "ACCESS_LEVEL < 1000"
)
private int accessLevel;
@Column(name = "CREATED_ON", nullable = false, updatable = false)
private Date createdOn = new Date();
public Role() {}
public Role(String name, String displayName, int accessLevel) {
this.name = name;
this.displayName = displayName;
this.accessLevel = accessLevel;
}
// Immutable properties
public Long getId() { return id; }
public Integer getVersion() { return version; }
public Date getCreatedOn() { return createdOn; }
// Mutable properties
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getDisplayName() { return displayName; }
public void setDisplayName(String displayName) { this.displayName = displayName; }
public int getAccessLevel() { return accessLevel; }
public void setAccessLevel(int accessLevel) { this.accessLevel = accessLevel; }
public String toString() {
return "Role ('" + getId() + "'), " +
"Name: '" + getName() + "'";
}
public int compareTo(Object o) {
return getDisplayName().compareTo(((Role)o).getDisplayName());
}
}
1.1 date: 2007/03/07 18:37:35; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Node.java
Index: Node.java
===================================================================
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Length;
import org.hibernate.validator.Pattern;
import javax.persistence.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Date;
import java.io.Serializable;
@Entity
@Table(
name = "NODE",
uniqueConstraints = {
// Siblings in a directory can't have the same name
@UniqueConstraint(columnNames = {"PARENT_NODE_ID", "WIKINAME"}),
// Wikiname of a document needs to be unique within an area
@UniqueConstraint(columnNames = {"NODE_TYPE", "AREA_NR", "WIKINAME"})
}
)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name = "NODE_TYPE",
length = 255
)
public abstract class Node implements Serializable {
// Uses Hibernates ability to map the same class twice, see HistoricalNode.hbm.xml
@Transient
private Long historicalNodeId;
@Column(name = "NODE_REVISION", nullable = false)
private int revision = 0;
@Id
@GeneratedValue
@Column(name = "NODE_ID")
protected Long nodeId;
@Version
@Column(name = "OBJ_VERSION")
protected Integer version;
@Column(name = "NAME", length = 255, nullable = false)
@Length(min = 3, max = 255)
@Pattern(regex="[a-zA-Z]?.+", message="Name must start with a letter")
protected String name;
@Column(name = "WIKINAME", length = 255, nullable = false)
protected String wikiname;
@Column(name = "MENU_ITEM", nullable = false)
protected boolean menuItem;
@Column(name = "AREA_NR", nullable = false)
private Long areaNumber;
// Required EAGER loading, we cast this to 'Directory' sometimes and proxy wouldn't work
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "PARENT_NODE_ID", nullable = true, insertable = false, updatable = false)
protected Node parent;
@OneToMany(cascade = CascadeType.PERSIST)
@JoinColumn(name = "PARENT_NODE_ID", nullable = true)
@org.hibernate.annotations.IndexColumn(name = "NODE_POSITION")
// TODO: We are not really using this: @org.hibernate.annotations.Filter(name = "Node.onlyMenuItems")
@org.hibernate.annotations.BatchSize(size = 5)
private List<Node> children = new ArrayList<Node>();
@Column(name = "CREATED_ON", nullable = false, updatable = false)
private Date createdOn = new Date();
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CREATED_BY_USER_ID", nullable = false, updatable = false)
protected User createdBy;
@Column(name = "LAST_MODIFIED_ON")
protected Date lastModifiedOn;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "LAST_MODIFIED_BY_USER_ID")
protected User lastModifiedBy;
@Column(name = "WRITE_ACCESS_LEVEL", nullable = false)
protected int writeAccessLevel = 100;
@Column(name = "READ_ACCESS_LEVEL", nullable = false)
protected int readAccessLevel = 100;
public Node() {}
public Node(String name) {
this.name = name;
}
/**
* Creates copy for history archiving, increments originals revision.
* @param original The node to make a copy of
*/
public Node(Node original) {
if (original == null) return;
this.revision = original.revision;
this.nodeId = original.nodeId;
this.name = original.name;
this.wikiname = original.wikiname;
this.lastModifiedOn = original.lastModifiedOn;
}
// Immutable properties
public Long getId() { return nodeId; }
public Integer getVersion() { return version; }
public Date getCreatedOn() { return createdOn; }
public int getRevision() { return revision; }
public Long getHistoryId() { return historicalNodeId; }
// Mutable properties
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
makeDirty();
}
public String getWikiname() {
return wikiname;
}
public boolean isMenuItem() {
return menuItem;
}
public void setMenuItem(boolean menuItem) {
this.menuItem = menuItem;
}
public Long getAreaNumber() {
return areaNumber;
}
public void setAreaNumber(Long areaNumber) {
this.areaNumber = areaNumber;
}
public Node getParent() {
return parent;
}
public void setParent(Node parent) {
this.parent = parent;
}
public List<Node> getChildren() {
return children;
}
public void addChild(Node child) {
if (child.getParent() != null) child.getParent().getChildren().remove(child);
child.setParent(this);
this.getChildren().add(child);
}
public void removeChild(Node child) {
child.setParent(null);
this.getChildren().remove(child);
}
public User getCreatedBy() {
return createdBy;
}
public void setCreatedBy(User createdBy) {
this.createdBy = createdBy;
}
public Date getLastModifiedOn() {
return lastModifiedOn;
}
public void setLastModifiedOn(Date lastModifiedOn) {
this.lastModifiedOn = lastModifiedOn;
}
public User getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(User lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
// Misc methods
protected void makeDirty() {
setLastModifiedOn(new Date());
}
public Directory getArea() {
Node currentNode = this;
// TODO: This is hardcoding the "parentless parent" logic for the wiki root
while (currentNode.getParent() != null && currentNode.getParent().getParent() != null) {
currentNode = currentNode.getParent();
}
return (Directory)currentNode;
}
public void incrementRevision() {
revision++;
}
public boolean isHistoricalRevision() {
return historicalNodeId!=null;
}
public void rollback(Node revision) {
this.name = revision.name;
this.wikiname = revision.wikiname;
makeDirty();
}
}
More information about the jboss-cvs-commits
mailing list