[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model ...
Christian Bauer
christian at hibernate.org
Fri Aug 17 09:00:25 EDT 2007
User: cbauer
Date: 07/08/17 09:00:25
Modified: examples/wiki/src/main/org/jboss/seam/wiki/core/model
DatabaseObjects.hbm.xml Directory.java
LinkProtocol.java ImageMetaInfo.java Document.java
File.java Comment.java HistoricalNode.hbm.xml
User.java Role.java Feed.java Node.java
FeedEntry.java
Added: examples/wiki/src/main/org/jboss/seam/wiki/core/model
UserProfile.java
Removed: examples/wiki/src/main/org/jboss/seam/wiki/core/model
UserImage.java
Log:
Major refactoring of core data schema and some new features
Revision Changes Path
1.3 +100 -5 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/DatabaseObjects.hbm.xml
(In the diff below, changes in quantity of whitespace are not shown.)
Index: DatabaseObjects.hbm.xml
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/DatabaseObjects.hbm.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- DatabaseObjects.hbm.xml 21 Jun 2007 11:05:48 -0000 1.2
+++ DatabaseObjects.hbm.xml 17 Aug 2007 13:00:24 -0000 1.3
@@ -44,6 +44,15 @@
<database-object>
<create>
+ alter table NODE drop constraint FK_NODE_PARENT_NODE_ID;
+ alter table NODE add constraint FK_NODE_PARENT_NODE_ID foreign key (PARENT_NODE_ID) references NODE on delete cascade;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
+ </database-object>
+
+ <database-object>
+ <create>
alter table NODE drop constraint FK_NODE_LAST_MODIFIED_BY_USER_ID;
alter table NODE add constraint FK_NODE_LAST_MODIFIED_BY_USER_ID foreign key (LAST_MODIFIED_BY_USER_ID) references USERS on delete set null;
</create>
@@ -53,8 +62,26 @@
<database-object>
<create>
- alter table NODE drop constraint FK_DIRECTORY_DEFAULT_DOCUMENT_ID;
- alter table NODE add constraint FK_DIRECTORY_DEFAULT_DOCUMENT_ID foreign key (DEFAULT_DOCUMENT_ID) references NODE on delete set null;
+ alter table NODE_DIRECTORY drop constraint FK_DIRECTORY_DEFAULT_DOCUMENT_ID;
+ alter table NODE_DIRECTORY add constraint FK_DIRECTORY_DEFAULT_DOCUMENT_ID foreign key (DEFAULT_DOCUMENT_ID) references NODE on delete set null;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
+ </database-object>
+
+ <database-object>
+ <create>
+ alter table NODE_DOCUMENT drop constraint FK_NODE_DOCUMENT_DOCUMENT_ID;
+ alter table NODE_DOCUMENT add constraint FK_NODE_DOCUMENT_DOCUMENT_ID foreign key (DOCUMENT_ID) references NODE on delete cascade;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
+ </database-object>
+
+ <database-object>
+ <create>
+ alter table NODE_DIRECTORY drop constraint FK_NODE_DIRECTORY_DIRECTORY_ID;
+ alter table NODE_DIRECTORY add constraint FK_NODE_DIRECTORY_DIRECTORY_ID foreign key (DIRECTORY_ID) references NODE on delete cascade;
</create>
<drop></drop>
<dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
@@ -96,6 +123,14 @@
<dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
</database-object>
+ <database-object>
+ <create>
+ alter table USERS drop constraint FK_USER_USER_PROFILE_ID;
+ alter table USERS add constraint FK_USER_USER_PROFILE_ID foreign key (USER_PROFILE_ID) references USER_PROFILE on delete cascade;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
+ </database-object>
<database-object>
<create>
@@ -162,6 +197,22 @@
<database-object>
<create>
+ alter table NODE drop foreign key FK_NODE_PARENT_NODE_ID;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
+ </database-object>
+ <database-object>
+ <create>
+ alter table NODE
+ add constraint FK_NODE_PARENT_NODE_ID foreign key (PARENT_NODE_ID) references NODE (NODE_ID) on delete cascade;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
+ </database-object>
+
+ <database-object>
+ <create>
alter table NODE drop foreign key FK_NODE_LAST_MODIFIED_BY_USER_ID;
</create>
<drop></drop>
@@ -178,14 +229,44 @@
<database-object>
<create>
- alter table NODE drop foreign key FK_DIRECTORY_DEFAULT_DOCUMENT_ID;
+ alter table NODE_DIRECTORY drop foreign key FK_DIRECTORY_DEFAULT_DOCUMENT_ID;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
+ </database-object>
+ <database-object>
+ <create>
+ alter table NODE_DIRECTORY add constraint FK_DIRECTORY_DEFAULT_DOCUMENT_ID foreign key (DEFAULT_DOCUMENT_ID) references NODE (NODE_ID) on delete set null;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
+ </database-object>
+
+ <database-object>
+ <create>
+ alter table NODE_DOCUMENT drop foreign key FK_NODE_DOCUMENT_DOCUMENT_ID;
</create>
<drop></drop>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
- alter table NODE add constraint FK_DIRECTORY_DEFAULT_DOCUMENT_ID foreign key (DEFAULT_DOCUMENT_ID) references NODE (NODE_ID) on delete set null;
+ alter table NODE_DOCUMENT add constraint FK_NODE_DOCUMENT_DOCUMENT_ID foreign key (DOCUMENT_ID) references NODE (NODE_ID) on delete cascade;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
+ </database-object>
+
+ <database-object>
+ <create>
+ alter table NODE_DIRECTORY drop foreign key FK_NODE_DIRECTORY_DIRECTORY_ID;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
+ </database-object>
+ <database-object>
+ <create>
+ alter table NODE_DIRECTORY add constraint FK_NODE_DIRECTORY_DIRECTORY_ID foreign key (DIRECTORY_ID) references NODE (NODE_ID) on delete cascade;
</create>
<drop></drop>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
@@ -251,6 +332,20 @@
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
+ <database-object>
+ <create>
+ alter table USERS drop foreign key FK_USER_USER_PROFILE_ID;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
+ </database-object>
+ <database-object>
+ <create>
+ alter table USERS add constraint FK_USER_USER_PROFILE_ID foreign key (USER_PROFILE_ID) references USER_PROFILE (USER_PROFILE_ID) on delete cascade;
+ </create>
+ <drop></drop>
+ <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
+ </database-object>
<database-object>
<create>
1.8 +15 -9 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Directory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Directory.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Directory.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- Directory.java 27 Apr 2007 10:33:40 -0000 1.7
+++ Directory.java 17 Aug 2007 13:00:24 -0000 1.8
@@ -1,13 +1,27 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.seam.wiki.core.model;
import javax.persistence.*;
@Entity
@DiscriminatorValue("DIRECTORY")
+ at SecondaryTable(
+ name = "NODE_DIRECTORY",
+ pkJoinColumns = @PrimaryKeyJoinColumn(name = "DIRECTORY_ID")
+)
+ at org.hibernate.annotations.Table(
+ appliesTo = "NODE_DIRECTORY",
+ foreignKey = @org.hibernate.annotations.ForeignKey(name = "FK_NODE_DIRECTORY_DIRECTORY_ID")
+)
public class Directory extends Node {
@ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "DEFAULT_DOCUMENT_ID", nullable = true)
+ @JoinColumn(table = "NODE_DIRECTORY", name = "DEFAULT_DOCUMENT_ID", nullable = true)
@org.hibernate.annotations.ForeignKey(name = "FK_DIRECTORY_DEFAULT_DOCUMENT_ID")
private Document defaultDocument;
@@ -38,14 +52,6 @@
this.defaultDocument = defaultDocument;
}
- public String toString() {
- return getName();
- }
-
- public Directory getParent() {
- return (Directory)super.getParent();
- }
-
public Feed getFeed() {
return feed;
}
1.3 +9 -3 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/LinkProtocol.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LinkProtocol.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/LinkProtocol.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- LinkProtocol.java 19 Apr 2007 14:58:32 -0000 1.2
+++ LinkProtocol.java 17 Aug 2007 13:00:24 -0000 1.3
@@ -1,3 +1,9 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Length;
@@ -16,15 +22,15 @@
private Long id;
@Version
- @Column(name = "OBJ_VERSION")
+ @Column(name = "OBJ_VERSION", nullable = false)
protected Integer version;
- @Column(name = "PREFIX")
+ @Column(name = "PREFIX", nullable = false)
@Length(min = 2, max = 10)
@org.hibernate.validator.Pattern(regex="[a-zA-Z]+", message="Prefix must only contain letters")
private String prefix;
- @Column(name = "LINK")
+ @Column(name = "LINK", nullable = false)
@Length(min = 3, max = 1000)
private String link;
1.4 +6 -0 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/ImageMetaInfo.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ImageMetaInfo.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/ImageMetaInfo.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ImageMetaInfo.java 12 Jun 2007 17:51:00 -0000 1.3
+++ ImageMetaInfo.java 17 Aug 2007 13:00:24 -0000 1.4
@@ -1,3 +1,9 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.seam.wiki.core.model;
import javax.persistence.*;
1.13 +29 -11 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Document.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Document.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Document.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- Document.java 12 Jun 2007 12:29:59 -0000 1.12
+++ Document.java 17 Aug 2007 13:00:24 -0000 1.13
@@ -1,33 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Length;
import org.jboss.seam.wiki.core.search.annotations.Searchable;
import javax.persistence.*;
+import javax.persistence.Entity;
+import java.util.List;
@Entity
@DiscriminatorValue("DOCUMENT")
@org.hibernate.search.annotations.Indexed
@Searchable(description = "Documents")
@org.hibernate.annotations.BatchSize(size = 10)
+ at SecondaryTable(
+ name = "NODE_DOCUMENT",
+ pkJoinColumns = @PrimaryKeyJoinColumn(name = "DOCUMENT_ID")
+)
+ at org.hibernate.annotations.Table(
+ appliesTo = "NODE_DOCUMENT",
+ foreignKey = @org.hibernate.annotations.ForeignKey(name = "FK_NODE_DOCUMENT_DOCUMENT_ID")
+)
public class Document extends Node {
- @Column(name = "CONTENT")
+ @Column(table = "NODE_DOCUMENT", name = "CONTENT", nullable = false)
@Length(min = 0, max = 32768)
@Basic(fetch = FetchType.LAZY) // Lazy loaded through bytecode instrumentation
@org.hibernate.search.annotations.Field(index = org.hibernate.search.annotations.Index.TOKENIZED)
@Searchable(description = "Content")
private String content;
- @Column(name = "NAME_AS_TITLE")
+ @Column(table = "NODE_DOCUMENT", name = "NAME_AS_TITLE")
private Boolean nameAsTitle = true;
- @Column(name = "ENABLE_COMMENTS")
+ @Column(table = "NODE_DOCUMENT", name = "ENABLE_COMMENTS")
private Boolean enableComments = false;
- @Column(name = "ENABLE_COMMENT_FORM")
+ @Column(table = "NODE_DOCUMENT", name = "ENABLE_COMMENT_FORM")
private Boolean enableCommentForm = true;
+ @OneToMany(mappedBy = "document", fetch = FetchType.LAZY)
+ @org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
+ @org.hibernate.annotations.OrderBy(clause = "CREATED_ON desc")
+ @org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.EXTRA)
+ private List<Comment> comments;
+
public Document() {
super("New Document");
content = "Edit this text..."; // Don't know why the interactive preview doesn't work without content
@@ -75,22 +97,18 @@
this.enableCommentForm = enableCommentForm;
}
- public Directory getParent() {
- return (Directory)super.getParent();
+ public List<Comment> getComments() {
+ return comments;
}
public void addChild(Node child) {
throw new UnsupportedOperationException("Documents can't have children");
}
- public void removeChild(Node child) {
+ public Node 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.9 +7 -9 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/File.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: File.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/File.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- File.java 12 Jun 2007 17:51:00 -0000 1.8
+++ File.java 17 Aug 2007 13:00:24 -0000 1.9
@@ -1,3 +1,9 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.seam.wiki.core.model;
import javax.persistence.*;
@@ -97,20 +103,12 @@
this.imageMetaInfo = imageMetaInfo;
}
- 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) {
+ public Node removeChild(Node child) {
throw new UnsupportedOperationException("Files can't have children");
}
- public String toString() {
- return getName();
- }
-
}
1.6 +8 -3 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Comment.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Comment.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Comment.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- Comment.java 21 Jun 2007 11:05:48 -0000 1.5
+++ Comment.java 17 Aug 2007 13:00:24 -0000 1.6
@@ -1,3 +1,9 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Length;
@@ -30,13 +36,12 @@
private Long id = null;
@Version
- @Column(name = "OBJ_VERSION")
+ @Column(name = "OBJ_VERSION", nullable = false)
private int version = 0;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "DOCUMENT_ID", nullable = false)
@org.hibernate.annotations.ForeignKey(name = "FK_COMMENT_DOCUMENT_ID")
- @org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
private Document document;
@Column(name = "SUBJECT", nullable = false)
@@ -58,7 +63,7 @@
private String fromUserHomepage;
@Column(name = "COMMENT_TEXT", nullable = false)
- @Length(min = 1, max = 32768)
+ @Length(min = 1, max = 8192)
@org.hibernate.search.annotations.Field(index = org.hibernate.search.annotations.Index.TOKENIZED)
private String text;
1.4 +2 -2 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/HistoricalNode.hbm.xml
(In the diff below, changes in quantity of whitespace are not shown.)
Index: HistoricalNode.hbm.xml
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/HistoricalNode.hbm.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- HistoricalNode.hbm.xml 19 Apr 2007 14:58:32 -0000 1.3
+++ HistoricalNode.hbm.xml 17 Aug 2007 13:00:24 -0000 1.4
@@ -33,7 +33,7 @@
<subclass name="Document" entity-name="HistoricalDocument" discriminator-value="DOCUMENT">
<property name="content" column="CONTENT" length="32768"/>
</subclass>
-
+<!-- TODO: Versioning for files
<subclass name="File" entity-name="HistoricalFile" discriminator-value="FILE">
<property name="filename" length="255" column="FILENAME"/>
<property name="filesize" column="FILESIZE"/>
@@ -45,7 +45,7 @@
<property name="thumbnail" column="IMAGE_THUMBNAIL"/>
</component>
</subclass>
-
+-->
</class>
</hibernate-mapping>
1.9 +16 -2 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/User.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: User.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/User.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- User.java 4 May 2007 12:35:30 -0000 1.8
+++ User.java 17 Aug 2007 13:00:24 -0000 1.9
@@ -1,3 +1,9 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.NotNull;
@@ -19,7 +25,7 @@
private Long id = null;
@Version
- @Column(name = "OBJ_VERSION")
+ @Column(name = "OBJ_VERSION", nullable = false)
private int version = 0;
@Column(name = "FIRSTNAME", length = 63, nullable = false)
@@ -67,11 +73,16 @@
@org.hibernate.annotations.ForeignKey(name = "USER_ROLE_USER_ID", inverseName = "USER_ROLE_ROLE_ID")
private List<Role> roles = new ArrayList<Role>();
- @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
+ @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MEMBER_HOME_NODE_ID", nullable = true)
@org.hibernate.annotations.ForeignKey(name = "FK_USER_MEMBER_HOME_NODE_ID")
private Directory memberHome;
+ @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
+ @JoinColumn(name = "USER_PROFILE_ID", nullable = false, unique = true)
+ @org.hibernate.annotations.ForeignKey(name = "FK_USER_USER_PROFILE_ID")
+ private UserProfile profile = new UserProfile();
+
public User() {}
public User(String firstname, String lastname,
@@ -122,6 +133,9 @@
public List<Role> getRoles() { return roles; }
public void setRoles(List<Role> roles) { this.roles = roles; }
+ public UserProfile getProfile() { return profile; }
+ public void setProfile(UserProfile profile) { this.profile = profile; }
+
// Misc methods
public String toString() {
1.6 +7 -1 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Role.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Role.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Role.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- Role.java 19 Apr 2007 18:36:11 -0000 1.5
+++ Role.java 17 Aug 2007 13:00:24 -0000 1.6
@@ -1,3 +1,9 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Length;
@@ -16,7 +22,7 @@
private Long id = null;
@Version
- @Column(name = "OBJ_VERSION")
+ @Column(name = "OBJ_VERSION", nullable = false)
private int version = 0;
@Column(name = "NAME", length = 255, nullable = false, unique = true)
1.5 +8 -24 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Feed.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Feed.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Feed.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- Feed.java 22 Apr 2007 10:15:33 -0000 1.4
+++ Feed.java 17 Aug 2007 13:00:24 -0000 1.5
@@ -1,3 +1,9 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.seam.wiki.core.model;
import javax.persistence.*;
@@ -14,21 +20,15 @@
private Long id;
@Version
- @Column(name = "OBJ_VERSION")
+ @Column(name = "OBJ_VERSION", nullable = false)
protected Integer version;
@Column(name = "TITLE", nullable = false)
private String title;
- @Column(name = "DESCRIPTION", nullable = true)
- private String description;
-
- @Column(name = "AUTHOR", nullable = true)
+ @Column(name = "AUTHOR", nullable = false)
private String author;
- @Column(name = "COPYRIGHT", nullable = true)
- private String copyright;
-
@Column(name = "PUBLISHED_ON", nullable = false, updatable = false)
private Date publishedDate = new Date();
@@ -65,14 +65,6 @@
this.title = title;
}
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
public String getAuthor() {
return author;
}
@@ -81,14 +73,6 @@
this.author = author;
}
- public String getCopyright() {
- return copyright;
- }
-
- public void setCopyright(String copyright) {
- this.copyright = copyright;
- }
-
public Date getPublishedDate() {
return publishedDate;
}
1.16 +66 -37 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Node.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Node.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Node.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- Node.java 12 Jun 2007 12:29:59 -0000 1.15
+++ Node.java 17 Aug 2007 13:00:24 -0000 1.16
@@ -1,15 +1,22 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Length;
import org.hibernate.validator.Pattern;
+import org.jboss.seam.wiki.core.nestedset.AbstractNestedSetNode;
import org.jboss.seam.wiki.core.preferences.WikiPreferenceValue;
import org.jboss.seam.wiki.core.search.PaddedIntegerBridge;
import org.jboss.seam.wiki.core.search.annotations.Searchable;
import org.jboss.seam.wiki.core.search.annotations.SearchableType;
import javax.persistence.*;
-import java.util.*;
import java.io.Serializable;
+import java.util.*;
@Entity
@Table(
@@ -34,7 +41,7 @@
name = "accessLevelFilter",
condition = "READ_ACCESS_LEVEL <= :currentAccessLevel"
)
-public abstract class Node implements Serializable {
+public abstract class Node extends AbstractNestedSetNode<Node> implements Serializable {
// Uses Hibernates ability to map the same class twice, see HistoricalNode.hbm.xml
@Transient
@@ -49,7 +56,7 @@
protected Long nodeId;
@Version
- @Column(name = "OBJ_VERSION")
+ @Column(name = "OBJ_VERSION", nullable = false)
protected Integer version;
@Column(name = "NAME", length = 255, nullable = false)
@@ -68,19 +75,24 @@
@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)
+ // The generated DDL doesn't have a NOT NULL (the root node of the tree has a NULL parent)
@JoinColumn(name = "PARENT_NODE_ID", nullable = true, insertable = false, updatable = false)
@org.hibernate.annotations.ForeignKey(name = "FK_NODE_PARENT_NODE_ID")
- @org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
protected Node parent;
@OneToMany(fetch = FetchType.LAZY)
- @JoinColumn(name = "PARENT_NODE_ID", nullable = true)
- @org.hibernate.annotations.IndexColumn(name = "NODE_POSITION")
- @org.hibernate.annotations.BatchSize(size = 5) // Helps with walking the node tree
+ // TODO: The NOT NULL constraint here is a hack so ON DELETE CASCADE works, it's not in the DDL
+ // Without this setting, Hibernate would null the PARENT_NODE_ID column of children when it deletes a parent,
+ // we don't want that because there is a FK constraint with cascading delete on it in the database!
+ @JoinColumn(name = "PARENT_NODE_ID", nullable = false)
+ @org.hibernate.annotations.IndexColumn(name = "DISPLAY_POSITION")
private List<Node> children = new ArrayList<Node>();
+ @Column(name = "DISPLAY_POSITION", nullable = false, updatable = false, insertable = false)
+ // Hibernate would complain for newly persistent instances if it is null...
+ private Integer displayPosition = Integer.MAX_VALUE;
+
@Column(name = "CREATED_ON", nullable = false, updatable = false)
@org.hibernate.search.annotations.Field(
index = org.hibernate.search.annotations.Index.UN_TOKENIZED,
@@ -178,14 +190,6 @@
this.wikiname = wikiname;
}
- public boolean isMenuItem() {
- return menuItem;
- }
-
- public void setMenuItem(boolean menuItem) {
- this.menuItem = menuItem;
- }
-
public Long getAreaNumber() {
return areaNumber;
}
@@ -194,27 +198,12 @@
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 boolean isMenuItem() {
+ return menuItem;
}
- public void removeChild(Node child) {
- child.setParent(null);
- this.getChildren().remove(child);
+ public void setMenuItem(boolean menuItem) {
+ this.menuItem = menuItem;
}
public User getCreatedBy() {
@@ -270,15 +259,55 @@
this.preferences = preferences;
}
+ public String getTreeSuperclassEntityName() {
+ return "Node";
+ }
+
+ // TODO: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1615
+ public String[] getTreeSuperclassPropertiesForGrouping() {
+ return new String[]{
+ "id", "class", "version",
+ "nsLeft", "nsRight", "nsThread", "parent",
+ "areaNumber", "createdBy", "createdOn", "lastModifiedBy", "lastModifiedOn", "menuItem", "name", "displayPosition",
+ "readAccessLevel", "revision", "wikiname", "writeAccessLevel",
+ "contentType", "filename", "filesize", "imageMetaInfo.sizeX", "imageMetaInfo.sizeY", "imageMetaInfo.thumbnail", "imageMetaInfo.thumbnailData",
+ "defaultDocument", "enableComments", "enableCommentForm", "nameAsTitle",
+ };
+ }
+
+ public Directory getParent() {
+ return (Directory)parent; // No proxies here!
+ }
+
+ public void setParent(Node parent) {
+ this.parent = parent;
+ }
+
+ public List<Node> getChildren() {
+ return children;
+ }
+
+ public Integer getDisplayPosition() {
+ return displayPosition;
+ }
+
+ public void setDisplayPosition(Integer displayPosition) {
+ this.displayPosition = displayPosition;
+ }
+
// Misc methods
- public Directory getArea() {
+ public String toString() {
+ return getName() + " (ID: " + getId() + ")";
+ }
+
+ public Node 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;
+ return currentNode;
}
public void incrementRevision() {
1.9 +7 -3 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/FeedEntry.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FeedEntry.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/FeedEntry.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- FeedEntry.java 6 Jul 2007 14:38:39 -0000 1.8
+++ FeedEntry.java 17 Aug 2007 13:00:24 -0000 1.9
@@ -1,11 +1,15 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Length;
import javax.persistence.*;
import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
import java.io.Serializable;
@Entity
@@ -18,7 +22,7 @@
private Long id;
@Version
- @Column(name = "OBJ_VERSION")
+ @Column(name = "OBJ_VERSION", nullable = false)
protected Integer version;
@Column(name = "LINK", nullable = false)
1.1 date: 2007/08/17 13:00:24; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/UserProfile.java
Index: UserProfile.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Length;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "USER_PROFILE")
public class UserProfile {
@Id
@GeneratedValue(generator = "wikiSequenceGenerator")
@Column(name = "USER_PROFILE_ID")
private Long id;
@Version
@Column(name = "OBJ_VERSION", nullable = false)
protected Integer version;
@Column(name = "CREATED_ON", nullable = false, updatable = false)
private Date createdOn = new Date();
@Length(min = 0, max = 1000)
@Column(name = "BIO", nullable = true)
private String bio;
@Length(min = 0, max = 1000)
@Column(name = "WEBSITE", nullable = true)
private String website;
@Length(min = 0, max = 255)
@Column(name = "LOCATION", nullable = true)
private String location;
@Length(min = 0, max = 1000)
@Column(name = "OCCUPATION", nullable = true)
private String occupation;
@Length(min = 0, max = 1000)
@Column(name = "SIGNATURE", nullable = true)
private String signature;
// SchemaExport needs length.. MySQL has "tinyblob", "mediumblob" and other such nonsense types
@Lob
@Column(name = "IMAGE_DATA", nullable = true, length = 200000)
@Basic(fetch = FetchType.LAZY) // Lazy loaded through bytecode instrumentation
private byte[] image;
@Column(name = "IMAGE_CONTENT_TYPE", nullable = true, length = 255)
private String imageContentType;
public UserProfile() {}
// Immutable properties
public Long getId() { return id; }
public Integer getVersion() { return version; }
public Date getCreatedOn() { return createdOn; }
// Mutable properties
public String getBio() {
return bio;
}
public void setBio(String bio) {
this.bio = bio.length() > 0 ? bio : null;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website.length() > 0 ? website : null;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location.length() > 0 ? location : null;
}
public String getOccupation() {
return occupation;
}
public void setOccupation(String occupation) {
this.occupation = occupation.length() > 0 ? occupation : null;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature.length() > 0 ? signature : null;
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
public String getImageContentType() {
return imageContentType;
}
public void setImageContentType(String imageContentType) {
this.imageContentType = imageContentType;
}
}
More information about the jboss-cvs-commits
mailing list