[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model ...
Christian Bauer
christian at hibernate.org
Tue Dec 18 23:29:20 EST 2007
User: cbauer
Date: 07/12/18 23:29:20
Modified: examples/wiki/src/main/org/jboss/seam/wiki/core/model
DatabaseObjects.hbm.xml LinkProtocol.java User.java
UserProfile.java Role.java Feed.java FeedEntry.java
Added: examples/wiki/src/main/org/jboss/seam/wiki/core/model
WikiCommentFeedEntry.java
HistoricalWikiFile.hbm.xml WikiNode.java
DisplayTagCount.java WikiUpload.java
WikiComment.java WikiUploadImage.java
WikiDocumentDefaults.java WikiDirectory.java
Queries.hbm.xml WikiDocumentFeedEntry.java
WikiDocument.java WikiMacro.java WikiFile.java
WikiMenuItem.java
Removed: examples/wiki/src/main/org/jboss/seam/wiki/core/model
Document.java File.java Directory.java
ImageMetaInfo.java Comment.java
HistoricalNode.hbm.xml Node.java
Log:
Major rewrite of the most of the application
Revision Changes Path
1.8 +54 -194 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.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- DatabaseObjects.hbm.xml 9 Nov 2007 15:08:25 -0000 1.7
+++ DatabaseObjects.hbm.xml 19 Dec 2007 04:29:20 -0000 1.8
@@ -5,6 +5,10 @@
<hibernate-mapping>
+ <filter-def name="accessLevelFilter">
+ <filter-param name="currentAccessLevel" type="integer"/>
+ </filter-def>
+
<!-- TODO: Re-creating FK constraints with options not supported by Hibernate's @ForeignKey
This sucks big time... especially for MySQL which is too dumb to recognize two commands separated with a semicolon...
http://opensource.atlassian.com/projects/hibernate/browse/ANN-598
@@ -17,19 +21,10 @@
<database-object>
<create>
- alter table FEEDENTRY drop constraint FK_FEEDENTRY_DOCUMENT_ID;
- alter table FEEDENTRY add constraint FK_FEEDENTRY_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 FEED_FEEDENTRY drop constraint FK_FEED_FEEDENTRY_FEED_ID;
alter table FEED_FEEDENTRY add constraint FK_FEED_FEEDENTRY_FEED_ID foreign key (FEED_ID) references FEED on delete cascade;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
</database-object>
@@ -38,88 +33,52 @@
alter table FEED_FEEDENTRY drop constraint FK_FEED_FEEDENTRY_FEEDENTRY_ID;
alter table FEED_FEEDENTRY add constraint FK_FEED_FEEDENTRY_FEEDENTRY_ID foreign key (FEEDENTRY_ID) references FEEDENTRY 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_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>
- <drop></drop>
- <dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
- </database-object>
-
- <database-object>
- <create>
- 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>
+ <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;
+ alter table WIKI_DIRECTORY drop constraint FK_WIKI_DIRECTORY_DEFAULT_FILE_ID;
+ alter table WIKI_DIRECTORY add constraint FK_WIKI_DIRECTORY_DEFAULT_FILE_ID foreign key (DEFAULT_FILE_ID) references WIKI_FILE on delete set null;
</create>
- <drop></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;
+ alter table WIKI_TAG drop constraint FK_WIKI_TAG_FILE_ID;
+ alter table WIKI_TAG add constraint FK_WIKI_TAG_FILE_ID foreign key (FILE_ID) references WIKI_FILE on delete cascade;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
</database-object>
<database-object>
<create>
- alter table NODE_FILE drop constraint FK_NODE_FILE_FILE_ID;
- alter table NODE_FILE add constraint FK_NODE_FILE_FILE_ID foreign key (FILE_ID) references NODE on delete cascade;
+ alter table WIKI_FILE_LINK drop constraint FK_SOURCE_WIKI_FILE_ID;
+ alter table WIKI_FILE_LINK add constraint FK_SOURCE_WIKI_FILE_ID foreign key (SOURCE_WIKI_FILE_ID) references WIKI_FILE on delete cascade;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
</database-object>
<database-object>
<create>
- alter table PREFERENCE drop constraint FK_PREFERENCE_NODE_ID;
- alter table PREFERENCE add constraint FK_PREFERENCE_NODE_ID foreign key (NODE_ID) references NODE on delete cascade;
+ alter table WIKI_FILE_LINK drop constraint FK_TARGET_WIKI_FILE_ID;
+ alter table WIKI_FILE_LINK add constraint FK_TARGET_WIKI_FILE_ID foreign key (TARGET_WIKI_FILE_ID) references WIKI_FILE on delete cascade;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
</database-object>
<database-object>
<create>
- alter table PREFERENCE drop constraint FK_PREFERENCE_USER_ID;
- alter table PREFERENCE add constraint FK_PREFERENCE_USER_ID foreign key (USER_ID) references USERS on delete cascade;
+ alter table USERS drop constraint FK_USER_MEMBER_HOME_WIKI_DIRECTORY_ID;
+ alter table USERS add constraint FK_USER_MEMBER_HOME_WIKI_DIRECTORY_ID foreign key (MEMBER_HOME_WIKI_DIRECTORY_ID) references WIKI_DIRECTORY on delete set null;
</create>
- <drop></drop>
- <dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
- </database-object>
-
- <database-object>
- <create>
- alter table USERS drop constraint FK_USER_MEMBER_HOME_NODE_ID;
- alter table USERS add constraint FK_USER_MEMBER_HOME_NODE_ID foreign key (MEMBER_HOME_NODE_ID) references NODE on delete set null;
- </create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
</database-object>
@@ -128,7 +87,7 @@
alter table USER_ROLE drop constraint USER_ROLE_USER_ID;
alter table USER_ROLE add constraint USER_ROLE_USER_ID foreign key (USER_ID) references USERS on delete cascade;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
</database-object>
@@ -137,7 +96,7 @@
alter table USER_ROLE drop constraint USER_ROLE_ROLE_ID;
alter table USER_ROLE add constraint USER_ROLE_ROLE_ID foreign key (ROLE_ID) references ROLES on delete cascade;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
</database-object>
@@ -146,16 +105,7 @@
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>
- alter table COMMENTS drop constraint FK_COMMENT_FROM_USER_ID;
- alter table COMMENTS add constraint FK_COMMENT_FROM_USER_ID foreign key (FROM_USER_ID) references USERS on delete cascade;
- </create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
</database-object>
@@ -179,38 +129,25 @@
<dialect-scope name="org.hibernate.dialect.HSQLDialect"/>
</database-object>
-
<!-- ############################### MySQL ############################### -->
<database-object>
<create>
- alter table FEEDENTRY drop foreign key FK_FEEDENTRY_DOCUMENT_ID;
- </create><drop></drop><dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
- </database-object>
- <database-object>
- <create>
- alter table FEEDENTRY
- add constraint FK_FEEDENTRY_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 FEED_FEEDENTRY drop foreign key FK_FEED_FEEDENTRY_FEED_ID;
- </create><drop></drop><dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
+ </create><drop/><dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
alter table FEED_FEEDENTRY
add constraint FK_FEED_FEEDENTRY_FEED_ID foreign key (FEED_ID) references FEED (FEED_ID) on delete cascade;
- </create><drop></drop><dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
+ </create><drop/><dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
alter table FEED_FEEDENTRY drop foreign key FK_FEED_FEEDENTRY_FEEDENTRY_ID;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
@@ -218,144 +155,82 @@
alter table FEED_FEEDENTRY
add constraint FK_FEED_FEEDENTRY_FEEDENTRY_ID foreign key (FEEDENTRY_ID) references FEEDENTRY (FEEDENTRY_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_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>
- <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
- </database-object>
- <database-object>
- <create>
- alter table NODE
- add constraint FK_NODE_LAST_MODIFIED_BY_USER_ID foreign key (LAST_MODIFIED_BY_USER_ID) references USERS (USER_ID) on delete set null;
- </create>
- <drop></drop>
- <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
- </database-object>
-
- <database-object>
- <create>
- 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>
+ <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;
+ alter table WIKI_DIRECTORY drop foreign key FK_WIKI_DIRECTORY_DEFAULT_FILE_ID;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
- alter table NODE_DOCUMENT add constraint FK_NODE_DOCUMENT_DOCUMENT_ID foreign key (DOCUMENT_ID) references NODE (NODE_ID) on delete cascade;
+ alter table WIKI_DIRECTORY add constraint FK_WIKI_DIRECTORY_DEFAULT_FILE_ID foreign key (DEFAULT_FILE_ID) references WIKI_FILE(NODE_ID) on delete set null;
</create>
- <drop></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;
+ alter table WIKI_TAG drop foreign key FK_WIKI_TAG_FILE_ID;
</create>
- <drop></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;
+ alter table WIKI_TAG add constraint FK_WIKI_TAG_FILE_ID foreign key (FILE_ID) references WIKI_FILE(NODE_ID) on delete cascade;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
- alter table NODE_FILE drop foreign key FK_NODE_FILE_FILE_ID;
+ alter table WIKI_FILE_LINK drop foreign key FK_SOURCE_WIKI_FILE_ID;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
- alter table NODE_FILE add constraint FK_NODE_FILE_FILE_ID foreign key (FILE_ID) references NODE (NODE_ID) on delete cascade;
+ alter table WIKI_FILE_LINK add constraint FK_SOURCE_WIKI_FILE_ID foreign key (SOURCE_WIKI_FILE_ID) references WIKI_FILE(NODE_ID) on delete cascade;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
- alter table PREFERENCE drop foreign key FK_PREFERENCE_NODE_ID;
+ alter table WIKI_FILE_LINK drop foreign key FK_TARGET_WIKI_FILE_ID;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
- alter table PREFERENCE add constraint FK_PREFERENCE_NODE_ID foreign key (NODE_ID) references NODE (NODE_ID) on delete cascade;
+ alter table WIKI_FILE_LINK add constraint FK_TARGET_WIKI_FILE_ID foreign key (TARGET_WIKI_FILE_ID) references WIKI_FILE(NODE_ID) on delete cascade;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
- alter table PREFERENCE drop foreign key FK_PREFERENCE_USER_ID;
+ alter table USERS drop foreign key FK_USER_MEMBER_HOME_WIKI_DIRECTORY_ID;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
- alter table PREFERENCE add constraint FK_PREFERENCE_USER_ID foreign key (USER_ID) references USERS (USER_ID) on delete cascade;
+ alter table USERS add constraint FK_USER_MEMBER_HOME_WIKI_DIRECTORY_ID foreign key (MEMBER_HOME_WIKI_DIRECTORY_ID) references WIKI_DIRECTORY(NODE_ID) on delete set null;
</create>
- <drop></drop>
- <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
- </database-object>
-
- <database-object>
- <create>
- alter table USERS drop foreign key FK_USER_MEMBER_HOME_NODE_ID;
- </create>
- <drop></drop>
- <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
- </database-object>
- <database-object>
- <create>
- alter table USERS add constraint FK_USER_MEMBER_HOME_NODE_ID foreign key (MEMBER_HOME_NODE_ID) references NODE (NODE_ID) on delete set null;
- </create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
@@ -363,14 +238,14 @@
<create>
alter table USER_ROLE drop foreign key USER_ROLE_USER_ID;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
alter table USER_ROLE add constraint USER_ROLE_USER_ID foreign key (USER_ID) references USERS (USER_ID) on delete cascade;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
@@ -378,14 +253,14 @@
<create>
alter table USER_ROLE drop foreign key USER_ROLE_ROLE_ID;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
<database-object>
<create>
alter table USER_ROLE add constraint USER_ROLE_ROLE_ID foreign key (ROLE_ID) references ROLES (ROLE_ID) on delete cascade;
</create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
@@ -393,29 +268,14 @@
<create>
alter table USERS drop foreign key FK_USER_USER_PROFILE_ID;
</create>
- <drop></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>
- alter table COMMENTS drop foreign key FK_COMMENT_FROM_USER_ID;
- </create>
- <drop></drop>
- <dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
- </database-object>
- <database-object>
- <create>
- alter table COMMENTS add constraint FK_COMMENT_FROM_USER_ID foreign key (FROM_USER_ID) references USERS (USER_ID) on delete cascade;
- </create>
- <drop></drop>
+ <drop/>
<dialect-scope name="org.hibernate.dialect.MySQL5InnoDBDialect"/>
</database-object>
1.5 +1 -1 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.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- LinkProtocol.java 12 Oct 2007 16:31:25 -0000 1.4
+++ LinkProtocol.java 19 Dec 2007 04:29:20 -0000 1.5
@@ -23,7 +23,7 @@
@Version
@Column(name = "OBJ_VERSION", nullable = false)
- protected Integer version;
+ protected int version;
@Column(name = "PREFIX", nullable = false)
@Length(min = 2, max = 10)
1.14 +17 -6 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.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- User.java 9 Nov 2007 15:08:25 -0000 1.13
+++ User.java 19 Dec 2007 04:29:20 -0000 1.14
@@ -20,6 +20,9 @@
@org.hibernate.annotations.BatchSize(size = 20)
public class User implements Serializable {
+ public static final String GUEST_USERNAME = "guest";
+ public static final String ADMIN_USERNAME = "admin";
+
@Id
@GeneratedValue(generator = "wikiSequenceGenerator")
@Column(name = "USER_ID")
@@ -27,7 +30,7 @@
@Version
@Column(name = "OBJ_VERSION", nullable = false)
- private int version = 0;
+ private int version;
@Column(name = "FIRSTNAME", length = 63, nullable = false)
@NotNull
@@ -90,9 +93,9 @@
private List<Role> roles = new ArrayList<Role>();
@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;
+ @JoinColumn(name = "MEMBER_HOME_WIKI_DIRECTORY_ID", nullable = true)
+ @org.hibernate.annotations.ForeignKey(name = "FK_USER_MEMBER_HOME_WIKI_DIRECTORY_ID")
+ private WikiDirectory memberHome;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "USER_PROFILE_ID", nullable = false, unique = true)
@@ -151,8 +154,8 @@
public String getActivationCode() { return activationCode; }
public void setActivationCode(String activationCode) { this.activationCode = activationCode; }
- public Directory getMemberHome() { return memberHome; }
- public void setMemberHome(Directory memberHome) { this.memberHome = memberHome; }
+ public WikiDirectory getMemberHome() { return memberHome; }
+ public void setMemberHome(WikiDirectory memberHome) { this.memberHome = memberHome; }
public List<Role> getRoles() { return roles; }
public void setRoles(List<Role> roles) { this.roles = roles; }
@@ -162,6 +165,14 @@
// Misc methods
+ public boolean isGuest() {
+ return GUEST_USERNAME.equals(getUsername());
+ }
+
+ public boolean isAdmin() {
+ return ADMIN_USERNAME.equals(getUsername());
+ }
+
public String toString() {
return getUsername();
}
1.3 +1 -1 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/UserProfile.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UserProfile.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/UserProfile.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- UserProfile.java 9 Nov 2007 15:08:25 -0000 1.2
+++ UserProfile.java 19 Dec 2007 04:29:20 -0000 1.3
@@ -23,7 +23,7 @@
@Version
@Column(name = "OBJ_VERSION", nullable = false)
- protected Integer version;
+ protected int version;
@Column(name = "CREATED_ON", nullable = false, updatable = false)
private Date createdOn = new Date();
1.8 +12 -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.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- Role.java 9 Nov 2007 15:08:25 -0000 1.7
+++ Role.java 19 Dec 2007 04:29:20 -0000 1.8
@@ -16,6 +16,9 @@
@Table(name = "ROLES")
public class Role implements Serializable, Comparable {
+ public static final int GUESTROLE_ACCESSLEVEL = 0;
+ public static final int ADMINROLE_ACCESSLEVEL = 1000;
+
@Id
@GeneratedValue(generator = "wikiSequenceGenerator")
@Column(name = "ROLE_ID")
@@ -23,7 +26,7 @@
@Version
@Column(name = "OBJ_VERSION", nullable = false)
- private int version = 0;
+ private int version;
@Column(name = "NAME", length = 255, nullable = false, unique = true)
private String name;
@@ -75,6 +78,14 @@
public int getAccessLevel() { return accessLevel; }
public void setAccessLevel(int accessLevel) { this.accessLevel = accessLevel; }
+ public boolean isAdminRole() {
+ return getAccessLevel() == ADMINROLE_ACCESSLEVEL;
+ }
+
+ public boolean isGuestRole() {
+ return getAccessLevel() == GUESTROLE_ACCESSLEVEL;
+ }
+
public String toString() {
return "Role ('" + getId() + "'), " +
"Access Level: '" + getAccessLevel() + "' " +
1.8 +5 -10 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.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- Feed.java 9 Nov 2007 15:02:07 -0000 1.7
+++ Feed.java 19 Dec 2007 04:29:20 -0000 1.8
@@ -20,10 +20,6 @@
@Column(name = "FEED_ID")
private Long id;
- @Version
- @Column(name = "OBJ_VERSION", nullable = false)
- protected Integer version;
-
@Column(name = "TITLE", nullable = false)
private String title;
@@ -37,10 +33,10 @@
private Date publishedDate = new Date();
@OneToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "DIRECTORY_ID", nullable = false, updatable = false)
- @org.hibernate.annotations.ForeignKey(name = "FK_FEED_DIRECTORY_ID")
+ @JoinColumn(name = "DIRECTORY_ID", nullable = false, updatable = false, unique = true)
+ @org.hibernate.annotations.ForeignKey(name = "FK_FEED_WIKI_DIRECTORY_ID")
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
- private Directory directory;
+ private WikiDirectory directory;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
@@ -57,7 +53,6 @@
// Immutable properties
public Long getId() { return id; }
- public Integer getVersion() { return version; }
// Mutable properties
@@ -93,11 +88,11 @@
this.publishedDate = publishedDate;
}
- public Directory getDirectory() {
+ public WikiDirectory getDirectory() {
return directory;
}
- public void setDirectory(Directory directory) {
+ public void setDirectory(WikiDirectory directory) {
this.directory = directory;
}
1.14 +9 -33 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.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- FeedEntry.java 15 Nov 2007 06:22:51 -0000 1.13
+++ FeedEntry.java 19 Dec 2007 04:29:20 -0000 1.14
@@ -13,15 +13,10 @@
import java.io.Serializable;
@Entity
- at Table(
- name = "FEEDENTRY",
- uniqueConstraints = {
- // An entry can either be for a document (DOCUMENT_ID 123, COMMENT_IDENTIFIER null)
- // or a comment (DOCUMENT_ID 123, COMMENT_IDENTIFIER 456). Duplicate comment identifiers
- // for the same document are not allowed.
- @UniqueConstraint(columnNames = {"DOCUMENT_ID", "COMMENT_IDENTIFIER"})
- }
-)
+ at Table(name = "FEEDENTRY")
+ at Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+ at DiscriminatorColumn(name = "FEEDENTRY_TYPE", length = 255)
+ at DiscriminatorValue("EXTERNAL")
public class FeedEntry implements Serializable, Comparable {
public static final String END_TEASER_MACRO = "endTeaser";
@@ -34,7 +29,7 @@
@Version
@Column(name = "OBJ_VERSION", nullable = false)
- protected Integer version;
+ protected int version;
@Column(name = "LINK", nullable = false)
@Length(min = 3, max = 1024)
@@ -62,14 +57,6 @@
@Length(min = 1, max = 32768)
private String descriptionValue;
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "DOCUMENT_ID", nullable = false)
- @org.hibernate.annotations.ForeignKey(name = "FK_FEEDENTRY_DOCUMENT_ID")
- private Document document;
-
- @Column(name = "COMMENT_IDENTIFIER", nullable = true)
- private Long commentIdentifier;
-
public FeedEntry() {}
// Immutable properties
@@ -148,20 +135,8 @@
return isTeaserMarkerPresent() ? stripped.substring(0, stripped.indexOf(END_TEASER_MARKER)) : stripped;
}
- public Document getDocument() {
- return document;
- }
-
- public void setDocument(Document document) {
- this.document = document;
- }
-
- public Long getCommentIdentifier() {
- return commentIdentifier;
- }
-
- public void setCommentIdentifier(Long commentIdentifier) {
- this.commentIdentifier = commentIdentifier;
+ public int getReadAccessLevel() {
+ return 0; // No restrictions
}
// Sort by date
@@ -172,10 +147,11 @@
}
public String toString() {
- return "FeedEntry: " + getId();
+ return "FeedEntry (" + getId() + ")";
}
private String stripHTMLTags(String original) {
return original.replaceAll("\\<([a-zA-Z]|/){1}?.*?\\>","");
}
+
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiCommentFeedEntry.java
Index: WikiCommentFeedEntry.java
===================================================================
package org.jboss.seam.wiki.core.model;
import javax.persistence.*;
@Entity
@DiscriminatorValue("WIKI_COMMENT")
public class WikiCommentFeedEntry extends FeedEntry {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "WIKI_COMMENT_ID", nullable = true)
@org.hibernate.annotations.ForeignKey(name = "FK_FEEDENTRY_WIKI_COMMENT_ID")
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
private WikiComment comment;
public WikiComment getComment() {
return comment;
}
public void setComment(WikiComment comment) {
this.comment = comment;
}
public int getReadAccessLevel() {
return getComment().getReadAccessLevel();
}
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/HistoricalWikiFile.hbm.xml
Index: HistoricalWikiFile.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 of WikiFile subclasses we want to keep a history of.
@author Christian Bauer
-->
<hibernate-mapping package="org.jboss.seam.wiki.core.model" default-access="field">
<class name="WikiDocument" entity-name="HistoricalWikiDocument" table="WIKI_DOCUMENT_HISTORY" polymorphism="explicit">
<id name="historicalFileId" column="FILE_HISTORY_ID">
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
<param name="sequence_name">WIKI_SEQUENCE</param>
</generator>
</id>
<!-- Mandatory WikiFile properties -->
<property name="id" column="FILE_ID" not-null="true" unique-key="unique_revision_per_file_id"/>
<property name="revision" column="FILE_REVISION" not-null="true" unique-key="unique_revision_per_file_id"/>
<property name="name" length="255" not-null="true" column="NAME"/>
<property name="lastModifiedOn" column="LAST_MODIFIED_ON" type="timestamp" not-null="false"/>
<property name="lastModifiedByUsername" column="LAST_MODIFIED_BY_USERNAME" not-null="false"/>
<!-- Optional WikiFile subclass properties -->
<property name="content" column="CONTENT" length="32768"/>
</class>
</hibernate-mapping>
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiNode.java
Index: WikiNode.java
===================================================================
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Pattern;
import org.hibernate.validator.Length;
import org.jboss.seam.wiki.core.search.annotations.Searchable;
import org.jboss.seam.wiki.core.search.annotations.SearchableType;
import org.jboss.seam.wiki.core.search.PaddedIntegerBridge;
import javax.persistence.*;
import java.util.Date;
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(
name = "WIKI_NODE",
uniqueConstraints = {
// Wikiname of a document needs to be unique within an area
@UniqueConstraint(columnNames = {"AREA_NR", "WIKINAME"})
}
)
@org.hibernate.annotations.Filter(
name = "accessLevelFilter",
condition = "READ_ACCESS_LEVEL <= :currentAccessLevel"
)
@org.hibernate.annotations.BatchSize(size = 20)
public abstract class WikiNode implements Comparable {
@Id
@GeneratedValue(generator = "wikiSequenceGenerator")
@Column(name = "NODE_ID")
@org.hibernate.search.annotations.DocumentId(name = "nodeId")
protected Long id;
@Version
@Column(name = "OBJ_VERSION", nullable = false)
protected int version;
@Column(name = "AREA_NR", nullable = false)
protected Long areaNumber;
@Column(name = "NAME", length = 255, nullable = false)
@Length(min = 3, max = 255)
@Pattern(
regex="^[a-zA-Z0-9]+[^/#\\|\\]\\[]*",
message="#{messages['lacewiki.entity.NameMustStartWithLetterOrNumber']}"
)
protected String name;
@Column(name = "WIKINAME", length = 255, nullable = false)
@Pattern(
regex="^[A-Z0-9]+.*",
message="#{messages['lacewiki.entity.NameMustStartWithUppercaseLetterOrNumber']}"
)
protected String wikiname;
@Column(name = "CREATED_ON", nullable = false, updatable = false)
@org.hibernate.search.annotations.Field(
index = org.hibernate.search.annotations.Index.UN_TOKENIZED,
store = org.hibernate.search.annotations.Store.YES
)
@org.hibernate.search.annotations.DateBridge(resolution = org.hibernate.search.annotations.Resolution.DAY)
@Searchable(description = "Created", type = SearchableType.PASTDATE)
protected Date createdOn = new Date();
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CREATED_BY_USER_ID", nullable = false)
@org.hibernate.annotations.ForeignKey(name = "FK_WIKI_NODE_CREATED_BY_USER_ID")
protected User createdBy;
@Column(name = "LAST_MODIFIED_ON", nullable = true, insertable = false)
@org.hibernate.search.annotations.Field(
index = org.hibernate.search.annotations.Index.UN_TOKENIZED,
store = org.hibernate.search.annotations.Store.YES
)
@org.hibernate.search.annotations.DateBridge(resolution = org.hibernate.search.annotations.Resolution.DAY)
@Searchable(description = "Modified", type = SearchableType.PASTDATE)
protected Date lastModifiedOn;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "LAST_MODIFIED_BY_USER_ID", nullable = true, insertable = false)
@org.hibernate.annotations.ForeignKey(name = "FK_WIKI_NODE_LAST_MODIFIED_BY")
protected User lastModifiedBy;
@Column(name = "WRITE_ACCESS_LEVEL", nullable = false)
protected int writeAccessLevel = 0;
@Column(name = "READ_ACCESS_LEVEL", nullable = false)
@org.hibernate.search.annotations.Field(
index = org.hibernate.search.annotations.Index.UN_TOKENIZED,
store = org.hibernate.search.annotations.Store.YES
)
@org.hibernate.search.annotations.FieldBridge(impl = PaddedIntegerBridge.class)
protected int readAccessLevel = 0;
@Column(name = "WRITE_PROTECTED", nullable = false)
protected boolean writeProtected = false;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "PARENT_NODE_ID", nullable = true)
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
@org.hibernate.annotations.ForeignKey(name = "FK_WIKI_NODE_PARENT_NODE_ID")
@org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.JOIN)
/*
@org.hibernate.annotations.LazyToOne(org.hibernate.annotations.LazyToOneOption.NO_PROXY)
*/
protected WikiNode parent;
protected WikiNode() {}
protected WikiNode(String name) {
this.name = name;
}
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public Long getAreaNumber() { return areaNumber; }
public void setAreaNumber(Long areaNumber) { this.areaNumber = areaNumber; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getWikiname() { return wikiname; }
public void setWikiname(String wikiname) { this.wikiname = wikiname; }
public Date getCreatedOn() { return createdOn; }
public void setCreatedOn(Date createdOn) { this.createdOn = createdOn; }
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; }
public int getWriteAccessLevel() { return writeAccessLevel; }
public void setWriteAccessLevel(int writeAccessLevel) { this.writeAccessLevel = writeAccessLevel; }
public int getReadAccessLevel() { return readAccessLevel; }
public void setReadAccessLevel(int readAccessLevel) { this.readAccessLevel = readAccessLevel; }
public boolean isWriteProtected() { return writeProtected; }
public void setWriteProtected(boolean writeProtected) { this.writeProtected = writeProtected; }
public WikiNode getParent() { return parent; }
public void setParent(WikiNode parent) { this.parent = parent; }
public WikiNode getArea() {
if (this.getParent() != null && this.getParent().getParent() == null) return this; // This is an area
// Else, walk up the tree until we find the area
WikiNode current = this.getParent();
while (current != null && current.getParent() != null && current.getParent().getParent() != null) {
current = current.getParent();
}
return current; // Return null if this is the Wiki ROOT
}
public int compareTo(Object o) {
return getName().compareTo( ((WikiNode)o).getName());
}
/**
* Creates copy for display or history archiving.
* <p>
* Does <b>NOT</b> copy the node id and object version, so the copy might as well be
* considered transient and can be persisted right away. If you want to store the
* copy in the audit log, call setId() manually before on the copy, passing in the
* identifier value of the original. Note that no collections or entity association
* (many-to-one, one-to-one) references are copied!
* </p>
* @param original The node to make a copy of
* @param copyLazyProperties Copy (potentially large) properties which are lazily loaded
*/
public void flatCopy(WikiNode original, boolean copyLazyProperties) {
this.areaNumber = original.getAreaNumber();
this.name = original.name;
this.wikiname = original.wikiname;
this.lastModifiedOn = original.lastModifiedOn;
this.writeAccessLevel = original.writeAccessLevel;
this.readAccessLevel = original.readAccessLevel;
}
// Need this for JSF EL expressions
public boolean isInstance(String className) {
try {
Class clazz = Class.forName(getClass().getPackage().getName() + "." + className);
return isInstance(clazz);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public boolean isInstance(Class clazz) {
return clazz.isAssignableFrom(this.getClass());
}
public boolean isOwnedByRegularUser() {
return getCreatedBy() != null
&& !User.ADMIN_USERNAME.equals(getCreatedBy().getUsername())
&& !User.GUEST_USERNAME.equals(getCreatedBy().getUsername());
}
public abstract String getPermURL(String suffix);
public abstract String getWikiURL();
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/DisplayTagCount.java
Index: DisplayTagCount.java
===================================================================
package org.jboss.seam.wiki.core.model;
import java.io.Serializable;
/**
* A simple DTO.
*
* @author Christian Bauer
*/
public class DisplayTagCount implements Comparable, Serializable {
String tag;
Long count;
public DisplayTagCount() {}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
public int compareTo(Object o) {
int result = ((DisplayTagCount)o).getCount().compareTo( this.getCount() );
return result == 0
? this.getTag().compareTo( ((DisplayTagCount)o).getTag() )
: result;
}
public String toString() {
return "TagCount(" + getCount() + "): " + getTag();
}
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiUpload.java
Index: WikiUpload.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 javax.persistence.*;
@Entity
@Table(name = "WIKI_UPLOAD")
@org.hibernate.annotations.ForeignKey(name = "FK_WIKI_UPLOAD_NODE_ID")
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
public class WikiUpload extends WikiFile {
@Column(name = "FILENAME", length = 255, nullable = false)
private String filename;
@Column(name = "FILESIZE", nullable = false)
private int filesize;
// SchemaExport needs length.. MySQL has "tinyblob", "mediumblob" and other such nonsense types
@Lob
@Column(name = "FILEDATA", nullable = false, length = 10000000)
@Basic(fetch = FetchType.LAZY) // Lazy loaded through bytecode instrumentation
private byte[] data;
@Column(name = "CONTENT_TYPE", length = 255)
private String contentType;
public WikiUpload() { super("New File"); }
public WikiUpload(String name) {
super(name);
}
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;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public String getHistoricalEntityName() {
return null;
}
public String getFeedDescription() {
return getFilename() + ", " + getContentType();
}
public String getFilenameWithoutExtension() {
if (getFilename().contains(".")) {
return getFilename().substring(0, getFilename().length()-getExtension().length()-1);
} else {
return getFilename();
}
}
public String getExtension() {
if (getFilename().contains(".")) {
return getFilename().substring( getFilename().lastIndexOf(".")+1, getFilename().length());
} else {
return null;
}
}
public void flatCopy(WikiUpload original, boolean copyLazyProperties) {
super.flatCopy(original, copyLazyProperties);
this.filename = original.getFilename();
this.filesize = original.getFilesize();
this.contentType = original.getContentType();
if (copyLazyProperties) {
this.data = original.getData();
}
}
public String getPermURL(String suffix) {
return "/servlets/files/download.seam?fileId=" + getId();
}
public String getWikiURL() {
return "/servlets/files/download.seam?fileId=" + getId();
}
public String toString() {
return "WikiUpload (" + getId() + "): " + getName() + ", " + getFilename();
}
public boolean isAttachedToDocuments() {
return true;
}
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiComment.java
Index: WikiComment.java
===================================================================
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Email;
import org.hibernate.validator.Length;
import org.jboss.seam.wiki.core.nestedset.NestedSetNode;
import org.jboss.seam.wiki.core.nestedset.NestedSetNodeInfo;
import org.jboss.seam.wiki.core.search.annotations.Searchable;
import org.jboss.seam.wiki.core.search.annotations.SearchableType;
import org.jboss.seam.wiki.core.search.annotations.CompositeSearchables;
import org.jboss.seam.wiki.core.search.annotations.CompositeSearchable;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "WIKI_COMMENT")
@org.hibernate.annotations.ForeignKey(name = "FK_WIKI_COMMENT_NODE_ID")
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
@org.hibernate.search.annotations.Indexed
@Searchable(description = "Comments")
@CompositeSearchables(
@CompositeSearchable(
description = "Content", type = SearchableType.PHRASE,
properties = {"subject", "content"}
)
)
public class WikiComment extends WikiNode implements NestedSetNode<WikiComment>, Serializable {
@Column(name = "SUBJECT", nullable = false)
@Length(min = 3, max = 255)
@org.hibernate.search.annotations.Field(index = org.hibernate.search.annotations.Index.TOKENIZED)
private String subject;
@Column(name = "FROM_USER_NAME", nullable = true)
@Length(min = 3, max = 100)
private String fromUserName;
@Column(name = "FROM_USER_EMAIL", nullable = true)
@Length(min = 0, max = 255)
@Email
private String fromUserEmail;
@Column(name = "FROM_USER_HOMEPAGE", nullable = true)
@Length(min = 0, max = 1000)
private String fromUserHomepage;
@Column(name = "CONTENT", nullable = false)
@Length(min = 1, max = 32768)
@Basic(fetch = FetchType.LAZY) // Lazy loaded through bytecode instrumentation
@org.hibernate.search.annotations.Field(index = org.hibernate.search.annotations.Index.TOKENIZED)
private String content;
@Column(name = "USE_WIKI_TEXT", nullable = false)
private boolean useWikiText = true;
@Transient
private Long level;
@Embedded
private NestedSetNodeInfo<WikiComment> nodeInfo;
public WikiComment () {
nodeInfo = new NestedSetNodeInfo<WikiComment>(this);
}
public String getSubject() { return subject; }
public void setSubject(String subject) { this.subject = subject; }
public String getFromUserName() { return fromUserName; }
public void setFromUserName(String fromUserName) { this.fromUserName = fromUserName; }
public String getFromUserEmail() { return fromUserEmail; }
public void setFromUserEmail(String fromUserEmail) { this.fromUserEmail = fromUserEmail; }
public String getFromUserHomepage() { return fromUserHomepage;}
public void setFromUserHomepage(String fromUserHomepage) { this.fromUserHomepage = fromUserHomepage; }
public String getContent() { return content; }
public void setContent(String content) { this.content = content; }
public boolean isUseWikiText() { return useWikiText; }
public void setUseWikiText(boolean useWikiText) { this.useWikiText = useWikiText; }
public Long getLevel() { return level; }
public void setLevel(Long level) { this.level = level; }
public void flatCopy(WikiComment original, boolean copyLazyProperties) {
super.flatCopy(original, copyLazyProperties);
this.subject = original.subject;
this.fromUserName = original.fromUserName;
this.fromUserEmail = original.fromUserEmail;
this.fromUserHomepage = original.fromUserHomepage;
this.useWikiText = original.useWikiText;
if (copyLazyProperties) {
this.content = original.content;
}
}
public NestedSetNodeInfo<WikiComment> getNodeInfo() {
return nodeInfo;
}
public NestedSetNodeInfo<WikiComment> getParentNodeInfo() {
if (getParent() != null && WikiComment.class.isAssignableFrom(getParent().getClass()))
return ((WikiComment)getParent()).getNodeInfo();
return null;
}
public String[] getPropertiesForGroupingInQueries() {
return new String[]{
"version", "parent",
"areaNumber", "name", "wikiname", "createdBy", "createdOn",
"lastModifiedBy", "lastModifiedOn", "readAccessLevel", "writeAccessLevel", "writeProtected",
"subject", "fromUserName", "fromUserEmail", "fromUserHomepage", "useWikiText",
};
}
public String[] getLazyPropertiesForGroupingInQueries() {
return new String[] {"content"};
}
public String getPermURL(String suffix) {
return "/" + getParentDocument().getId() + suffix + "#comment" + getId();
}
public String getWikiURL() {
return "/" + getArea().getWikiname() + "/" + getParentDocument().getWikiname() + "#comment" + getId();
}
// TODO: Everything can have comments
public WikiDocument getParentDocument() {
WikiNode current = this.getParent();
if (WikiDocument.class.isAssignableFrom(current.getClass())) return (WikiDocument)current;
while (current.getParent() != null && WikiComment.class.isAssignableFrom(current.getParent().getClass())) {
current = current.getParent();
}
return (WikiDocument)current.getParent(); // Let's just assume that the parent of a comment is at some point a document
}
public void setDerivedName(WikiNode node) {
setName(node.getName() + ".Comment" + new Date().getTime());
}
public String toString() {
return "Comment (" + getId() + "), " +
"Subject: '" + getSubject() + "'";
}
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiUploadImage.java
Index: WikiUploadImage.java
===================================================================
package org.jboss.seam.wiki.core.model;
import javax.persistence.*;
@Entity
@Table(name = "WIKI_UPLOAD_IMAGE")
@org.hibernate.annotations.ForeignKey(name = "FK_WIKI_UPLOAD_IMAGE_NODE_ID")
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
public class WikiUploadImage extends WikiUpload {
@Column(name = "SIZE_X")
private int sizeX;
@Column(name = "SIZE_Y")
private int sizeY;
@Column(name = "THUMBNAIL")
private char thumbnail = 'A'; // Disable embedding by default, attach
// SchemaExport needs length.. MySQL has "tinyblob", "mediumblob" and other such nonsense types
@Lob
@Column(name = "THUMBNAIL_DATA", length = 1000000, nullable = true)
@Basic(fetch = FetchType.LAZY) // Lazy loaded through bytecode instrumentation
private byte[] thumbnailData;
public WikiUploadImage() {}
public WikiUploadImage(int sizeX, int sizeY, 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 byte[] getThumbnailData() {
return thumbnailData;
}
public void setThumbnailData(byte[] thumbnailData) {
this.thumbnailData = thumbnailData;
}
public boolean isAttachedToDocuments() {
return getThumbnail() == 'A';
}
public void flatCopy(WikiUploadImage original, boolean copyLazyProperties) {
super.flatCopy(original, copyLazyProperties);
this.sizeX = original.sizeX;
this.sizeY = original.sizeY;
this.thumbnail = original.thumbnail;
if (copyLazyProperties) {
this.thumbnailData = original.thumbnailData;
}
}
public String toString() {
return "WikiUploadImage (" + getId() + "): " + getName()
+ ", " + getFilename() + ", Size: " + getSizeX() + "x" + getSizeY();
}
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiDocumentDefaults.java
Index: WikiDocumentDefaults.java
===================================================================
package org.jboss.seam.wiki.core.model;
public class WikiDocumentDefaults {
public String[] getDefaultHeaderMacros() {
return new String[0];
}
public String[] getDefaultContentMacros() {
return new String[0];
}
public String[] getDefaultFooterMacros() {
return new String[0];
}
public String getDefaultHeader() {
return "";
}
public String getDefaultContent() {
return "Edit this text...";
}
public String getDefaultFooter() {
return "";
}
public String getDefaultName() {
return "New Document";
}
public void setDefaults(WikiDocument document) {}
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiDirectory.java
Index: WikiDirectory.java
===================================================================
package org.jboss.seam.wiki.core.model;
import org.hibernate.validator.Length;
import org.jboss.seam.wiki.core.nestedset.NestedSetNode;
import org.jboss.seam.wiki.core.nestedset.NestedSetNodeInfo;
import org.jboss.seam.wiki.core.nestedset.query.NestedSetDuplicator;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Table(name = "WIKI_DIRECTORY")
@org.hibernate.annotations.ForeignKey(name = "FK_WIKI_DIRECTORY_NODE_ID")
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
public class WikiDirectory extends WikiNode implements NestedSetNode<WikiDirectory>, Serializable {
@Column(name = "DESCRIPTION", nullable = true)
@Length(min = 0, max = 512)
private String description;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DEFAULT_FILE_ID", nullable = true, unique = true)
@org.hibernate.annotations.ForeignKey(name = "FK_WIKI_DIRECTORY_DEFAULT_FILE_ID")
@org.hibernate.annotations.LazyToOne(org.hibernate.annotations.LazyToOneOption.NO_PROXY)
private WikiFile defaultFile;
@OneToOne(fetch = FetchType.LAZY, mappedBy = "directory", cascade = CascadeType.PERSIST)
@org.hibernate.annotations.LazyToOne(org.hibernate.annotations.LazyToOneOption.NO_PROXY)
private Feed feed;
@Embedded
private NestedSetNodeInfo<WikiDirectory> nodeInfo;
public WikiDirectory() {
nodeInfo = new NestedSetNodeInfo<WikiDirectory>(this);
}
public WikiDirectory(String name) {
super(name);
nodeInfo = new NestedSetNodeInfo<WikiDirectory>(this);
}
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
/**
* Careful calling this, it always returns the assigned File, even if
* the user has a lower access level. Hibernate filters don't filter many-to-one
* because if we have the id, we get the instance.
*
* @return WikiFile The assigned default starting file of this directory
*/
public WikiFile getDefaultFile() { return defaultFile; }
public void setDefaultFile(WikiFile defaultFile) { this.defaultFile = defaultFile; }
public Feed getFeed() { return feed; }
public void setFeed(Feed feed) { this.feed = feed; }
public void flatCopy(WikiDirectory original, boolean copyLazyProperties) {
super.flatCopy(original, copyLazyProperties);
this.description = original.description;
this.nodeInfo = original.nodeInfo;
}
public NestedSetNodeInfo<WikiDirectory> getNodeInfo() {
return nodeInfo;
}
public NestedSetNodeInfo<WikiDirectory> getParentNodeInfo() {
if (getParent() != null && WikiDirectory.class.isAssignableFrom(getParent().getClass()))
return ((WikiDirectory)getParent()).getNodeInfo();
return null;
}
public String[] getPropertiesForGroupingInQueries() {
return new String[]{
"version", "parent",
"areaNumber", "name", "wikiname", "createdBy", "createdOn",
"lastModifiedBy", "lastModifiedOn", "readAccessLevel", "writeAccessLevel", "writeProtected",
"defaultFile", "description"
};
}
public String[] getLazyPropertiesForGroupingInQueries() {
return new String[0];
}
public String getPermURL(String suffix) {
return "/" + getId() + suffix;
}
public String getWikiURL() {
if (getArea() == null) return "/"; // Wiki ROOT
if (getArea().getWikiname().equals(getWikiname())) {
return "/" + getArea().getWikiname();
} else {
return "/" + getArea().getWikiname() + "/" + getWikiname();
}
}
public String toString() {
return "Directory (" + getId() + "): " + getName();
}
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Queries.hbm.xml
Index: Queries.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">
<!--
Workarounds for Hibernate bugs, mostly.
@author Christian Bauer
-->
<hibernate-mapping package="org.jboss.seam.wiki.core.model" default-access="field">
<!--
TODO: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1657
-->
<sql-query name="updateNestedSet.org.jboss.seam.wiki.core.model.WikiComment">
<query-param name="left" type="long"/>
<query-param name="right" type="long"/>
<query-param name="thread" type="long"/>
<query-param name="id" type="long"/>
update WIKI_COMMENT set NS_LEFT = :left, NS_RIGHT = :right, NS_THREAD = :thread where NODE_ID = :id
</sql-query>
<sql-query name="updateNestedSet.org.jboss.seam.wiki.core.model.WikiDirectory">
<query-param name="left" type="long"/>
<query-param name="right" type="long"/>
<query-param name="thread" type="long"/>
<query-param name="id" type="long"/>
update WIKI_DIRECTORY set NS_LEFT = :left, NS_RIGHT = :right, NS_THREAD = :thread where NODE_ID = :id
</sql-query>
<sql-query name="updateNestedSet.org.jboss.seam.wiki.test.nestedset.TestDirectory">
<query-param name="left" type="long"/>
<query-param name="right" type="long"/>
<query-param name="thread" type="long"/>
<query-param name="id" type="long"/>
update TEST_DIRECTORY set NS_LEFT = :left, NS_RIGHT = :right, NS_THREAD = :thread where ITEM_ID = :id
</sql-query>
</hibernate-mapping>
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiDocumentFeedEntry.java
Index: WikiDocumentFeedEntry.java
===================================================================
package org.jboss.seam.wiki.core.model;
import javax.persistence.*;
@Entity
@DiscriminatorValue("WIKI_DOCUMENT")
public class WikiDocumentFeedEntry extends FeedEntry {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "WIKI_DOCUMENT_ID", nullable = true)
@org.hibernate.annotations.ForeignKey(name = "FK_FEEDENTRY_WIKI_DOCUMENT_ID")
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
private WikiDocument document;
public WikiDocument getDocument() {
return document;
}
public void setDocument(WikiDocument document) {
this.document = document;
}
public int getReadAccessLevel() {
return getDocument().getReadAccessLevel();
}
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiDocument.java
Index: WikiDocument.java
===================================================================
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 java.io.Serializable;
import java.util.Set;
import java.util.LinkedHashSet;
@Entity
@Table(name = "WIKI_DOCUMENT")
@org.hibernate.annotations.ForeignKey(name = "FK_WIKI_DOCUMENT_NODE_ID")
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
@org.hibernate.search.annotations.Indexed
@Searchable(description = "Documents")
public class WikiDocument extends WikiFile implements Serializable {
@Column(name = "NAME_AS_TITLE", nullable = false)
private boolean nameAsTitle = true;
@Column(name = "ENABLE_COMMENTS", nullable = false)
private boolean enableComments = false;
@Column(name = "ENABLE_COMMENT_FORM", nullable = false)
private boolean enableCommentForm = true;
@Column(name = "ENABLE_COMMENTS_ON_FEEDS", nullable = false)
private boolean enableCommentsOnFeeds = true;
@Column(name = "HEADER", nullable = true)
@Length(min = 0, max = 4000)
private String header;
@Column(name = "HEADER_MACROS", nullable = true, length = 4000)
private String headerMacrosString;
@Transient
private Set<WikiMacro> headerMacros = new LinkedHashSet<WikiMacro>();
@Column(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 = "CONTENT_MACROS", nullable = true, length = 4000)
private String contentMacrosString;
@Transient
private Set<WikiMacro> contentMacros = new LinkedHashSet<WikiMacro>();
@Column(name = "FOOTER", nullable = true)
@Length(min = 0, max = 4000)
private String footer;
@Column(name = "FOOTER_MACROS", nullable = true, length = 4000)
private String footerMacrosString;
@Transient
private Set<WikiMacro> footerMacros = new LinkedHashSet<WikiMacro>();
public WikiDocument() {
super();
WikiDocumentDefaults defaults = new WikiDocumentDefaults();
setDefaults(defaults);
}
public WikiDocument(WikiDocumentDefaults defaults) {
super(defaults.getDefaultName());
setDefaults(defaults);
}
@Override
@org.hibernate.search.annotations.Field(index = org.hibernate.search.annotations.Index.TOKENIZED)
@Searchable(description = "Name")
public String getName() {
return super.getName();
}
public String getHeader() { return header; }
public void setHeader(String header) { this.header = header; }
public String getContent() { return content; }
public void setContent(String content) { this.content = content; }
public String getFooter() { return footer; }
public void setFooter(String footer) { this.footer = footer; }
public boolean isNameAsTitle() { return nameAsTitle; }
public void setNameAsTitle(boolean nameAsTitle) { this.nameAsTitle = nameAsTitle; }
public boolean isEnableComments() { return enableComments; }
public void setEnableComments(boolean enableComments) { this.enableComments = enableComments; }
public boolean isEnableCommentForm() { return enableCommentForm; }
public void setEnableCommentForm(boolean enableCommentForm) { this.enableCommentForm = enableCommentForm; }
public boolean isEnableCommentsOnFeeds() { return enableCommentsOnFeeds; }
public void setEnableCommentsOnFeeds(boolean enableCommentsOnFeeds) { this.enableCommentsOnFeeds = enableCommentsOnFeeds; }
public String getHeaderMacrosString() { return headerMacrosString; }
public void setHeaderMacrosString(String headerMacrosString) { this.headerMacrosString = headerMacrosString; }
public String getContentMacrosString() { return contentMacrosString; }
public void setContentMacrosString(String contentMacrosString) { this.contentMacrosString = contentMacrosString; }
public String getFooterMacrosString() { return footerMacrosString; }
public void setFooterMacrosString(String footerMacrosString) { this.footerMacrosString = footerMacrosString; }
public Set<WikiMacro> getHeaderMacros() { return headerMacros; }
public void setHeaderMacros(Set<WikiMacro> headerMacros) { this.headerMacros = headerMacros; }
public Set<WikiMacro> getContentMacros() { return contentMacros; }
public void setContentMacros(Set<WikiMacro> contentMacros) { this.contentMacros = contentMacros; }
public Set<WikiMacro> getFooterMacros() { return footerMacros; }
public void setFooterMacros(Set<WikiMacro> footerMacros) { this.footerMacros = footerMacros; }
public void flatCopy(WikiDocument original, boolean copyLazyProperties) {
super.flatCopy(original, copyLazyProperties);
this.nameAsTitle = original.nameAsTitle;
this.enableComments = original.enableComments;
this.enableCommentForm = original.enableCommentForm;
this.enableCommentsOnFeeds = original.enableCommentsOnFeeds;
this.headerMacrosString = original.headerMacrosString;
this.contentMacrosString = original.contentMacrosString;
this.footerMacrosString = original.footerMacrosString;
if (copyLazyProperties) {
this.content = original.content;
}
}
public void rollback(WikiDocument revision) {
super.rollback(revision);
this.content = revision.content;
}
public boolean macroPresent(String macroName) {
WikiMacro wikiMacro = new WikiMacro(macroName);
return getHeaderMacros().contains(wikiMacro) ||
getContentMacros().contains(wikiMacro) ||
getFooterMacros().contains(wikiMacro);
}
public String getFeedDescription() {
return getContent();
}
public String getHistoricalEntityName() {
return "HistoricalWikiDocument";
}
public String getPermURL(String suffix) {
return "/" + getId() + suffix;
}
public String getWikiURL() {
return "/" + getArea().getWikiname() + "/" + getWikiname();
}
public void setDefaults(WikiDocumentDefaults defaults) {
setName(defaults.getDefaultName());
setHeaderMacrosString( appendMacrosAsString(defaults.getDefaultHeaderMacros()) );
setHeader( appendMacrosAsWikiTextString(defaults.getDefaultHeaderMacros()) + defaults.getDefaultHeader() );
setContentMacrosString( appendMacrosAsString(defaults.getDefaultContentMacros()) );
setContent( appendMacrosAsWikiTextString(defaults.getDefaultContentMacros()) + defaults.getDefaultContent());
setFooterMacrosString( appendMacrosAsString(defaults.getDefaultFooterMacros()) );
setFooter( appendMacrosAsWikiTextString(defaults.getDefaultFooterMacros()) + defaults.getDefaultFooter());
defaults.setDefaults(this);
}
private String appendMacrosAsString(String[] macros) {
if (macros.length == 0) return "";
StringBuilder macrosString = new StringBuilder();
for (String s : macros) {
macrosString.append(s).append(" ");
}
return macrosString.substring(0, macrosString.length() - 1);
}
private String appendMacrosAsWikiTextString(String[] macros) {
if (macros.length == 0) return "";
StringBuilder macrosString = new StringBuilder();
for (String s : macros) {
macrosString.append("[<=").append(s).append("]\n");
}
return macrosString.toString();
}
public String toString() {
return "Document (" + getId() + "): " + getName();
}
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiMacro.java
Index: WikiMacro.java
===================================================================
package org.jboss.seam.wiki.core.model;
import java.io.Serializable;
import java.util.SortedMap;
import java.util.TreeMap;
public class WikiMacro implements Serializable {
private String name;
private SortedMap<String,String> params = new TreeMap<String,String>();
public WikiMacro(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public SortedMap<String, String> getParams() {
return params;
}
public void setParams(SortedMap<String, String> params) {
this.params = params;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
WikiMacro macro = (WikiMacro) o;
if (!name.equals(macro.name)) return false;
return true;
}
public int hashCode() {
return name.hashCode();
}
public String toString() {
return "WikiMacro: " + getName() + " Params: " + getParams().size();
}
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiFile.java
Index: WikiFile.java
===================================================================
package org.jboss.seam.wiki.core.model;
import javax.persistence.*;
import java.util.*;
@Entity
@Table(name = "WIKI_FILE")
@org.hibernate.annotations.ForeignKey(name = "FK_WIKI_FILE_NODE_ID")
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
public abstract class WikiFile extends WikiNode {
@org.hibernate.annotations.CollectionOfElements(fetch = FetchType.LAZY)
@JoinTable(name = "WIKI_TAG", joinColumns = @JoinColumn(name = "FILE_ID"))
@Column(name = "TAG", nullable = false)
@org.hibernate.annotations.ForeignKey(name = "FK_WIKI_TAG_FILE_ID")
@org.hibernate.annotations.Sort(type = org.hibernate.annotations.SortType.NATURAL)
//@org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
@org.hibernate.annotations.BatchSize(size = 20)
private SortedSet<String> tags = new TreeSet<String>();
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "WIKI_FILE_LINK",
joinColumns = @JoinColumn(name = "SOURCE_WIKI_FILE_ID", nullable = false, updatable = false),
inverseJoinColumns= @JoinColumn(name = "TARGET_WIKI_FILE_ID", nullable = false, updatable = false)
)
@org.hibernate.annotations.ForeignKey(name = "FK_SOURCE_WIKI_FILE_ID", inverseName = "FK_TARGET_WIKI_FILE_ID")
@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.EXTRA)
protected Set<WikiFile> outgoingLinks = new HashSet<WikiFile>();
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "outgoingLinks")
@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.EXTRA)
protected Set<WikiFile> incomingLinks = new HashSet<WikiFile>();
// Uses Hibernates ability to map the same class twice, see HistoricalWikiFile.hbm.xml
@Transient
private Long historicalFileId;
@Transient
protected String lastModifiedByUsername;
@Column(name = "FILE_REVISION", nullable = false)
private int revision = 0;
protected WikiFile() {}
protected WikiFile(String name) {
super(name);
}
public SortedSet<String> getTags() { return tags; }
public void setTags(SortedSet<String> tags) { this.tags = tags; }
public Set<WikiFile> getOutgoingLinks() { return outgoingLinks; }
public void setOutgoingLinks(Set<WikiFile> outgoingLinks) { this.outgoingLinks = outgoingLinks; }
public Set<WikiFile> getIncomingLinks() { return incomingLinks; }
public void setIncomingLinks(Set<WikiFile> incomingLinks) { this.incomingLinks = incomingLinks; }
public Long getHistoricalFileId() { return historicalFileId; }
public String getLastModifiedByUsername() { return lastModifiedByUsername; }
@Override
public void setLastModifiedBy(User lastModifiedBy) {
super.setLastModifiedBy(lastModifiedBy);
lastModifiedByUsername = lastModifiedBy.getUsername();
}
public int getRevision() { return revision; }
public void setRevision(int revision) { this.revision = revision; }
public void incrementRevision() {
revision++;
}
public boolean isHistoricalRevision() {
return historicalFileId!=null;
}
public void flatCopy(WikiFile original, boolean copyLazyProperties) {
super.flatCopy(original, copyLazyProperties);
this.revision = original.revision;
}
public void rollback(WikiFile revision) {
this.name = revision.name;
this.wikiname = revision.wikiname;
}
public List<String> getTagsAsList() {
return new ArrayList<String>(getTags());
}
public boolean isTagged(String tag) {
return getTags().contains(tag);
}
public String getTagsCommaSeparated() {
if (getTags().size() == 0) return null;
StringBuilder tagString = new StringBuilder();
for (String s : getTags()) {
tagString.append(s).append(", ");
}
return tagString.length()>0
? tagString.toString().substring(0, tagString.toString().length()-2) // Cut last comma
: tagString.toString();
}
public void setTagsCommaSeparated(String tagString) {
getTags().clear();
if (tagString == null || tagString.length() == 0) return;
String[] tagArray = tagString.split(",");
for (String s : tagArray) {
getTags().add(s.trim());
}
}
public abstract String getHistoricalEntityName();
public abstract String getFeedDescription();
}
1.1 date: 2007/12/19 04:29:20; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiMenuItem.java
Index: WikiMenuItem.java
===================================================================
package org.jboss.seam.wiki.core.model;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Table(name = "WIKI_MENU_ITEM")
public class WikiMenuItem implements Serializable {
@Id
@Column(name = "DIRECTORY_ID")
private Long directoryId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "DIRECTORY_ID", insertable = false, updatable = false)
@org.hibernate.annotations.ForeignKey(name = "FK_MENU_ITEM_DIRECTORY_ID")
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
private WikiDirectory directory;
@Column(name = "DISPLAY_POSITION", nullable = false)
private long displayPosition;
protected WikiMenuItem() {}
public WikiMenuItem(WikiDirectory directory) {
this.directoryId = directory.getId();
setDirectory(directory);
}
public Long getDirectoryId() {
return directoryId;
}
public void setDirectoryId(Long directoryId) {
this.directoryId = directoryId;
}
public WikiDirectory getDirectory() {
return directory;
}
public void setDirectory(WikiDirectory directory) {
this.directory = directory;
}
public long getDisplayPosition() {
return displayPosition;
}
public void setDisplayPosition(long displayPosition) {
this.displayPosition = displayPosition;
}
public String toString() {
return "Menu Item position " + getDisplayPosition() + ": " + getDirectory();
}
}
More information about the jboss-cvs-commits
mailing list