Alejandro,
Would you mind fixing this bug (see stack dump below) ... reproducible in roster demo. This one seems to be the last of the lazyinitialization exceptions that the code in this message repairs. But this last one may turn out to be a hibernate bug.
My modeling is fine and cascades are fine as well as equals/hashCode which are trails compliant like simple and ajaxlist, etc...
Seems unable to operate collections whose pojos operate inheritence atleast for ones that span several delegation levels specifically
League<---Organization<---coaches.
Best regards
Ken in nashua
I implemented the following in the persistence service
public void reattachCollection(Object[] models)
{
if ( models != null )
for ( int i = 0; i < models.length; i++)
reattach (models[i]);
}
public void mergeCollection(Object[] models)
{
if ( models != null )
for ( int i = 0; i < models.length; i++)
merge (models[i]);
}
@Transactional
public void reattach(Object model)
{
getSession().lock(model, LockMode.NONE);
}
@Transactional(readOnly=false)
public <T> T merge(T instance)
{
Object mergedInstance;
FlushMode previousFlushMode = getSession().getFlushMode();
getSession().setFlushMode(FlushMode.COMMIT);
try {
mergedInstance = getHibernateTemplate().merge(instance);
}
catch (DataAccessException dex) {
throw new PersistenceException(dex);
} finally {
getSession().setFlushMode(previousFlushMode);
}
return (T) mergedInstance;
}
And am using cascade = CascadeType.ALL
Organization.JAVA
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = 'coach_organization_fk', insertable = true, updatable = true, nullable = true)
@Collection(child = true, inverse = 'organization')
@PropertyDescriptor(readOnly = false, searchable = true)
public Set<Coach> getCoaches()
{
return coaches;
}
Coach.JAVA
@ManyToOne
@JoinColumn(name = 'coach_organization_fk', insertable = false, updatable = true, nullable = true)
public Organization getOrganization()
{
return organization;
}
You may continue by restarting the session.
[ +/- ] Exception: failed to lazily initialize a collection of role: org.trails.demo.Organization.coaches, no session or session was closed org.apache.hivemind.ApplicationRuntimeException
|
component:
| $HibernateEditPage_37@3c1[OrganizationEdit]
|
location:
| context:/WEB-INF/DefaultEdit.page, line 2, column 63
1
| <!DOCTYPEpage-specification PUBLIC '-//Apache Software Foundation//TapestrySpecification 4.1//EN''http://jakarta.apache.org/tapestry/dtd/Tapestry_4_1.dtd'>
| 2
| <page-specification class='org.trails.page.HibernateEditPage'>
| 3
|
| 4
| <property name='model' persist='session'/>
| 5
| <property name='modelNew' persist='session'/>
| 6
| <property name='classDescriptor' persist='session'/>
| 7
|
|
|
|
[ +/- ] Exception: failed to lazily initialize a collection of role: org.trails.demo.Organization.coaches, no session or session was closed
Need to know the score, the latest news, or you need your HotmailĀ®-get your "fix".
Check it out.
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/EditCollectionTest.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/EditCollectionTest.java (revision 0)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/EditCollectionTest.java (revision 0)
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2004 Chris Nelson
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ */
+package org.trails.component;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+import ognl.Ognl;
+
+import org.apache.tapestry.contrib.palette.SortMode;
+import org.apache.tapestry.form.IPropertySelectionModel;
+import org.jmock.Mock;
+import org.trails.demo.Coach;
+import org.trails.demo.League;
+import org.trails.demo.Organization;
+import org.trails.descriptor.CollectionDescriptor;
+import org.trails.descriptor.IClassDescriptor;
+import org.trails.descriptor.IdentifierDescriptor;
+import org.trails.descriptor.TrailsClassDescriptor;
+import org.trails.page.PageResolver;
+
+public class EditCollectionTest extends ComponentTest {
+
+ League foo;
+ Organization baz1;
+ Organization baz2;
+ Coach bing1;
+ Coach bing2;
+
+ Mock pageResolverMock = new Mock(PageResolver.class);
+
+ public void setUp() {
+ foo = new League();
+
+ baz1 = new Organization();
+ baz1.setName("baz 1");
+ baz1.setId(new Integer("1"));
+ baz2 = new Organization();
+ baz2.setName("baz 2");
+ baz2.setId(new Integer("2"));
+ foo.getOrganizations().add(baz1);
+ foo.getOrganizations().add(baz2);
+
+ bing1 = new Coach();
+ bing1.setEmailAddress("bing 1");
+ bing1.setId(new Integer("3"));
+ bing2 = new Coach();
+ bing2.setEmailAddress("bing 2");
+ bing2.setId(new Integer("4"));
+ baz1.getCoaches().add(bing1);
+ baz1.getCoaches().add(bing2);
+ baz2.getCoaches().add(bing1);
+ baz2.getCoaches().add(bing2);
+ }
+
+ public void testOgnl() throws Exception {
+ EditCollection editCollection = buildEditCollection("bings",
+ Coach.class, null);
+ Ognl.getValue("collectionDescriptor.childRelationship", editCollection);
+ }
+
+ public void testBuildSelectedList() throws Exception {
+ EditCollection editCollection = buildEditCollection("bazzes",
+ Organization.class, foo.getOrganizations());
+ editCollection.setSelected(editCollection.buildSelectedList());
+ assertEquals("2 in list", 2, editCollection.getSelected().size());
+ Boolean toBeDeleted = (Boolean) editCollection.getSelected().get(1);
+ assertFalse("not to be deleted", toBeDeleted.booleanValue());
+ }
+
+ public void testRemove() throws Exception {
+ EditCollection editCollection = buildEditCollection("organizations",
+ Organization.class, foo.getOrganizations());
+ ArrayList<Boolean> deletedList = new ArrayList<Boolean>();
+ deletedList.add(true);
+ deletedList.add(false);
+
+ // dunno what order they're in really
+ Iterator bazIterator = foo.getOrganizations().iterator();
+ baz1 = (Organization) bazIterator.next();
+ baz2 = (Organization) bazIterator.next();
+ editCollection.setSelected(deletedList);
+ editCollection.remove();
+ // System.out.println("size of collection: " +
+ // foo.getOrganizations().size());
+ assertFalse("baz1 removed", foo.getOrganizations().contains(baz1));
+ assertTrue("baz2 not removed", foo.getOrganizations().contains(baz2));
+ }
+
+ public void testMove() throws Exception {
+ EditCollection editCollection = buildEditCollection("coaches",
+ Coach.class, baz1.getCoaches());
+ ArrayList<Boolean> selectedList = new ArrayList<Boolean>();
+
+ selectedList.add(false);
+ selectedList.add(true);
+ editCollection.setSelected(selectedList);
+ editCollection.moveUp();
+ assertEquals("still 2", 2, baz1.getCoaches().size());
+ assertEquals("bing2 moved up", bing2, baz1.getCoaches().toArray()[0]);
+
+ selectedList.set(0, true);
+ selectedList.set(1, false);
+ editCollection.moveDown();
+ assertEquals("still 2", 2, baz1.getCoaches().size());
+ assertEquals("bing2 moved down", bing2, baz1.getCoaches().toArray()[1]);
+ }
+
+ public void testSortMode() throws Exception {
+ EditCollection editCollection = buildEditCollection("bings",
+ Coach.class, new ArrayList());
+ assertEquals("user sortable", SortMode.USER, editCollection
+ .getSortMode());
+ }
+
+ public void testGetSelectionModel() throws Exception {
+ EditCollection editCollection = buildEditCollection("bings",
+ Coach.class, new ArrayList());
+ Coach bing1 = new Coach();
+ bing1.setEmailAddress("bing 1");
+ bing1.setId(new Integer("6"));
+ editCollection.getCollectionDescriptor().setChildRelationship(true);
+ editCollection.getCollection().add(bing1);
+
+ IClassDescriptor classDescriptor = new TrailsClassDescriptor(
+ Coach.class);
+ classDescriptor.getPropertyDescriptors().add(
+ new IdentifierDescriptor(League.class, Coach.class));
+ descriptorServiceMock.expects(once()).method("getClassDescriptor")
+ .with(eq(Coach.class)).will(returnValue(classDescriptor));
+
+ IPropertySelectionModel selectionModel = editCollection
+ .getSelectionModel();
+ assertEquals("has 1", 1, selectionModel.getOptionCount());
+ assertEquals("is bing1", bing1, selectionModel.getOption(0));
+
+ }
+
+ private EditCollection buildEditCollection(String property,
+ Class elementType, Collection collection) {
+ CollectionDescriptor collectionDescriptor = new CollectionDescriptor(
+ League.class, property, Set.class);
+ collectionDescriptor.setElementType(elementType);
+ collectionDescriptor.setChildRelationship(true);
+
+ return (EditCollection) creator.newInstance(EditCollection.class,
+ new Object[] { "persistenceService", persistenceMock.proxy(),
+ "descriptorService", descriptorServiceMock.proxy(),
+ "pageResolver", pageResolverMock.proxy(),
+ "collectionDescriptor", collectionDescriptor,
+ "collection", collection, "model", foo });
+ }
+}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/ComponentsReuseTest.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/ComponentsReuseTest.java (revision 0)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/ComponentsReuseTest.java (revision 0)
@@ -0,0 +1,72 @@
+package org.trails.component;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+
+import junit.framework.TestCase;
+import ognl.Ognl;
+import ognl.OgnlException;
+
+import org.apache.tapestry.test.Creator;
+import org.trails.demo.Coach;
+import org.trails.demo.League;
+import org.trails.demo.Organization;
+
+public class ComponentsReuseTest extends TestCase {
+ protected Creator creator = new Creator();
+ protected League league;
+ protected Organization organization;
+
+ public void setUp() {
+ league = (League) creator.newInstance(League.class, new Object[] {
+ "organizations", new HashSet() });
+ assertNotNull(league);
+ assertNotNull(league.getOrganizations());
+ organization = (Organization) creator.newInstance(Organization.class,
+ new Object[] { "coaches", new ArrayList() });
+ assertNotNull(organization);
+ assertNotNull(organization.getCoaches());
+
+ assertEquals("size is 0", 0, organization.getCoaches().size());
+ organization.getCoaches().add(new Coach());
+ assertEquals("size is 1", 1, organization.getCoaches().size());
+ }
+
+ public void testAddCoach() {
+ try {
+ assertNotNull(Ognl.getValue("coaches", organization));
+ assertEquals("size is 1", 1, organization.getCoaches().size());
+ organization.getCoaches().add(new Coach());
+ assertEquals("size is 2", 2, organization.getCoaches().size());
+ assertNotNull(Ognl.getValue("coaches", organization));
+
+ Coach coach0 = (Coach) organization.getCoaches().toArray()[0];
+ assertEquals("size is 0", 0, coach0.getRoles().size());
+ assertNotNull(Ognl.getValue("roles", coach0));
+ } catch (OgnlException e) {
+ fail();
+ }
+ }
+ public void testOgnlBaseClassProperty() {
+ try {
+ Coach coach0 = (Coach) organization.getCoaches().toArray()[0];
+ assertEquals("size is 0", 0, coach0.getRoles().size());
+ assertNotNull(Ognl.getValue("roles", coach0));
+ organization.getCoaches().add(new Coach());
+ organization.getCoaches().add(new Coach());
+ organization.getCoaches().add(new Coach());
+ organization.getCoaches().add(new Coach());
+ organization.getCoaches().add(new Coach());
+ organization.getCoaches().add(new Coach());
+ organization.getCoaches().add(new Coach());
+ organization.getCoaches().add(new Coach());
+ organization.getCoaches().add(new Coach());
+
+ for ( Coach coach : organization.getCoaches() ) {
+ assertNotNull(Ognl.getValue("roles", coach));
+ }
+ } catch (OgnlException e) {
+ fail();
+ }
+ }
+}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Role.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Role.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Role.java (working copy)
@@ -3,19 +3,8 @@
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
+import javax.persistence.*;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
-import javax.persistence.Table;
-import javax.persistence.Transient;
-import javax.persistence.Version;
-
import org.acegisecurity.GrantedAuthority;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
@@ -33,15 +22,12 @@
{
private Integer id;
-
private String name;
-
private String description;
-
private Integer version;
-
private Set<User> users = new HashSet<User>();
+
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@PropertyDescriptor(index = 0)
@@ -58,7 +44,7 @@
@PropertyDescriptor(index = 1)
@Length(min = 1, max = 20)
@NotNull
- // @Id @GeneratedValue(strategy = GenerationType.NONE)
+// @Id @GeneratedValue(strategy = GenerationType.NONE)
public String getName()
{
return this.name;
@@ -82,12 +68,16 @@
}
@ManyToMany(fetch = FetchType.EAGER)
- @JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "role_ID") }, inverseJoinColumns = { @JoinColumn(name = "user_ID") })
+ @JoinTable(
+ name = "user_role",
+ joinColumns = {@JoinColumn(name = "role_ID")},
+ inverseJoinColumns = {@JoinColumn(name = "user_ID")})
public Set<User> getUsers()
{
return users;
}
+
public void setUsers(Set<User> users)
{
this.users = users;
@@ -105,24 +95,28 @@
this.version = version;
}
- public boolean equals(Object o)
+ public boolean equals(Object rhs)
{
- if (this == o)
+ if (this == rhs)
return true;
- if (o == null || getClass() != o.getClass())
+ if (rhs == null)
return false;
-
- final Role role = (Role) o;
-
- if (id != null ? !id.equals(role.id) : role.id != null)
+ if (!(rhs instanceof Person))
return false;
+
+ final Role castedObject = (Role) rhs;
+ //if (id != null ? !id.equals(role.id) : role.id != null) return false;
+
+ if ( ! this.getName().equalsIgnoreCase(castedObject.getName()) )
+ return false;
return true;
}
public int hashCode()
{
- return (id != null ? id.hashCode() : super.hashCode());
+ //return (id != null ? id.hashCode() : super.hashCode());
+ return getName().hashCode();
}
public String toString()
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/League.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/League.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/League.java (working copy)
@@ -10,6 +10,7 @@
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@@ -23,15 +24,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.validator.NotNull;
-import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition;
-import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType;
import org.trails.descriptor.annotation.BlobDescriptor;
import org.trails.descriptor.annotation.ClassDescriptor;
import org.trails.descriptor.annotation.Collection;
import org.trails.descriptor.annotation.PropertyDescriptor;
+import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition;
+import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType;
import org.trails.security.annotation.RemoveRequiresRole;
import org.trails.security.annotation.UpdateRequiresRole;
-import org.trails.demo.DatePattern;
import org.trails.validation.ValidateUniqueness;
/**
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Organization.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Organization.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Organization.java (working copy)
@@ -1,9 +1,11 @@
package org.trails.demo;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
@@ -26,17 +28,16 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.validator.NotNull;
-import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition;
-import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType;
import org.trails.descriptor.annotation.BlobDescriptor;
import org.trails.descriptor.annotation.ClassDescriptor;
import org.trails.descriptor.annotation.Collection;
import org.trails.descriptor.annotation.HardOneToOne;
import org.trails.descriptor.annotation.PropertyDescriptor;
import org.trails.descriptor.annotation.HardOneToOne.Identity;
+import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition;
+import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType;
import org.trails.security.annotation.RemoveRequiresRole;
import org.trails.security.annotation.UpdateRequiresRole;
-import org.trails.demo.DatePattern;
import org.trails.validation.ValidateUniqueness;
/**
@@ -117,7 +118,7 @@
return demographics;
}
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne
@JoinColumn(name = "organization_league_fk", insertable = false, updatable = true, nullable = true)
public League getLeague()
{
@@ -134,17 +135,16 @@
return director;
}
- @OneToMany
+ @OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "coach_organization_fk", insertable = true, updatable = true, nullable = true)
@Collection(child = true, inverse = "organization")
@PropertyDescriptor(readOnly = false, searchable = true)
- // @OrderBy("lastName")
public Set<Coach> getCoaches()
{
return coaches;
}
- @OneToMany
+ @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name = "team_organization_fk", insertable = true, updatable = true, nullable = true)
@Collection(child = true, inverse = "organization")
@PropertyDescriptor(readOnly = false)
@@ -319,9 +319,9 @@
return true;
if (rhs == null)
return false;
- if (!(rhs instanceof Organization))
+ if (!(rhs instanceof League))
return false;
- final Organization castedObject = (Organization) rhs;
+ final League castedObject = (League) rhs;
if (getId() == null)
{
if (castedObject.getId() != null)
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Person.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Person.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Person.java (working copy)
@@ -11,8 +11,6 @@
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@@ -22,6 +20,7 @@
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
+import javax.persistence.MappedSuperclass;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Transient;
@@ -32,16 +31,17 @@
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.hibernate.validator.NotNull;
-import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition;
-import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType;
+import org.hibernate.annotations.ForeignKey;
import org.trails.descriptor.annotation.BlobDescriptor;
import org.trails.descriptor.annotation.ClassDescriptor;
import org.trails.descriptor.annotation.PropertyDescriptor;
+import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition;
+import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType;
import org.trails.security.annotation.RemoveRequiresRole;
+import org.trails.security.annotation.UpdateRequiresAssociation;
import org.trails.security.annotation.UpdateRequiresRole;
+import org.trails.security.annotation.ViewRequiresAssociation;
import org.trails.security.annotation.ViewRequiresRole;
-import org.trails.demo.DatePattern;
import org.trails.validation.ValidateUniqueness;
/**
@@ -55,73 +55,48 @@
@ViewRequiresRole( { "ROLE_ADMIN", "ROLE_MANAGER", "ROLE_USER" })
@ValidateUniqueness(property = "emailAddress")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
-// @Inheritance(strategy = InheritanceType.JOINED)
-// @MappedSuperclass
-@ClassDescriptor(hidden = true)
-public class Person implements UserDetails, Cloneable, Serializable
-{
+//@Inheritance(strategy = InheritanceType.JOINED)
+//@MappedSuperclass
+@ViewRequiresAssociation
+@UpdateRequiresAssociation
+@ClassDescriptor(hasCyclicRelationships = true, hidden = true)
+public class Person implements UserDetails, Cloneable, Serializable {
private static final Log log = LogFactory.getLog(Person.class);
- public enum ERole
- {
- USER, ADMIN
- }
-
- public enum EApplicationRole
- {
- MANAGER, DIRECTOR, SALES, MARKETING
- }
-
protected Integer id = null;
-
protected String firstName;
-
protected String lastName;
-
protected Demographics demographics = new Demographics();
-
protected Date dob;
-
protected String emailAddress;
-
protected String password;
- protected ERole eRole;
-
- protected EApplicationRole eApplicationRole;
-
protected Set<Role> roles = new HashSet<Role>();
-
protected boolean accountNonExpired = true;
-
protected boolean accountNonLocked = true;
-
protected boolean credentialsNonExpired = true;
-
protected boolean enabled = true;
- protected Long created = new Long(GregorianCalendar.getInstance().getTimeInMillis());
+ protected Long created = new Long(GregorianCalendar.getInstance()
+ .getTimeInMillis());
- protected Long accessed = new Long(GregorianCalendar.getInstance().getTimeInMillis());
+ protected Long accessed = new Long(GregorianCalendar.getInstance()
+ .getTimeInMillis());
/**
* CTOR
*/
- public Person(Person dto)
- {
- try
- {
+ public Person(Person dto) {
+ try {
BeanUtils.copyProperties(this, dto);
setUsername(emailAddress);
- } catch (Exception e)
- {
+ } catch (Exception e) {
log.error(e.toString());
e.printStackTrace();
}
}
- public Person()
- {
+ public Person() {
}
/**
@@ -134,8 +109,7 @@
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@PropertyDescriptor(readOnly = true, summary = true, index = 0)
- public Integer getId()
- {
+ public Integer getId() {
return id;
}
@@ -144,80 +118,55 @@
@BlobDescriptor(renderType = RenderType.IMAGE, contentDisposition = ContentDisposition.ATTACHMENT)
@PropertyDescriptor(summary = true, index = 1)
@OneToOne(cascade = CascadeType.ALL)
- public UploadableMedia getPhoto()
- {
+ public UploadableMedia getPhoto() {
return photo;
}
- @Enumerated(value = EnumType.STRING)
- @NotNull(message = "is required")
- @PropertyDescriptor(summary = true, index = 2)
- public ERole getERole()
- {
- return eRole;
- }
-
- @Enumerated(value = EnumType.STRING)
- @PropertyDescriptor(summary = true, index = 9)
- public EApplicationRole getEApplicationRole()
- {
- return eApplicationRole;
- }
-
@PropertyDescriptor(summary = true, index = 3)
- public String getFirstName()
- {
+ public String getFirstName() {
return firstName;
}
@PropertyDescriptor(summary = true, index = 4)
- public String getLastName()
- {
+ public String getLastName() {
return lastName;
}
@PropertyDescriptor(summary = true, index = 5)
- public Date getDob()
- {
+ public Date getDob() {
return dob;
}
@Embedded
- public Demographics getDemographics()
- {
+ public Demographics getDemographics() {
return demographics;
}
@Column(unique = true)
@PrimaryKeyJoinColumn
@PropertyDescriptor(summary = true, index = 7)
- public String getEmailAddress()
- {
+ public String getEmailAddress() {
return emailAddress;
}
@PropertyDescriptor(summary = true, index = 8)
- public String getPassword()
- {
+ public String getPassword() {
return password;
}
@PropertyDescriptor(hidden = true, summary = false, searchable = false)
- public Long getCreated()
- {
+ public Long getCreated() {
return created;
}
@PropertyDescriptor(hidden = true, summary = false, searchable = false)
- public Long getAccessed()
- {
+ public Long getAccessed() {
return accessed;
}
@Transient
@PropertyDescriptor(hidden = true, summary = false, searchable = false)
- public String getCreatedAsString()
- {
+ public String getCreatedAsString() {
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(created.longValue());
return DatePattern.sdf.format(cal.getTime());
@@ -225,202 +174,174 @@
@Transient
@PropertyDescriptor(hidden = true, summary = false, searchable = false)
- public String getAccessedAsString()
- {
+ public String getAccessedAsString() {
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(accessed.longValue());
return DatePattern.sdf.format(cal.getTime());
}
- public void setId(Integer id)
- {
+ public void setId(Integer id) {
this.id = id;
}
- public void setPhoto(UploadableMedia photo)
- {
+ public void setPhoto(UploadableMedia photo) {
this.photo = photo;
}
- public void setERole(ERole role)
- {
- this.eRole = role;
- }
-
- public void setEApplicationRole(EApplicationRole applicationRole)
- {
- eApplicationRole = applicationRole;
- }
-
- public void setFirstName(String firstName)
- {
+ public void setFirstName(String firstName) {
this.firstName = firstName;
}
- public void setLastName(String lastName)
- {
+ public void setLastName(String lastName) {
this.lastName = lastName;
}
- public void setDob(Date dob)
- {
+ public void setDob(Date dob) {
this.dob = dob;
}
- public void setDemographics(Demographics demographics)
- {
+ public void setDemographics(Demographics demographics) {
this.demographics = demographics;
}
- public void setEmailAddress(String emailAddress)
- {
+ public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
setUsername(emailAddress);
}
- public void setPassword(String password)
- {
+ public void setPassword(String password) {
this.password = password;
}
- public void setCreated(Long created)
- {
+ public void setCreated(Long created) {
this.created = created;
}
@Transient
@PropertyDescriptor(hidden = true, summary = false, searchable = false)
- public void setCreatedAsString(String value) throws Exception
- {
+ public void setCreatedAsString(String value) throws Exception {
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(DatePattern.sdf.parse(value).getTime());
this.created = new Long(cal.getTimeInMillis());
}
- public void setAccessed(Long accessed)
- {
+ public void setAccessed(Long accessed) {
this.accessed = accessed;
}
@Transient
@PropertyDescriptor(hidden = true, summary = false, searchable = false)
- public void setAccessedAsString(String value) throws Exception
- {
+ public void setAccessedAsString(String value) throws Exception {
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(DatePattern.sdf.parse(value).getTime());
this.accessed = new Long(cal.getTimeInMillis());
}
@Override
- public Person clone()
- {
+ public Person clone() {
return new Person(this);
}
@Override
- public String toString()
- {
- return getFirstName() + " " + getLastName() + " [" + getUsername() + "]";
+ public String toString() {
+ return getFirstName() + " " + getLastName() + " [" + getUsername()
+ + "]";
}
@Override
public int hashCode()
{
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode());
- return result;
+ return (getId() != null ? getId().hashCode() : 0);
}
-
+
+ /**
+ * equals and hashCode need to be hammered out for hibernate to work properly
+ *
+ * Check the matrix summary for best practices
+ * at
http://www.hibernate.org/109.html+ *
+ * Our Person object implements a composite key (ID + emailAddress) whereby
+ * both are required to be unique for any Person.
+ *
+ * The ID is not a reliable comparison since hibernate suspends state til saved.
+ */
@Override
- public boolean equals(Object rhs)
- {
- if (this == rhs)
- return true;
- if (rhs == null)
- return false;
- if (!(rhs instanceof Person))
- return false;
+ public boolean equals(Object rhs) {
+ if (this == rhs) return true; // instance equality
+ if (rhs == null || getClass() != rhs.getClass()) return false; // null/class equality
+
final Person castedObject = (Person) rhs;
- if (getId() == null)
- {
- if (castedObject.getId() != null)
- return false;
- } else if (!getId().equals(castedObject.getId()))
- return false;
- return true;
+
+ return !(getId() != null ? !getId().equals(castedObject.getId()) : castedObject.getId() != null);
}
- public boolean isAccountNonExpired()
- {
+ public boolean isAccountNonExpired() {
return accountNonExpired;
}
- public void setAccountNonExpired(boolean accountNonExpired)
- {
+ public void setAccountNonExpired(boolean accountNonExpired) {
this.accountNonExpired = accountNonExpired;
}
- public boolean isAccountNonLocked()
- {
+ public boolean isAccountNonLocked() {
return accountNonLocked;
}
- public void setAccountNonLocked(boolean accountNonLocked)
- {
+ public void setAccountNonLocked(boolean accountNonLocked) {
this.accountNonLocked = accountNonLocked;
}
- public boolean isCredentialsNonExpired()
- {
+ public boolean isCredentialsNonExpired() {
return credentialsNonExpired;
}
- public void setCredentialsNonExpired(boolean credentialsNonExpired)
- {
+ public void setCredentialsNonExpired(boolean credentialsNonExpired) {
this.credentialsNonExpired = credentialsNonExpired;
}
- public boolean isEnabled()
- {
+ public boolean isEnabled() {
return enabled;
}
- public void setEnabled(boolean enabled)
- {
+ public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
@Transient
@PropertyDescriptor(hidden = true)
- public GrantedAuthority[] getAuthorities()
- {
+ public GrantedAuthority[] getAuthorities() {
log.debug("Person " + getUsername() + " has roles " + roles);
if (roles == null || roles.size() == 0)
- throw new UsernameNotFoundException("Person has no GrantedAuthority");
+ throw new UsernameNotFoundException(
+ "Person has no GrantedAuthority");
return roles.toArray(new GrantedAuthority[roles.size()]);
}
- @ManyToMany(fetch = FetchType.EAGER)
- @JoinTable(name = "join_table_person_role", joinColumns = { @JoinColumn(name = "person_fk") }, inverseJoinColumns = { @JoinColumn(name = "role_fk") })
- public Set<Role> getRoles()
- {
+ @ManyToMany(cascade=CascadeType.REFRESH, fetch = FetchType.EAGER)
+ @JoinTable(
+ name = "join_table_person_role",
+ joinColumns = { @JoinColumn(name = "person_table_primary_key") },
+ inverseJoinColumns = { @JoinColumn(name = "role_table_primary_key")}
+ )
+
+ //@ForeignKey(name = "person_fk", inverseName = "role_id")
+ //@Column(unique=true)
+ //@UpdateRequiresRole({"ROLE_ADMIN"})
+ //@RemoveRequiresRole( { "ROLE_ADMIN" })
+ public Set<Role> getRoles() {
return roles;
}
- public void setRoles(Set<Role> roles)
- {
+ public void setRoles(Set<Role> roles) {
this.roles = roles;
}
@PropertyDescriptor(hidden = true)
- public String getUsername()
- {
+ public String getUsername() {
return emailAddress;
}
- public void setUsername(String username)
- {
+ public void setUsername(String username) {
this.emailAddress = username;
}
}
\ No newline at end of file
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/TeamYear.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/TeamYear.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/TeamYear.java (working copy)
@@ -4,6 +4,7 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
+import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@@ -19,7 +20,7 @@
import org.trails.descriptor.annotation.PropertyDescriptor;
import org.trails.security.annotation.RemoveRequiresRole;
import org.trails.security.annotation.UpdateRequiresRole;
-import org.trails.demo.DatePattern;
+import org.trails.validation.ValidateUniqueness;
/**
*
@@ -28,6 +29,7 @@
@Entity
@RemoveRequiresRole({"ROLE_ADMIN"})
@UpdateRequiresRole({"ROLE_ADMIN"})
+@ValidateUniqueness(property = "yearStart")
@ClassDescriptor(hasCyclicRelationships = true, hidden = false)
public class TeamYear implements Cloneable, Serializable
{
@@ -87,12 +89,14 @@
return league;
}
+ @Column(unique = true)
@PropertyDescriptor(index = 1)
public Integer getYearStart()
{
return yearStart;
}
+ @Column(unique = true)
@PropertyDescriptor(index = 2)
public Integer getYearEnd()
{
@@ -176,37 +180,26 @@
{
this.created = created;
}
-
+
@Override
- public int hashCode()
+ public String toString()
{
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode());
- return result;
+ return this.getYearStart() + "/" + this.getYearEnd();
}
@Override
- public boolean equals(Object rhs)
+ public int hashCode()
{
- if (this == rhs)
- return true;
- if (rhs == null)
- return false;
- if (!(rhs instanceof TeamYear))
- return false;
+ return (getId() != null ? getId().hashCode() : 0);
+ }
+
+ @Override
+ public boolean equals(Object rhs) {
+ if (this == rhs) return true; // instance equality
+ if (rhs == null || getClass() != rhs.getClass()) return false; // null/class equality
+
final TeamYear castedObject = (TeamYear) rhs;
- if (getId() == null)
- {
- if (castedObject.getId() != null)
- return false;
- } else if (!getId().equals(castedObject.getId()))
- return false;
- return true;
+
+ return !(getId() != null ? !getId().equals(castedObject.getId()) : castedObject.getId() != null);
}
-
- public String toString()
- {
- return getYearStart().toString() + "/" + getYearEnd().toString();
- }
}
\ No newline at end of file
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/UploadableMedia.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/UploadableMedia.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/UploadableMedia.java (working copy)
@@ -3,6 +3,7 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
+import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
@@ -15,12 +16,11 @@
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.trails.descriptor.annotation.BlobDescriptor;
+import org.trails.descriptor.annotation.PropertyDescriptor;
import org.trails.descriptor.extension.ITrailsBlob;
import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition;
import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType;
-import org.trails.descriptor.annotation.BlobDescriptor;
-import org.trails.descriptor.annotation.PropertyDescriptor;
-import org.trails.demo.DatePattern;
/**
*
@@ -168,6 +168,7 @@
@BlobDescriptor(renderType = RenderType.IMAGE, contentDisposition = ContentDisposition.ATTACHMENT)
@PropertyDescriptor(summary = true)
@Lob
+ @Column(columnDefinition = "longblob", length = 6291456)
// uncomment for mysql - @Column(columnDefinition = "longblob", length = 6291456)
public byte[] getBytes()
{
@@ -284,7 +285,10 @@
public void reset()
{
-
+ fileName = null;
+ filePath = null;
+ contentType = null;
+ bytes = null;
}
public String toString()
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Director.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Director.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Director.java (working copy)
@@ -52,8 +52,6 @@
public Director()
{
- setERole(ERole.USER);
- setEApplicationRole(EApplicationRole.DIRECTOR);
}
@OneToOne(mappedBy = "director")
@@ -77,30 +75,13 @@
}
@Override
- public int hashCode()
- {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode());
- return result;
+ public int hashCode() {
+ return super.hashCode();
}
@Override
- public boolean equals(Object rhs)
- {
- if (this == rhs)
- return true;
- if (rhs == null)
- return false;
- if (!(rhs instanceof Director))
- return false;
- final Director castedObject = (Director) rhs;
- if (getId() == null)
- {
- if (castedObject.getId() != null)
- return false;
- } else if (!getId().equals(castedObject.getId()))
- return false;
- return true;
+ public boolean equals(Object rhs) {
+
+ return super.equals(rhs);
}
}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Officer.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Officer.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Officer.java (working copy)
@@ -1,8 +1,7 @@
package org.trails.demo;
+import javax.persistence.CascadeType;
import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@@ -11,10 +10,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.trails.descriptor.annotation.ClassDescriptor;
-import org.trails.descriptor.annotation.PropertyDescriptor;
-import org.trails.security.RestrictionType;
-import org.trails.security.annotation.UpdateRequiresRole;
import org.trails.security.annotation.RemoveRequiresRole;
+import org.trails.security.annotation.UpdateRequiresAssociation;
+import org.trails.security.annotation.UpdateRequiresRole;
+import org.trails.security.annotation.ViewRequiresAssociation;
import org.trails.security.annotation.ViewRequiresRole;
/**
@@ -23,100 +22,57 @@
* @author kenneth.colassi
nhhockeyplayer@...
*/
@Entity
-@RemoveRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER"})
-@UpdateRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER"})
-@ViewRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER", "ROLE_USER"})
+@RemoveRequiresRole( { "ROLE_ADMIN", "ROLE_MANAGER" })
+@UpdateRequiresRole( { "ROLE_ADMIN", "ROLE_MANAGER" })
+@ViewRequiresRole( { "ROLE_ADMIN", "ROLE_MANAGER", "ROLE_USER" })
+@ViewRequiresAssociation
+@UpdateRequiresAssociation
@ClassDescriptor(hasCyclicRelationships = true, hidden = true)
-public class Officer extends Person
-{
+public class Officer extends Person {
private static final Log log = LogFactory.getLog(Officer.class);
- protected enum EOfficerRole
- {
- COMMISSIONER, SECRETARY, TREASURER, OFFICIALS, MEDIA, MARKETING
- }
-
- private EOfficerRole eOfficerRole;
-
private League league = null;
/**
* CTOR
*/
- public Officer(Officer dto)
- {
+ public Officer(Officer dto) {
super(dto);
- try
- {
+ try {
BeanUtils.copyProperties(this, dto);
- } catch (Exception e)
- {
+ } catch (Exception e) {
log.error(e.toString());
e.printStackTrace();
}
}
- public Officer()
- {
- setERole(ERole.USER);
+ public Officer() {
}
- @Enumerated(value = EnumType.STRING)
- @PropertyDescriptor(summary = true)
- public EOfficerRole getEOfficerRole()
- {
- return eOfficerRole;
- }
-
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne
@JoinColumn(name = "officer_league_fk", insertable = false, updatable = true, nullable = true)
- public League getLeague()
- {
+ public League getLeague() {
return league;
}
- public void setEOfficerRole(EOfficerRole role)
- {
- this.eOfficerRole = role;
- }
-
- public void setLeague(League league)
- {
+ public void setLeague(League league) {
this.league = league;
}
@Override
- public Officer clone()
- {
+ public Officer clone() {
return new Officer(this);
}
@Override
- public int hashCode()
- {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode());
- return result;
+ public int hashCode() {
+ return super.hashCode();
}
@Override
- public boolean equals(Object rhs)
- {
- if (this == rhs)
- return true;
- if (rhs == null)
- return false;
- if (!(rhs instanceof Officer))
- return false;
- final Officer castedObject = (Officer) rhs;
- if (getId() == null)
- {
- if (castedObject.getId() != null)
- return false;
- } else if (!getId().equals(castedObject.getId()))
- return false;
- return true;
+ public boolean equals(Object rhs) {
+
+ return super.equals(rhs);
}
}
\ No newline at end of file
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Coach.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Coach.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Coach.java (working copy)
@@ -1,8 +1,10 @@
package org.trails.demo;
+import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@@ -12,7 +14,9 @@
import org.trails.descriptor.annotation.ClassDescriptor;
import org.trails.descriptor.annotation.PropertyDescriptor;
import org.trails.security.annotation.RemoveRequiresRole;
+import org.trails.security.annotation.UpdateRequiresAssociation;
import org.trails.security.annotation.UpdateRequiresRole;
+import org.trails.security.annotation.ViewRequiresAssociation;
import org.trails.security.annotation.ViewRequiresRole;
/**
@@ -24,7 +28,9 @@
@RemoveRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER"})
@UpdateRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER"})
@ViewRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER", "ROLE_USER"})
-@ClassDescriptor(hasCyclicRelationships = true, hidden = true)
+@ViewRequiresAssociation
+@UpdateRequiresAssociation
+@ClassDescriptor(hasCyclicRelationships = true)
public class Coach extends Person
{
private static final Log log = LogFactory.getLog(Coach.class);
@@ -59,7 +65,6 @@
public Coach()
{
- setERole(ERole.USER);
}
@Enumerated(value = EnumType.STRING)
@@ -70,7 +75,7 @@
}
@ManyToOne
- @JoinColumn(name = "team_id")
+ @JoinColumn(name = "coach_team_fk")
@PropertyDescriptor(searchable = true, index = 1)
public Team getTeam()
{
@@ -105,31 +110,31 @@
return new Coach(this);
}
+/*
@Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object rhs) {
+
+ return super.equals(rhs);
+ }
+ */
+
+ @Override
public int hashCode()
{
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode());
- return result;
+ return (getId() != null ? getId().hashCode() : 0);
}
-
@Override
- public boolean equals(Object rhs)
- {
- if (this == rhs)
- return true;
- if (rhs == null)
- return false;
- if (!(rhs instanceof Coach))
- return false;
+ public boolean equals(Object rhs) {
+ if (this == rhs) return true; // instance equality
+ if (rhs == null || getClass() != rhs.getClass()) return false; // null/class equality
+
final Coach castedObject = (Coach) rhs;
- if (getId() == null)
- {
- if (castedObject.getId() != null)
- return false;
- } else if (!getId().equals(castedObject.getId()))
- return false;
- return true;
- }
+
+ return !(getId() != null ? !getId().equals(castedObject.getId()) : castedObject.getId() != null);
+ }
}
\ No newline at end of file
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/User.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/User.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/User.java (working copy)
@@ -8,20 +8,8 @@
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
+import javax.persistence.*;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
-import javax.persistence.Table;
-import javax.persistence.Transient;
-import javax.persistence.Version;
-
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UsernameNotFoundException;
@@ -34,14 +22,15 @@
import org.trails.security.annotation.UpdateRequiresRole;
import org.trails.security.annotation.ViewRequiresAssociation;
import org.trails.security.annotation.ViewRequiresRole;
-import org.trails.security.password.DigestUtil;
import org.trails.validation.ValidateUniqueness;
+import org.trails.security.password.DigestUtil;
+
@Entity
@Table(name = "TRAILS_USER")
@ValidateUniqueness(property = "username")
@ClassDescriptor(hasCyclicRelationships = true)
-@ViewRequiresRole( { "ROLE_MANAGER", "ROLE_ROOT" })
+@ViewRequiresRole({"ROLE_MANAGER", "ROLE_ROOT"} )
@ViewRequiresAssociation
@UpdateRequiresAssociation
public class User implements UserDetails, Serializable
@@ -49,27 +38,16 @@
private static final Log log = LogFactory.getLog(User.class);
private Integer id;
-
private String username;
-
private String encodedPassword;
-
private String confirmPassword;
-
private String firstName;
-
private String lastName;
-
private Integer version;
-
private Set<Role> roles = new HashSet<Role>();
-
private boolean enabled = true;
-
private boolean accountNonExpired = true;
-
private boolean accountNonLocked = true;
-
private boolean credentialsNonExpired = true;
@Id
@@ -96,30 +74,24 @@
@Transient
@NotNull
@PropertyDescriptor(index = 2, summary = false)
- public String getPassword()
- {
+ public String getPassword() {
return encodedPassword;
}
- public void setPassword(String password)
- {
- if (password != null && !password.equals(encodedPassword))
- encodedPassword = DigestUtil.encode(password);
+ public void setPassword(String password) {
+ if (password!= null && !password.equals(encodedPassword)) encodedPassword= DigestUtil.encode(password);
}
-
+
@Column(name = "password", nullable = false)
- @PropertyDescriptor(hidden = true)
- public String getEncodedPassword()
- {
+ @PropertyDescriptor(hidden=true)
+ public String getEncodedPassword() {
return encodedPassword;
}
-
- public void setEncodedPassword(String encodedPassword)
- {
+ public void setEncodedPassword(String encodedPassword) {
this.encodedPassword = encodedPassword;
}
- // @Transient
+ //@Transient
@NotNull
// for validation purposes
@PropertyDescriptor(index = 3, summary = false)
@@ -128,6 +100,7 @@
return confirmPassword;
}
+
@Column(name = "first_name", length = 50, nullable = false)
@NotNull
@PropertyDescriptor(index = 4)
@@ -145,8 +118,11 @@
}
@ManyToMany(fetch = FetchType.EAGER)
- @JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "user_ID") }, inverseJoinColumns = { @JoinColumn(name = "role_ID") })
- @UpdateRequiresRole( { "ROLE_MANAGER" })
+ @JoinTable(
+ name = "user_role",
+ joinColumns = {@JoinColumn(name = "user_ID")},
+ inverseJoinColumns = {@JoinColumn(name = "role_ID")})
+ @UpdateRequiresRole({"ROLE_MANAGER"} )
public Set<Role> getRoles()
{
return roles;
@@ -189,17 +165,15 @@
this.version = version;
}
+
public boolean equals(Object o)
{
- if (this == o)
- return true;
- if (!(o instanceof User))
- return false;
+ if (this == o) return true;
+ if (!(o instanceof User)) return false;
final User user = (User) o;
- if (username != null ? !username.equals(user.getUsername()) : user.getUsername() != null)
- return false;
+ if (username != null ? !username.equals(user.getUsername()) : user.getUsername() != null) return false;
return true;
}
@@ -239,8 +213,7 @@
public GrantedAuthority[] getAuthorities()
{
log.debug("User " + getUsername() + " has roles " + roles);
- if (roles == null || roles.size() == 0)
- throw new UsernameNotFoundException("User has no GrantedAuthority");
+ if (roles == null || roles.size() == 0) throw new UsernameNotFoundException("User has no GrantedAuthority");
return roles.toArray(new GrantedAuthority[roles.size()]);
}
@@ -264,4 +237,5 @@
this.enabled = enabled;
}
+
}
\ No newline at end of file
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Team.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Team.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Team.java (working copy)
@@ -4,12 +4,14 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@@ -24,15 +26,14 @@
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition;
-import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType;
import org.trails.descriptor.annotation.BlobDescriptor;
import org.trails.descriptor.annotation.ClassDescriptor;
import org.trails.descriptor.annotation.Collection;
import org.trails.descriptor.annotation.PropertyDescriptor;
+import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition;
+import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType;
import org.trails.security.annotation.RemoveRequiresRole;
import org.trails.security.annotation.UpdateRequiresRole;
-import org.trails.demo.DatePattern;
/**
* A Team has players, coaches, clips and stats
@@ -151,8 +152,8 @@
return organization;
}
- @OneToMany
- @JoinColumn(name = "team_id")
+ @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
+ @JoinColumn(name = "coaches_team_fk")
@Collection(child = false, inverse = "team")
@PropertyDescriptor(readOnly = false, searchable = true)
//@OrderBy("lastName")
@@ -161,6 +162,16 @@
return coaches;
}
+ @OneToMany(cascade = CascadeType.ALL)
+ @JoinColumn(name = "clips_team_fk")
+ @Collection(child = true, inverse = "team")
+ @PropertyDescriptor(readOnly = false, searchable = false)
+ @OrderBy("name")
+ public Set<UploadableMedia> getClips()
+ {
+ return clips;
+ }
+
@Enumerated(value = EnumType.STRING)
@PropertyDescriptor(summary = true)
public EGender getGender()
@@ -204,16 +215,6 @@
}
@OneToMany(cascade = CascadeType.ALL)
- @JoinColumn(name = "clips_team_fk", insertable = true, updatable = true, nullable = true)
- @Collection(child = true, inverse = "team")
- @PropertyDescriptor(searchable = false, readOnly = false)
- @OrderBy("name")
- public Set<UploadableMedia> getClips()
- {
- return clips;
- }
-
- @OneToMany
@JoinColumn(name = "player_team_fk")
@Collection(child = false, inverse = "team")
@PropertyDescriptor(readOnly = false, searchable = true)
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/PlayerStat.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/PlayerStat.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/PlayerStat.java (working copy)
@@ -4,7 +4,9 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
+import javax.persistence.CascadeType;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Player.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Player.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Player.java (working copy)
@@ -7,6 +7,7 @@
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
@@ -183,30 +184,13 @@
}
@Override
- public int hashCode()
- {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode());
- return result;
+ public int hashCode() {
+ return super.hashCode();
}
@Override
- public boolean equals(Object rhs)
- {
- if (this == rhs)
- return true;
- if (rhs == null)
- return false;
- if (!(rhs instanceof Player))
- return false;
- final Player castedObject = (Player) rhs;
- if (getId() == null)
- {
- if (castedObject.getId() != null)
- return false;
- } else if (!getId().equals(castedObject.getId()))
- return false;
- return true;
+ public boolean equals(Object rhs) {
+
+ return super.equals(rhs);
}
}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/applicationContext.xml
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/applicationContext.xml (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/applicationContext.xml (working copy)
@@ -29,7 +29,6 @@
<property name="localeHolder" ref="localeHolder"/>
</bean>
-
<!-- ========================= RESOURCE DEFINITIONS ========================= -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
@@ -419,6 +418,62 @@
</property>
</bean>
+ <bean id="viewerService" class="org.trails.finder.EditorBlockFinder">
+ <property name="defaultBlockAddress">
+ <bean class="org.apache.tapestry.util.ComponentAddress">
+ <constructor-arg index="0">
+ <value>trails:Viewers</value>
+ </constructor-arg>
+ <constructor-arg index="1">
+ <value>stringViewer</value>
+ </constructor-arg>
+ </bean>
+ </property>
+ <property name="editorMap">
+ <map>
+ <entry>
+ <key>
+ <value>hidden</value>
+ </key>
+ <bean class="org.apache.tapestry.util.ComponentAddress">
+ <constructor-arg index="0">
+ <value>trails:Viewers</value>
+ </constructor-arg>
+ <constructor-arg index="1">
+ <value>hidden</value>
+ </constructor-arg>
+ </bean>
+ </entry>
+ <entry>
+ <key>
+ <value>richText</value>
+ </key>
+ <bean class="org.apache.tapestry.util.ComponentAddress">
+ <constructor-arg index="0">
+ <value>trails:Viewers</value>
+ </constructor-arg>
+ <constructor-arg index="1">
+ <value>htmlTextViewer</value>
+ </constructor-arg>
+ </bean>
+ </entry>
+ <entry>
+ <key>
+ <value>supportsExtension('org.trails.descriptor.extension.BlobDescriptorExtension')</value>
+ </key>
+ <bean class="org.apache.tapestry.util.ComponentAddress">
+ <constructor-arg index="0">
+ <value>trails:Viewers</value>
+ </constructor-arg>
+ <constructor-arg index="1">
+ <value>blobViewer</value>
+ </constructor-arg>
+ </bean>
+ </entry>
+ </map>
+ </property>
+ </bean>
+
<bean id="hibernateValidationAspect" class="org.trails.validation.HibernateValidationAspect" factory-method="aspectOf">
<property name="hibernateClassValidatorFactory" ref="hibernateClassValidatorFactory"/>
</bean>
@@ -429,5 +484,4 @@
</bean>
<bean id="localeHolder" class="org.trails.i18n.SpringLocaleHolder"/>
-
</beans>
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/hibernate.properties
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/hibernate.properties (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/hibernate.properties (working copy)
@@ -1,11 +1,9 @@
-hibernate.dialect=org.hibernate.dialect.HSQLDialect
-# hibernate.show_sql=true
+hibernate.dialect=org.hibernate.dialect.MySQLDialect
+hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
-
-hibernate.connection.driver_class=org.hsqldb.jdbcDriver
-hibernate.connection.url=jdbc:hsqldb:mem:test
-hibernate.connection.username=sa
-hibernate.connection.password=
-
-hibernate.max_fetch_depth=9
+hibernate.max_fetch_depth=0
+hibernate.connection.driver_class=com.mysql.jdbc.Driver
+hibernate.connection.url=jdbc:mysql://localhost:3306/roster?jdbcCompliantTruncation=false
+hibernate.connection.username=root
+hibernate.connection.password=admin
hibernate.jdbc.batch_versioned_data=true
\ No newline at end of file
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultList.html
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultList.html (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultList.html (working copy)
@@ -21,6 +21,6 @@
criteria="ognl:criteria"
object="ognl:object"
column="ognl:column"
- />
+ />
</span>
\ No newline at end of file
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultSearch.page
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultSearch.page (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultSearch.page (working copy)
@@ -2,8 +2,8 @@
"
http://jakarta.apache.org/tapestry/dtd/Tapestry_4_1.dtd">
<page-specification class="org.trails.page.SearchPage">
- <property name="model" persist="session"/>
- <property name="classDescriptor" persist="session"/>
+ <property name="model" persist="trails-form"/>
+ <property name="classDescriptor" persist="trails-form"/>
<property name="nextPage"/>
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultList.page
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultList.page (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultList.page (working copy)
@@ -1,10 +1,10 @@
-<!DOCTYPE page-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.1//EN"
- "
http://jakarta.apache.org/tapestry/dtd/Tapestry_4_1.dtd">
+<!DOCTYPE page-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.1//EN" "
http://jakarta.apache.org/tapestry/dtd/Tapestry_4_1.dtd">
<page-specification class="org.trails.page.HibernateListPage">
- <property name="instances" persist="session"/>
- <property name="criteria" persist="session"/>
- <property name="classDescriptor" persist="session"/>
+<!-- <property name="type" persist="session"/> -->
+ <property name="instances" persist="trails-default"/>
+ <property name="criteria" persist="trails-default"/>
+ <property name="classDescriptor" persist="trails-default"/>
<property name="object"/>
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.html
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.html (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.html (working copy)
@@ -19,7 +19,6 @@
</span>
</div>
- <form jwcid="@trails:ObjectForm" model="ognl:model">
+ <form jwcid="@trails:ObjectForm" model="ognl:model"/>
- </form>
</span>
\ No newline at end of file
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/hivemodule.xml
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/hivemodule.xml (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/hivemodule.xml (working copy)
@@ -57,7 +57,9 @@
<contribution configuration-id="tapestry.persist.PersistenceStrategy">
<strategy name="trails-entity" object="service:trails.hibernate.ReattachReattachPropertyPersistenceStrategy"/>
- </contribution>
+ <strategy name="trails-default" object="service:tapestry.persist.SessionPropertyPersistenceStrategy"/>
+ <strategy name="trails-form" object="service:tapestry.persist.SessionPropertyPersistenceStrategy"/>
+ </contribution>
<contribution configuration-id="tapestry.state.ApplicationObjects">
<state-object name="callbackStack" scope="session">
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.page
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.page (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.page (working copy)
@@ -1,5 +1,4 @@
-<!DOCTYPE page-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.1//EN"
- "
http://jakarta.apache.org/tapestry/dtd/Tapestry_4_1.dtd">
+<!DOCTYPE page-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.1//EN" "
http://jakarta.apache.org/tapestry/dtd/Tapestry_4_1.dtd">
<page-specification class="org.trails.page.HibernateEditPage">
<property name="model" persist="session"/>
@@ -18,5 +17,4 @@
</bean>
<inject property="callbackStack" type="state" object="callbackStack"/>
-
-</page-specification>
+</page-specification>
\ No newline at end of file
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/web.xml
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/web.xml (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/web.xml (working copy)
@@ -13,8 +13,12 @@
classpath:acegi-security.xml
classpath:applicationContext-seedData.xml
</param-value>
- </context-param>
-
+ </context-param>
+
+ <listener>
+ <listener-class>org.acegisecurity.ui.session.HttpSessionEventPublisher</listener-class>
+ </listener>
+
<!-- Added for Acegi support. -->
<filter>
<filter-name>Acegi Filter Chain Proxy</filter-name>
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/persistence/PersistenceService.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/persistence/PersistenceService.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/persistence/PersistenceService.java (working copy)
@@ -51,4 +51,8 @@
Serializable getIdentifier(Object data, IClassDescriptor classDescriptor);
boolean isTransient(Object data, IClassDescriptor classDescriptor);
+
+ public void reattachCollection(Object[] models);
+
+ public void mergeCollection(Object[] models);
}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/link/TrailsLink.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/link/TrailsLink.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/link/TrailsLink.java (working copy)
@@ -9,8 +9,8 @@
import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.link.AbstractLinkComponent;
import org.apache.tapestry.link.ILinkRenderer;
-import org.trails.descriptor.CollectionDescriptor;
import org.trails.descriptor.IClassDescriptor;
+import org.trails.descriptor.TrailsPropertyDescriptor;
import org.trails.engine.TrailsPagesServiceParameter;
import org.trails.page.PageType;
@@ -42,7 +42,8 @@
public abstract Object getModel();
@Parameter
- public abstract CollectionDescriptor getAssociationDescriptor();
+ //kwc public abstract CollectionDescriptor getAssociationDescriptor();
+ public abstract TrailsPropertyDescriptor getAssociationDescriptor();
@Parameter
public abstract Object getParent();
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/component/EditCollection.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/component/EditCollection.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/component/EditCollection.java (working copy)
@@ -11,13 +11,22 @@
*/
package org.trails.component;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
import ognl.Ognl;
import ognl.OgnlException;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.IAsset;
import org.apache.tapestry.IRequestCycle;
-import org.apache.tapestry.annotations.*;
+import org.apache.tapestry.annotations.Asset;
+import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.annotations.InjectObject;
+import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.contrib.palette.SortMode;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.link.ILinkRenderer;
@@ -28,12 +37,7 @@
import org.trails.persistence.PersistenceService;
import org.trails.util.Utils;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
/**
* This component produces a editor for a ManyToOne or ManyToMany collection. It allows a user to edit a collection
* property
@@ -116,12 +120,14 @@
super.prepareForRender(cycle);
selected = buildSelectedList();
}
-
+
public List<Boolean> buildSelectedList()
{
ArrayList<Boolean> selected = new ArrayList<Boolean>();
if (getCollection() != null)
{
+ getPersistenceService().mergeCollection(getCollection().toArray());
+
selected = new ArrayList<Boolean>(getCollection().size());
for (Object o : getCollection())
{
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/component/AssociationMgt.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/component/AssociationMgt.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/component/AssociationMgt.java (working copy)
@@ -1,72 +1,79 @@
package org.trails.component;
+import ognl.Ognl;
+import ognl.OgnlException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.annotations.InjectObject;
+import org.apache.tapestry.annotations.Parameter;
+import org.apache.tapestry.link.ILinkRenderer;
+import org.trails.descriptor.DescriptorService;
+import org.trails.descriptor.IClassDescriptor;
+import org.trails.descriptor.ObjectReferenceDescriptor;
+import org.trails.descriptor.extension.OwningObjectReferenceDescriptor;
+import org.trails.exception.TrailsRuntimeException;
+import org.trails.page.PageResolver;
+import org.trails.persistence.PersistenceService;
/**
- * @author kenneth.colassi
nhhockeyplayer@...
- * @OneToOne use case. <p/> This guy manages the owning side user interface of a
+ * @OneToOne use case. <p/>
+ *
+ * This guy manages the owning side user interface of a
* OneToOne association. <p/> Owner-<>-----Association
+ *
+ * @author kenneth.colassi
nhhockeyplayer@...
*/
-@ComponentClass(allowBody = true, allowInformalParameters = true)
+@ComponentClass(allowBody = false)
public abstract class AssociationMgt extends TrailsComponent
{
-/*
protected static final Log LOG = LogFactory.getLog(AssociationMgt.class);
+
+ @InjectObject("service:trails.core.PageResolver")
+ public abstract PageResolver getPageResolver();
- @Bean(lifecycle = Lifecycle.REQUEST)
- public abstract TrailsValidationDelegate getDelegate();
+ @Parameter(defaultValue = "page.descriptorService")
+ public abstract DescriptorService getDescriptorService();
- public abstract String getCreateExpression();
+ @Parameter(defaultValue = "page.persistenceService")
+ public abstract PersistenceService getPersistenceService();
- public abstract void setCreateExpression(String CreateExpression);
-
@Parameter(required = true, cache = true)
public abstract ObjectReferenceDescriptor getDescriptor();
-
public abstract void setDescriptor(ObjectReferenceDescriptor descriptor);
@Parameter(required = true, cache = true)
- public abstract Object getOwner();
-
- public abstract void setOwner(Object owner);
-
- @Parameter(required = true, cache = true)
public abstract Object getAssociation();
-
public abstract void setAssociation(Object association);
- @Parameter(required = true, cache = true)
- public abstract Object getValue();
+ /**
+ * The object which owns the instance being edited
+ */
+ @Parameter(required = false, defaultValue = "page.model")
+ public abstract Object getOwner();
+ public abstract void setOwner (Object owner);
+
+ /**
+ * Ognl expression to invoke on the model to create a new child instance
+ */
+ @Parameter(required = false)
+ public abstract String getCreateExpression();
- public abstract void setValue(Object value);
-
- @Parameter(required = true, cache = true)
- public abstract Object getModel();
-
- public abstract void setModel(Object bytes);
-
- @InjectState("callbackStack")
- public abstract CallbackStack getCallbackStack();
-
- public abstract void setCallbackStack(CallbackStack stack);
-
- @InjectObject("service:trails.core.PageResolver")
- public abstract PageResolver getPageResolver();
-
- @InjectObject("service:trails.core.PersistenceService")
- public abstract PersistenceService getPersistenceService();
-
- @InjectObject("service:trails.core.EditorService")
- public abstract BlockFinder getBlockFinder();
-
- @InjectObject("service:trails.core.DescriptorService")
- public abstract DescriptorService getDescriptorService();
-
public IClassDescriptor getClassDescriptor()
{
return getDescriptorService().getClassDescriptor(getDescriptor().getPropertyType());
}
+ /**
+ * org.apache.tapestry.contrib.link.ButtonLinkRenderer
+ *
+ * @return
+ */
+ @InjectObject(value = "service:trails.core.AddNewLinkRenderer")
+ public abstract ILinkRenderer getRenderer();
+
public AssociationMgt()
{
super();
@@ -92,39 +99,41 @@
return getDescriptor().getPropertyType().getClass();
}
- AssociationCallback buildCallback()
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.tapestry.AbstractComponent#prepareForRender(org.apache.tapestry.IRequestCycle)
+ */
+ protected void prepareForRender(IRequestCycle cycle)
{
- AssociationCallback callback = new AssociationCallback(getPage().getRequestCycle().getPage().getPageName(),
- getModel(), getDescriptor());
- return callback;
+ super.prepareForRender(cycle);
+ //if ( getAssociation()== null )
+ // addNew (cycle);
}
-
+
public void addNew(IRequestCycle cycle)
{
- getCallbackStack().push(buildCallback());
-
- String currentEditPageName = getPage().getRequestCycle().getPage().getPageName();
- EditPage ownerEditPage = (EditPage) getPageResolver().resolvePage(cycle, getDescriptor().getClass(),
- PageType.Edit);
-
- try
- {
+ try {
Object newModel = buildNewMemberInstance();
- EditCallback nextPage = new EditCallback(ownerEditPage.getPageName(), newModel);
-
- ((EditPage) cycle.getPage(currentEditPageName)).setNextPage(nextPage);
- nextPage.performCallback(cycle);
- } catch (Exception ex)
+ setAssociation(newModel);
+
+ //executeOgnlExpression(getDescriptor().findAddExpression(), newModel);
+ } catch (InstantiationException e)
{
- throw new TrailsRuntimeException(ex, getDescriptor().getClass().getClass());
+ throw new TrailsRuntimeException(e, getOwner().getClass());
+ } catch (IllegalAccessException e)
+ {
+ throw new TrailsRuntimeException(e, getOwner().getClass());
}
}
public void remove(IRequestCycle cycle)
{
- *//**
+ //this.executeOgnlExpression(getDescriptor().getRemoveExpression(), getAssociation());
+ /**
* This is a direct hit on the same page. No need to setup callbackstack.
- *//*
+ */
+ /*
EditPage editPage = (EditPage) getPageResolver().resolvePage(cycle, getDescriptor().getClass(), PageType.Edit);
AssociationCallback callback = buildCallback();
@@ -137,20 +146,21 @@
String currentEditPageName = getPage().getRequestCycle().getPage().getPageName();
((EditPage) cycle.getPage(currentEditPageName)).setNextPage(nextPage);
nextPage.performCallback(cycle);
- }
-
- public IPage edit(Object member)
+ */
+ }
+
+ private void executeOgnlExpression(String ognlExpression, Object newObject)
{
- AssociationCallback callback = new AssociationCallback(getPage().getRequestCycle().getPage().getPageName(),
- getModel(), getDescriptor());
- getCallbackStack().push(callback);
- EditPage editPage = (EditPage) getPageResolver().resolvePage(getPage().getRequestCycle(),
- Utils.checkForCGLIB(member.getClass()), PageType.Edit);
-
- editPage.setModel(member);
- return editPage;
- }
-
+ try
+ {
+ Ognl.setValue(ognlExpression, getOwner(), newObject);
+ Ognl.getValue(ognlExpression, getOwner());
+ } catch (OgnlException e)
+ {
+ throw new TrailsRuntimeException(e, getOwner().getClass());
+ }
+ }
+
protected Object buildNewMemberInstance() throws InstantiationException, IllegalAccessException
{
Object associationModel;
@@ -182,11 +192,34 @@
}
return associationModel;
+ }
+
+ /*
+ AssociationCallback buildCallback()
+ {
+ AssociationCallback callback = new AssociationCallback(getPage().getRequestCycle().getPage().getPageName(),
+ getModel(), getDescriptor());
+ return callback;
}
+ public IPage edit(Object member)
+ {
+ AssociationCallback callback = new AssociationCallback(getPage().getRequestCycle().getPage().getPageName(),
+ getModel(), getDescriptor());
+ getCallbackStack().push(callback);
+ EditPage editPage = (EditPage) getPageResolver().resolvePage(getPage().getRequestCycle(),
+ Utils.checkForCGLIB(member.getClass()), PageType.Edit);
+
+ editPage.setModel(member);
+ return editPage;
+ }
+
+
+
+ */
+
public OwningObjectReferenceDescriptor getOwningObjectReferenceDescriptor()
{
return getDescriptor().getExtension(OwningObjectReferenceDescriptor.class);
- }
- */
+ }
}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/engine/TrailsPagesService.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/engine/TrailsPagesService.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/engine/TrailsPagesService.java (working copy)
@@ -1,7 +1,9 @@
package org.trails.engine;
-import ognl.Ognl;
-import ognl.OgnlException;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.commons.lang.StringUtils;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.util.Defense;
@@ -17,16 +19,18 @@
import org.apache.tapestry.services.ResponseRenderer;
import org.trails.Trails;
import org.trails.builder.BuilderDirector;
+import org.trails.descriptor.IClassDescriptor;
+import org.trails.descriptor.IReferenceSupport;
+import org.trails.descriptor.TrailsPropertyDescriptor;
import org.trails.exception.TrailsRuntimeException;
-import org.trails.descriptor.CollectionDescriptor;
-import org.trails.descriptor.IClassDescriptor;
-import org.trails.page.*;
+import org.trails.page.EditPage;
+import org.trails.page.IActivatableTrailsPage;
+import org.trails.page.ModelPage;
+import org.trails.page.PageResolver;
+import org.trails.page.PageType;
import org.trails.services.ServiceConstants;
+import org.trails.util.Utils;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
public class TrailsPagesService implements IEngineService
{
@@ -97,8 +101,8 @@
IClassDescriptor classDescriptor =
(IClassDescriptor) dataSqueezer.unsqueeze(cycle.getParameter(ServiceConstants.CLASS_DESCRIPTOR));
Object model = unsqueezeIfNotNull(cycle, ServiceConstants.MODEL);
- CollectionDescriptor collectionDescriptor =
- (CollectionDescriptor) unsqueezeIfNotNull(cycle, ServiceConstants.ASSOC_DESCRIPTOR);
+ TrailsPropertyDescriptor collectionDescriptor =
+ (TrailsPropertyDescriptor) unsqueezeIfNotNull(cycle, ServiceConstants.ASSOC_DESCRIPTOR);
Object parent = unsqueezeIfNotNull(cycle, ServiceConstants.PAERNT_MODEL);
activateTrailsPage(cycle, pageType, classDescriptor, model, parent, collectionDescriptor);
@@ -106,7 +110,7 @@
responseRenderer.renderResponse(cycle);
}
- private void activateTrailsPage(IRequestCycle cycle, PageType pageType, IClassDescriptor classDescriptor, Object model, Object parent, CollectionDescriptor collectionDescriptor)
+ private void activateTrailsPage(IRequestCycle cycle, PageType pageType, IClassDescriptor classDescriptor, Object model, Object parent, TrailsPropertyDescriptor collectionDescriptor)
{
IPage rawPage = null;
@@ -154,10 +158,15 @@
if (PageType.NEW.equals(pageType))
{
((ModelPage) page).setModelNew(true);
- if ((collectionDescriptor != null) && (parent != null) &&
- (!StringUtils.isEmpty(collectionDescriptor.getInverseProperty())))
- {
- PropertyUtils.write(model, collectionDescriptor.getInverseProperty(), parent);
+ if ((collectionDescriptor != null) && (parent != null) ) {
+ if ( Utils.implementsInterface(collectionDescriptor.getClass(), IReferenceSupport.class) ) {
+
+ IReferenceSupport referenceDescriptor = (IReferenceSupport) collectionDescriptor;
+ if ( ! StringUtils.isEmpty(referenceDescriptor.getInverseProperty()) )
+ {
+ PropertyUtils.write(model, referenceDescriptor.getInverseProperty(), parent);
+ }
+ }
}
} else
{
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/engine/TrailsPagesServiceParameter.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/engine/TrailsPagesServiceParameter.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/engine/TrailsPagesServiceParameter.java (working copy)
@@ -5,6 +5,7 @@
import org.apache.hivemind.util.Defense;
import org.trails.descriptor.CollectionDescriptor;
import org.trails.descriptor.IClassDescriptor;
+import org.trails.descriptor.TrailsPropertyDescriptor;
import org.trails.page.PageType;
@@ -14,7 +15,7 @@
private PageType pageType;
private IClassDescriptor classDescriptor;
private Object model;
- private CollectionDescriptor associationDescriptor;
+ private TrailsPropertyDescriptor associationDescriptor;
private Object parent;
public TrailsPagesServiceParameter(PageType pageType, IClassDescriptor classDescriptor)
@@ -31,7 +32,7 @@
this.model = model;
}
- public TrailsPagesServiceParameter(PageType pageType, IClassDescriptor classDescriptor, Object model, CollectionDescriptor associationDescriptor, Object parent)
+ public TrailsPagesServiceParameter(PageType pageType, IClassDescriptor classDescriptor, Object model, TrailsPropertyDescriptor associationDescriptor, Object parent)
{
this(pageType, classDescriptor, model);
this.associationDescriptor = associationDescriptor;
@@ -53,7 +54,7 @@
return model;
}
- public CollectionDescriptor getAssociationDescriptor()
+ public TrailsPropertyDescriptor getAssociationDescriptor()
{
return associationDescriptor;
}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/page/IAssociationPage.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/page/IAssociationPage.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/page/IAssociationPage.java (working copy)
@@ -1,13 +1,13 @@
package org.trails.page;
-import org.trails.descriptor.CollectionDescriptor;
+import org.trails.descriptor.TrailsPropertyDescriptor;
public interface IAssociationPage extends IModelPage
{
- CollectionDescriptor getAssociationDescriptor();
+ TrailsPropertyDescriptor getAssociationDescriptor();
- void setAssociationDescriptor(CollectionDescriptor associationDescriptor);
+ void setAssociationDescriptor(TrailsPropertyDescriptor associationDescriptor);
Object getParent();
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/page/EditPage.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/page/EditPage.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/page/EditPage.java (working copy)
@@ -19,9 +19,10 @@
import org.apache.tapestry.callback.ICallback;
import org.apache.tapestry.engine.ILink;
import org.trails.callback.UrlCallback;
-import org.trails.util.Utils;
+import org.trails.descriptor.IReferenceSupport;
import org.trails.engine.TrailsPagesServiceParameter;
import org.trails.persistence.PersistenceException;
+import org.trails.util.Utils;
import org.trails.validation.TrailsValidationDelegate;
/**
@@ -121,7 +122,9 @@
{
if (cameFromCollection())
{
- Utils.executeOgnlExpression(getAssociationDescriptor().getAddExpression(), getModel(), getParent());
+ IReferenceSupport referenceDescriptor = (IReferenceSupport) getAssociationDescriptor();
+
+ Utils.executeOgnlExpression(referenceDescriptor.getAddExpression(), getModel(), getParent());
getPersistenceService().save(getParent());
}
return goBack(cycle);
@@ -136,7 +139,8 @@
{
if (cameFromCollection())
{
- Utils.executeOgnlExpression(getAssociationDescriptor().getRemoveExpression(), getModel(), getParent());
+ IReferenceSupport referenceDescriptor = (IReferenceSupport) getAssociationDescriptor();
+ Utils.executeOgnlExpression(referenceDescriptor.getRemoveExpression(), getModel(), getParent());
getPersistenceService().save(getParent());
}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/util/Utils.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/util/Utils.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/util/Utils.java (working copy)
@@ -163,4 +163,18 @@
throw new TrailsRuntimeException(e, model.getClass());
}
}
+
+ public static boolean implementsInterface (Class clazz, Class interfaze) {
+ boolean result = false;
+
+ Class [] interfaces = clazz.getInterfaces();
+ for ( int i = 0; i < interfaces.length; i++) {
+ Class anInterface = interfaces[i];
+ if ( anInterface.getCanonicalName().equalsIgnoreCase(interfaze.getCanonicalName())) {
+ result = true;
+ break;
+ }
+ }
+ return result;
+ }
}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/TrailsPropertyDescriptor.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/TrailsPropertyDescriptor.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/TrailsPropertyDescriptor.java (working copy)
@@ -354,4 +354,6 @@
{
this.name = name;
}
+
+
}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/IReferenceSupport.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/IReferenceSupport.java (revision 0)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/IReferenceSupport.java (revision 0)
@@ -0,0 +1,42 @@
+package org.trails.descriptor;
+
+public interface IReferenceSupport extends Cloneable {
+
+ /**
+ * InverseProperty was implemented so TrailsPagesService could articulate
+ * and retrieve the inverse
+ *
+ * The automated way this guy gets set:
+ * 1. HibernateDescriptorDecorator on bootstrap
+ * 2. decoration annotation handlers on bootstrap
+ */
+ public String getInverseProperty();
+
+ public void setInverseProperty(String inverseProperty);
+
+ /**
+ * Expression support was added so EditPage could articulate
+ */
+ public String getAddExpression();
+
+ public void setAddExpression(String addExpression);
+
+ public String getRemoveExpression();
+
+ public void setRemoveExpression(String removeExpression);
+
+ public String findAddExpression();
+
+ public String findRemoveExpression();
+
+ /*
+ public String getSwapExpression();
+
+ public void setSwapExpression(String swapExpression);
+
+
+ public String findExpression(String method, String defaultValue);
+
+ public String findExpression(String method);
+ */
+}
\ No newline at end of file
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/ObjectReferenceDescriptor.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/ObjectReferenceDescriptor.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/ObjectReferenceDescriptor.java (working copy)
@@ -18,9 +18,24 @@
* @see HibernateDescriptorDecorator
*/
public class ObjectReferenceDescriptor extends TrailsPropertyDescriptor
+ implements IReferenceSupport
{
- private Class actualType;
+ private Class propertyType;
+
+ private String inverseProperty = null;
+ private String addExpression = null;
+ private String removeExpression = null;
+ public String getInverseProperty()
+ {
+ return inverseProperty;
+ }
+
+ public void setInverseProperty(String inverseProperty)
+ {
+ this.inverseProperty = inverseProperty;
+ }
+
public ObjectReferenceDescriptor(Class beanType, IPropertyDescriptor descriptor,
Class actualType)
{
@@ -35,7 +50,7 @@
Class beanType, Class declaredType, Class actualType)
{
super(beanType, declaredType);
- this.actualType = actualType;
+ this.propertyType = actualType;
}
/* (non-Javadoc)
@@ -43,7 +58,7 @@
*/
public Class getPropertyType()
{
- return actualType;
+ return propertyType;
}
/* (non-Javadoc)
@@ -56,6 +71,59 @@
public Object clone()
{
+ // beanType is the parent Class type
+ // propertyType is the property Class type
return new ObjectReferenceDescriptor(getBeanType(), this, getPropertyType());
}
+
+ public String getAddExpression()
+ {
+ if (addExpression == null)
+ {
+ // addExpression returns the name of the property descriptor
+ // which equates to the lower case singular name of the actual property
+ // as it lives within the class as a class member
+ // (ie. Person == beanType)
+ // (ie. UploadableMedia == propertyType)
+ // (ie. findAddExpression == photo)
+ addExpression = findAddExpression();
+ }
+ return addExpression;
+ }
+
+ public void setAddExpression(String addExpression)
+ {
+ this.addExpression = addExpression;
+ }
+
+ public String getRemoveExpression()
+ {
+ if (removeExpression == null)
+ {
+ removeExpression = findRemoveExpression();
+ }
+ return removeExpression;
+ }
+
+ public void setRemoveExpression(String removeExpression)
+ {
+ this.removeExpression = removeExpression;
+ }
+
+ public String findAddExpression()
+ {
+ String expression = "";
+
+ expression = this.getName();
+
+ return expression;
+ }
+ public String findRemoveExpression()
+ {
+ String expression = "";
+
+ expression = this.getName();
+
+ return expression;
+ }
}
\ No newline at end of file
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/CollectionDescriptor.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/CollectionDescriptor.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/CollectionDescriptor.java (working copy)
@@ -22,6 +22,7 @@
public class CollectionDescriptor extends TrailsPropertyDescriptor
+ implements IReferenceSupport
{
protected static final Log LOG = LogFactory.getLog(CollectionDescriptor.class);
@@ -182,7 +183,7 @@
return new CollectionDescriptor(getBeanType(), this);
}
- private String findAddExpression()
+ public String findAddExpression()
{
final String method = "add";
@@ -204,7 +205,7 @@
}
- private String findRemoveExpression()
+ public String findRemoveExpression()
{
return findExpression("remove");
}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/extension/OwningObjectReferenceDescriptor.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/extension/OwningObjectReferenceDescriptor.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/java/org/trails/descriptor/extension/OwningObjectReferenceDescriptor.java (working copy)
@@ -3,6 +3,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.trails.descriptor.IDescriptorExtension;
+import org.trails.descriptor.IReferenceSupport;
/**
@@ -32,12 +33,14 @@
* @see org.trails.component.AssociationSelect
* @see org.trails.component.AssociationMgt
*/
-public class OwningObjectReferenceDescriptor implements IDescriptorExtension
+public class OwningObjectReferenceDescriptor implements IDescriptorExtension, IReferenceSupport
{
protected static final Log LOG = LogFactory.getLog(OwningObjectReferenceDescriptor.class);
private String inverseProperty = null;
+ private String addExpression = null;
+ private String removeExpression = null;
public String getInverseProperty()
{
@@ -49,4 +52,50 @@
this.inverseProperty = inverseProperty;
}
+ public String getAddExpression()
+ {
+ if (addExpression == null)
+ {
+ // addExpression returns the name of the property descriptor
+ // which equates to the lower case singular name of the actual property
+ // as it lives within the class as a class member
+ // (ie. Person == beanType)
+ // (ie. UploadableMedia == propertyType)
+ // (ie. findAddExpression == photo)
+ addExpression = findAddExpression();
+ }
+ return addExpression;
+ }
+
+ public void setAddExpression(String addExpression)
+ {
+ this.addExpression = addExpression;
+ }
+
+ public String getRemoveExpression()
+ {
+ if (removeExpression == null)
+ {
+ removeExpression = findRemoveExpression();
+ }
+ return removeExpression;
+ }
+
+ public void setRemoveExpression(String removeExpression)
+ {
+ this.removeExpression = removeExpression;
+ }
+
+ public String findAddExpression()
+ {
+ String expression = "NOP";
+
+ return expression;
+ }
+ public String findRemoveExpression()
+ {
+ String expression = "NOP";
+
+ return expression;
+ }
}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/component/AssociationMgt.html
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/component/AssociationMgt.html (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/component/AssociationMgt.html (working copy)
@@ -13,15 +13,39 @@
<tr>
<td>
<div jwcid="@If" condition="ognl:association">
- <input jwcid="removeButton" type="button"
- value="ognl:getMessage(@org.trails.util.Utils@REMOVE_MESSAGE)"/>
+ <input jwcid="removeButton@Submit"
+ type="button"
+ value="ognl:getMessage(@org.trails.util.Utils@REMOVE_MESSAGE)"
+ listener="listener:remove"
+ disabled="ognl:page.modelNew"
+ />
</div>
+
+
+ <span type="button" jwcid="@TrailsLink"
+ model="ognl:association"
+ classDescriptor="ognl:descriptorService.getClassDescriptor(descriptor.propertyType)"
+ pageType="ognl:@org.trails.page.PageType@NEW"
+ associationDescriptor="ognl:descriptor"
+ parent="ognl:owner"
+ disabled="ognl:page.modelNew"
+ renderer="ognl:renderer"
+ name="ognl:getMessage(@org.trails.util.Utils@ADD_NEW_MESSAGE)">
+ <span jwcid="@InsertI18N" bundleKey="org.trails.i18n.addNew" defaultMessage="[TRAILS][ORG.TRAILS.I18N.ADDNEW]"/>
+ </span>
+
+<!--
<div jwcid="@If" condition="ognl:not(page.isModelNew())">
<div jwcid="@If" condition="ognl:not association">
- <input jwcid="addButton" type="button"
- value="ognl:getMessage(@org.trails.util.Utils@ADD_NEW_MESSAGE)"/>
+ <input jwcid="addButton@Submit"
+ type="button"
+ value="ognl:getMessage(@org.trails.util.Utils@ADD_NEW_MESSAGE)"
+ listener="listener:addNew"
+ disabled="ognl:page.modelNew"
+ />
</div>
</div>
+-->
</td>
</tr>
</span>
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/component/AssociationMgt.jwc
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/component/AssociationMgt.jwc (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/component/AssociationMgt.jwc (working copy)
@@ -1,28 +1,5 @@
<!DOCTYPE component-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.1//EN" "
http://jakarta.apache.org/tapestry/dtd/Tapestry_4_1.dtd">
-<component-specification class="org.trails.component.AssociationMgt"
- allow-body="yes"
- allow-informal-parameters="yes">
+<component-specification class="org.trails.component.HibernateAssociationMgt">
- <property name="nextPage"/>
-
- <property name="delegator"/>
-
- <bean name="numberValidator" class="org.apache.tapestry.valid.NumberValidator" lifecycle="page">
- <set name="valueType">"int"</set>
- </bean>
-
- <component id="addButton" type="Submit">
- <binding name="listener">listener:addNew</binding>
- <binding name="defer">true</binding>
- <binding name="disabled">page.isModelNew()</binding>
- </component>
- <component id="removeButton" type="Submit">
- <binding name="listener">listener:remove</binding>
- <binding name="defer">false</binding>
- <binding name="disabled">page.isModelNew()</binding>
- </component>
-
- <parameter name="createExpression" required="no">
- <description>Ognl expression to invoke on the model to create a new association instance</description>
- </parameter>
</component-specification>
+
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/page/Editors.page
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/page/Editors.page (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/page/Editors.page (working copy)
@@ -59,6 +59,17 @@
<binding name="propertyDescriptor">descriptor</binding>
</component>
+ <component id="blobFields" type="BlobComponent">
+ <binding name="model">model</binding>
+ <binding name="descriptor">descriptor</binding>
+ </component>
+
+ <component id="associationMgt" type="AssociationMgt">
+ <binding name="owner">model</binding>
+ <binding name="association">model[#this.descriptor.name]</binding>
+ <binding name="descriptor">descriptor</binding>
+ </component>
+
<component id="associationSelect" type="AssociationSelect">
<binding name="value">model[#this.descriptor.name]</binding>
<binding name="propertyDescriptor">descriptor</binding>
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/page/Editors.html
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/page/Editors.html (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-core/src/main/resources/org/trails/page/Editors.html (working copy)
@@ -84,4 +84,16 @@
<label class="desc" jwcid="@FieldLabel" field="component:enumSelect" displayName="ognl:descriptor.displayName"/>
<select jwcid="enumSelect" class="field select medium"/>
</li>
-</span>
\ No newline at end of file
+</span>
+
+<span jwcid="blobEditor@Block">
+ <li><label class="desc"><span jwcid="@Insert" value="ognl:descriptor.displayName"/></label>
+ <span jwcid="blobFields" class="field text medium"/>
+ </li>
+</span>
+
+<span jwcid="owningReferenceEditor@Block">
+ <li><label class="desc"><span jwcid="@Insert" value="ognl:descriptor.displayName"/></label>
+ <select jwcid="associationMgt" class="field"/>
+ </li>
+</span>
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/java/org/trails/hibernate/HibernatePersistenceServiceImpl.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/java/org/trails/hibernate/HibernatePersistenceServiceImpl.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/java/org/trails/hibernate/HibernatePersistenceServiceImpl.java (working copy)
@@ -1,491 +1,509 @@
-/*
- * Copyright 2004 Chris Nelson
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and limitations under the License.
- */
-package org.trails.hibernate;
-
-import ognl.Ognl;
-import ognl.OgnlException;
-import org.hibernate.*;
-import org.hibernate.criterion.*;
-import org.hibernate.metadata.ClassMetadata;
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.dao.DataAccessException;
-import org.springframework.orm.hibernate3.HibernateCallback;
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-import org.trails.util.Utils;
-import org.trails.descriptor.CollectionDescriptor;
-import org.trails.descriptor.DescriptorService;
-import org.trails.descriptor.IClassDescriptor;
-import org.trails.descriptor.IPropertyDescriptor;
-import org.trails.persistence.HibernatePersistenceService;
-import org.trails.persistence.PersistenceException;
-import org.trails.validation.ValidationException;
-
-import java.io.Serializable;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-public class HibernatePersistenceServiceImpl extends HibernateDaoSupport implements
- HibernatePersistenceService, ApplicationContextAware
-{
-
- ApplicationContext appContext = null;
- private DescriptorService _descriptorService = null;
-
- /**
- * We need this because cylcic reference between HibernatePersistenceServiceImpl and TrailsDescriptorService
- */
- public DescriptorService getDescriptorService()
- {
- if (_descriptorService == null)
- {
- _descriptorService = (DescriptorService) appContext.getBean("descriptorService");
- }
- return _descriptorService;
- }
-
- /**
- *
https://trails.dev.java.net/servlets/ReadMsg?listName=users&msgNo=1226- * <p/>
- * Very often I find myself writing: <code> Object example = new Object(); example.setProperty(uniqueValue); List
- * objects = ((TrailsPage)getPage()).getPersistenceService().getInstances(example); (MyObject)objects.get(0); </code>
- * when, in fact, I know that the single property I populated my example object with should be unique, and thus only
- * one object should be returned
- *
- * @param type The type to use to check for security restrictions.
- * @param detachedCriteria
- * @return
- */
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public <T> T getInstance(final Class<T> type, DetachedCriteria detachedCriteria)
- {
- final DetachedCriteria criteria = alterCriteria(type, detachedCriteria);
-
- return (T) getHibernateTemplate().execute(new HibernateCallback()
- {
- public Object doInHibernate(Session session) throws HibernateException, SQLException
- {
- return criteria.getExecutableCriteria(session).uniqueResult();
- }
- });
- }
-
- /**
- * (non-Javadoc)
- *
- * @see org.trails.persistence.PersistenceService#getInstance(Class,Serializable)
- */
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public <T> T getInstance(final Class<T> type, final Serializable id)
- {
- DetachedCriteria criteria = DetachedCriteria.forClass(Utils.checkForCGLIB(type)).add(Expression.idEq(id));
- return getInstance(type, criteria);
- }
-
-
- /**
- * <strong>Description copied from:</strong> {@link org.springframework.orm.hibernate3.HibernateTemplate#load(Class,java.io.Serializable)}
- * and {@link org.hibernate.Session#load(Class,java.io.Serializable)}
- * <p/>
- * Return the persistent instance of the given entity class with the given identifier, assuming that the instance
- * exists, throwing an exception if not found.
- * <p/>
- * You should not use this method to determine if an instance exists (use get() instead). Use this only to retrieve an
- * instance that you assume exists, where non-existence would be an actual error.
- * <p/>
- * <p>This method is a thin wrapper around {@link org.hibernate.Session#load(Class,java.io.Serializable)} for
- * convenience. For an explanation of the exact semantics of this method, please do refer to the Hibernate API
- * documentation in the first instance.
- *
- * @param type a persistent class
- * @param id the identifier of the persistent instance
- * @return the persistent instance
- * @see org.springframework.orm.hibernate3.HibernateTemplate#load(Class,java.io.Serializable)
- * @see org.hibernate.Session#load(Class,java.io.Serializable)
- */
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public <T> T loadInstance(final Class<T> type, Serializable id)
- {
- return (T) getHibernateTemplate().load(type, id);
- }
-
- /**
- * Execute an HQL query.
- *
- * @param queryString a query expressed in Hibernate's query language
- * @return a List containing the results of the query execution
- * @see org.springframework.orm.hibernate3.HibernateTemplate#find(String)
- */
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public List find(String queryString)
- {
- return getHibernateTemplate().find(queryString);
- }
-
- /**
- * Execute an HQL query, binding one value to a "?" parameter in the query string.
- *
- * @param queryString a query expressed in Hibernate's query language
- * @param value the query parameter
- * @return a List containing the results of the query execution
- * @see org.springframework.orm.hibernate3.HibernateTemplate#find(String,Object)
- */
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public List find(String queryString, Object value)
- {
- return getHibernateTemplate().find(queryString, value);
- }
-
- /**
- * Execute an HQL query, binding a number of values to "?" parameters in the query string.
- *
- * @param queryString a query expressed in Hibernate's query language
- * @param values the query parameters
- * @return a List containing the results of the query execution
- * @see org.springframework.orm.hibernate3.HibernateTemplate#find(String,Object[])
- */
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public List find(String queryString, Object[] values)
- {
- return getHibernateTemplate().find(queryString, values);
- }
-
-
- /**
- * (non-Javadoc)
- *
- * @see org.trails.persistence.PersistenceService#getAllInstances(java.lang.Class)
- */
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public <T> List<T> getAllInstances(final Class<T> type)
- {
- DetachedCriteria criteria = DetachedCriteria.forClass(Utils.checkForCGLIB(type));
- return getInstances(type, criteria);
- }
-
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public <T> List<T> getInstances(final Class<T> type, int startIndex, int maxResults)
- {
- return getInstances(type, DetachedCriteria.forClass(type), startIndex, maxResults);
- }
-
- /**
- * (non-Javadoc)
- *
- * @see org.trails.persistence.PersistenceService#save(java.lang.Object)
- */
- @Transactional
- public <T> T save(T instance) throws ValidationException
- {
- try
- {
- IClassDescriptor iClassDescriptor = getDescriptorService().getClassDescriptor(instance.getClass());
- /* check isTransient to avoid merging on entities not persisted yet. TRAILS-33 */
- if (!iClassDescriptor.getHasCyclicRelationships() || isTransient(instance, iClassDescriptor))
- {
- getHibernateTemplate().saveOrUpdate(instance);
- } else
- {
- instance = (T) getHibernateTemplate().merge(instance);
- }
- return instance;
- }
- catch (DataAccessException dex)
- {
- throw new PersistenceException(dex);
- }
- }
-
- @Transactional
- public void removeAll(Collection collection)
- {
- getHibernateTemplate().deleteAll(collection);
- }
-
- @Transactional
- public void remove(Object instance)
- {
- // merge first to avoid NonUniqueObjectException
- getHibernateTemplate().delete(getHibernateTemplate().merge(instance));
- }
-
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public <T> List<T> getInstances(Class<T> type, DetachedCriteria criteria)
- {
- criteria = alterCriteria(type, criteria);
- criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
- return getHibernateTemplate().findByCriteria(criteria);
- }
-
- /**
- * (non-Javadoc)
- *
- * @see org.trails.persistence.PersistenceService#getAllTypes()
- */
- public List<Class> getAllTypes()
- {
- ArrayList<Class> allTypes = new ArrayList<Class>();
- for (Object classMetadata : getSessionFactory().getAllClassMetadata().values())
- {
- allTypes.add(((ClassMetadata) classMetadata).getMappedClass(EntityMode.POJO));
- }
- return allTypes;
- }
-
- @Transactional
- public void reattach(Object model)
- {
- getSession().lock(model, LockMode.NONE);
- }
-
-
- /**
- * (non-Javadoc)
- *
- * @see org.trails.persistence.PersistenceService#getInstance(Class<T>)
- */
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public <T> T getInstance(final Class<T> type)
- {
- return (T) getInstance(type, DetachedCriteria.forClass(type));
- }
-
- public Serializable getIdentifier(final Object data, final IClassDescriptor classDescriptor)
- {
- try
- {
- /** This is only until I figure out where are the Callbacks persisting its properties **/
-
- return (Serializable) Ognl.getValue(classDescriptor.getIdentifierDescriptor().getName(), data);
-
- } catch (OgnlException e)
- {
- return null;
- }
- }
-
-
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- private Serializable getIdentifier(final Object data)
- {
- return (Serializable) getHibernateTemplate().execute(new HibernateCallback()
- {
- public Object doInHibernate(Session session) throws HibernateException, SQLException
- {
- return session.getIdentifier(data);
- }
- });
- }
-
- public boolean isTransient(Object data, IClassDescriptor classDescriptor)
- {
- try
- {
- return getIdentifier(data, classDescriptor) == null;
- } catch (TransientObjectException e)
- {
- return true;
- }
- }
-
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public List getInstances(final Object example, final IClassDescriptor classDescriptor)
- {
- return (List) getHibernateTemplate().execute(new HibernateCallback()
- {
- public Object doInHibernate(Session session) throws HibernateException, SQLException
- {
- //create Criteria instance
- DetachedCriteria searchCriteria = DetachedCriteria.forClass(Utils.checkForCGLIB(example.getClass()));
- searchCriteria = alterCriteria(example.getClass(), searchCriteria);
-
- //loop over the example object's PropertyDescriptors
- for (IPropertyDescriptor propertyDescriptor : classDescriptor.getPropertyDescriptors())
- {
- //only add a Criterion to the Criteria instance if this property is searchable
- if (propertyDescriptor.isSearchable())
- {
- String propertyName = propertyDescriptor.getName();
- Class propertyClass = propertyDescriptor.getPropertyType();
- Object value = null;
- try
- {
- value = Ognl.getValue(propertyName, example);
- } catch (OgnlException e)
- { /* do nothing! */ }
-
- //only add a Criterion to the Criteria instance if the value for this property is non-null
- if (value != null)
- {
- if (String.class.isAssignableFrom(propertyClass) && ((String) value).length() > 0)
- {
- searchCriteria
- .add(Restrictions.like(propertyName, value.toString(), MatchMode.ANYWHERE));
- }
- /**
- * 'one'-end of many-to-one, one-to-one
- *
- * Just match the identifier
- */
- else if (propertyDescriptor.isObjectReference())
- {
- Serializable identifierValue = getIdentifier(value,
- getDescriptorService().getClassDescriptor(propertyDescriptor.getBeanType()));
- searchCriteria.createCriteria(propertyName).add(Restrictions.idEq(identifierValue));
- } else if (propertyClass.isPrimitive())
- {
- //primitive types: ignore zeroes in case of numeric types, ignore booleans anyway (TODO come up with something...)
- if (!propertyClass.equals(boolean.class) && ((Number) value).longValue() != 0)
- {
- searchCriteria.add(Restrictions.eq(propertyName, value));
- }
- } else if (propertyDescriptor.isCollection())
- {
- //one-to-many or many-to-many
- CollectionDescriptor collectionDescriptor =
- (CollectionDescriptor) propertyDescriptor;
- IClassDescriptor classDescriptor = getDescriptorService().getClassDescriptor(collectionDescriptor.getElementType());
- if (classDescriptor != null)
- {
- String identifierName = classDescriptor.getIdentifierDescriptor().getName();
- Collection<Serializable> identifierValues = new ArrayList<Serializable>();
- Collection associatedItems = (Collection) value;
- if (associatedItems != null && associatedItems.size() > 0)
- {
- for (Object o : associatedItems)
- {
- identifierValues.add(getIdentifier(o, classDescriptor));
- }
- //add a 'value IN collection' restriction
- searchCriteria.createCriteria(propertyName)
- .add(Restrictions.in(identifierName, identifierValues));
- }
- }
- }
- }
- }
- }
- searchCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
- return searchCriteria.getExecutableCriteria(session).list();
- }
- }, true);
- }
-
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public int count(Class type, DetachedCriteria detachedCriteria)
- {
- // todo hacking useNative is a result of SPR-2499 and will be removed soon
- boolean useNative = getHibernateTemplate().isExposeNativeSession();
- getHibernateTemplate().setExposeNativeSession(true);
- detachedCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
- final DetachedCriteria criteria = alterCriteria(type, detachedCriteria);
- Integer result = (Integer) getHibernateTemplate().execute(new HibernateCallback()
- {
- public Object doInHibernate(Session session) throws HibernateException, SQLException
- {
- Criteria executableCriteria =
- criteria.getExecutableCriteria(session).setProjection(Projections.rowCount());
- return executableCriteria.uniqueResult();
- }
- });
- getHibernateTemplate().setExposeNativeSession(useNative);
- return result;
- }
-
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public <T> List<T> getInstances(Class<T> type, final DetachedCriteria detachedCriteria, final int startIndex, final int maxResults)
- {
- return getInstances(alterCriteria(type, detachedCriteria), startIndex, maxResults);
- }
-
- @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
- public List getInstances(final DetachedCriteria detachedCriteria, final int startIndex, final int maxResults)
- {
- detachedCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
- // todo hacking useNative is a result of SPR-2499 and will be removed soon
- boolean useNative = getHibernateTemplate().isExposeNativeSession();
- getHibernateTemplate().setExposeNativeSession(true);
- List result = (List) getHibernateTemplate().execute(new HibernateCallback()
- {
- public Object doInHibernate(Session session) throws HibernateException, SQLException
- {
- Criteria executableCriteria = detachedCriteria.getExecutableCriteria(session);
- if (startIndex >= 0)
- {
- executableCriteria.setFirstResult(startIndex);
- }
- if (maxResults > 0)
- {
- executableCriteria.setMaxResults(maxResults);
- }
- return executableCriteria.list();
- }
- });
- getHibernateTemplate().setExposeNativeSession(useNative);
- return result;
- }
-
- /**
- * This hook allows subclasses to modify the query criteria, such as for security
- *
- * @param detachedCriteria The original Criteria query
- * @return The modified Criteria query for execution
- */
- protected DetachedCriteria alterCriteria(Class type, DetachedCriteria detachedCriteria)
- {
- return detachedCriteria;
- }
-
- /**
- * @see org.trails.persistence.HibernatePersistenceService#saveOrUpdate(java.lang.Object)
- */
- @Transactional
- public <T> T merge(T instance)
- {
- try
- {
- return (T) getHibernateTemplate().merge(instance);
- }
- catch (DataAccessException dex)
- {
- throw new PersistenceException(dex);
- }
- }
-
- /**
- * @see org.trails.persistence.HibernatePersistenceService#saveOrUpdate(java.lang.Object)
- */
- @Transactional
- public <T> T saveOrUpdate(T instance) throws ValidationException
- {
- try
- {
- getHibernateTemplate().saveOrUpdate(instance);
- return instance;
- }
- catch (DataAccessException dex)
- {
- throw new PersistenceException(dex);
- }
- }
-
- public void setApplicationContext(ApplicationContext arg0) throws BeansException
- {
- this.appContext = arg0;
-
- }
-}
+/*
+ * Copyright 2004 Chris Nelson
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ */
+package org.trails.hibernate;
+
+import ognl.Ognl;
+import ognl.OgnlException;
+import org.hibernate.*;
+import org.hibernate.criterion.*;
+import org.hibernate.metadata.ClassMetadata;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.dao.DataAccessException;
+import org.springframework.orm.hibernate3.HibernateCallback;
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+import org.trails.util.Utils;
+import org.trails.descriptor.CollectionDescriptor;
+import org.trails.descriptor.DescriptorService;
+import org.trails.descriptor.IClassDescriptor;
+import org.trails.descriptor.IPropertyDescriptor;
+import org.trails.persistence.HibernatePersistenceService;
+import org.trails.persistence.PersistenceException;
+import org.trails.validation.ValidationException;
+
+import java.io.Serializable;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class HibernatePersistenceServiceImpl extends HibernateDaoSupport implements
+ HibernatePersistenceService, ApplicationContextAware
+{
+
+ ApplicationContext appContext = null;
+ private DescriptorService _descriptorService = null;
+
+ /**
+ * We need this because cylcic reference between HibernatePersistenceServiceImpl and TrailsDescriptorService
+ */
+ public DescriptorService getDescriptorService()
+ {
+ if (_descriptorService == null)
+ {
+ _descriptorService = (DescriptorService) appContext.getBean("descriptorService");
+ }
+ return _descriptorService;
+ }
+
+ /**
+ *
https://trails.dev.java.net/servlets/ReadMsg?listName=users&msgNo=1226+ * <p/>
+ * Very often I find myself writing: <code> Object example = new Object(); example.setProperty(uniqueValue); List
+ * objects = ((TrailsPage)getPage()).getPersistenceService().getInstances(example); (MyObject)objects.get(0); </code>
+ * when, in fact, I know that the single property I populated my example object with should be unique, and thus only
+ * one object should be returned
+ *
+ * @param type The type to use to check for security restrictions.
+ * @param detachedCriteria
+ * @return
+ */
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public <T> T getInstance(final Class<T> type, DetachedCriteria detachedCriteria)
+ {
+ final DetachedCriteria criteria = alterCriteria(type, detachedCriteria);
+
+ return (T) getHibernateTemplate().execute(new HibernateCallback()
+ {
+ public Object doInHibernate(Session session) throws HibernateException, SQLException
+ {
+ return criteria.getExecutableCriteria(session).uniqueResult();
+ }
+ });
+ }
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.trails.persistence.PersistenceService#getInstance(Class,Serializable)
+ */
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public <T> T getInstance(final Class<T> type, final Serializable id)
+ {
+ DetachedCriteria criteria = DetachedCriteria.forClass(Utils.checkForCGLIB(type)).add(Expression.idEq(id));
+ return getInstance(type, criteria);
+ }
+
+
+ /**
+ * <strong>Description copied from:</strong> {@link org.springframework.orm.hibernate3.HibernateTemplate#load(Class,java.io.Serializable)}
+ * and {@link org.hibernate.Session#load(Class,java.io.Serializable)}
+ * <p/>
+ * Return the persistent instance of the given entity class with the given identifier, assuming that the instance
+ * exists, throwing an exception if not found.
+ * <p/>
+ * You should not use this method to determine if an instance exists (use get() instead). Use this only to retrieve an
+ * instance that you assume exists, where non-existence would be an actual error.
+ * <p/>
+ * <p>This method is a thin wrapper around {@link org.hibernate.Session#load(Class,java.io.Serializable)} for
+ * convenience. For an explanation of the exact semantics of this method, please do refer to the Hibernate API
+ * documentation in the first instance.
+ *
+ * @param type a persistent class
+ * @param id the identifier of the persistent instance
+ * @return the persistent instance
+ * @see org.springframework.orm.hibernate3.HibernateTemplate#load(Class,java.io.Serializable)
+ * @see org.hibernate.Session#load(Class,java.io.Serializable)
+ */
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public <T> T loadInstance(final Class<T> type, Serializable id)
+ {
+ return (T) getHibernateTemplate().load(type, id);
+ }
+
+ /**
+ * Execute an HQL query.
+ *
+ * @param queryString a query expressed in Hibernate's query language
+ * @return a List containing the results of the query execution
+ * @see org.springframework.orm.hibernate3.HibernateTemplate#find(String)
+ */
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public List find(String queryString)
+ {
+ return getHibernateTemplate().find(queryString);
+ }
+
+ /**
+ * Execute an HQL query, binding one value to a "?" parameter in the query string.
+ *
+ * @param queryString a query expressed in Hibernate's query language
+ * @param value the query parameter
+ * @return a List containing the results of the query execution
+ * @see org.springframework.orm.hibernate3.HibernateTemplate#find(String,Object)
+ */
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public List find(String queryString, Object value)
+ {
+ return getHibernateTemplate().find(queryString, value);
+ }
+
+ /**
+ * Execute an HQL query, binding a number of values to "?" parameters in the query string.
+ *
+ * @param queryString a query expressed in Hibernate's query language
+ * @param values the query parameters
+ * @return a List containing the results of the query execution
+ * @see org.springframework.orm.hibernate3.HibernateTemplate#find(String,Object[])
+ */
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public List find(String queryString, Object[] values)
+ {
+ return getHibernateTemplate().find(queryString, values);
+ }
+
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.trails.persistence.PersistenceService#getAllInstances(java.lang.Class)
+ */
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public <T> List<T> getAllInstances(final Class<T> type)
+ {
+ DetachedCriteria criteria = DetachedCriteria.forClass(Utils.checkForCGLIB(type));
+ return getInstances(type, criteria);
+ }
+
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public <T> List<T> getInstances(final Class<T> type, int startIndex, int maxResults)
+ {
+ return getInstances(type, DetachedCriteria.forClass(type), startIndex, maxResults);
+ }
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.trails.persistence.PersistenceService#save(java.lang.Object)
+ */
+ @Transactional
+ public <T> T save(T instance) throws ValidationException
+ {
+ try
+ {
+ IClassDescriptor iClassDescriptor = getDescriptorService().getClassDescriptor(instance.getClass());
+ /* check isTransient to avoid merging on entities not persisted yet. TRAILS-33 */
+ if (!iClassDescriptor.getHasCyclicRelationships() || isTransient(instance, iClassDescriptor))
+ {
+ getHibernateTemplate().saveOrUpdate(instance);
+ } else
+ {
+ instance = (T) getHibernateTemplate().merge(instance);
+ }
+ return instance;
+ }
+ catch (DataAccessException dex)
+ {
+ throw new PersistenceException(dex);
+ }
+ }
+
+ @Transactional
+ public void removeAll(Collection collection)
+ {
+ getHibernateTemplate().deleteAll(collection);
+ }
+
+ @Transactional
+ public void remove(Object instance)
+ {
+ // merge first to avoid NonUniqueObjectException
+ getHibernateTemplate().delete(getHibernateTemplate().merge(instance));
+ }
+
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public <T> List<T> getInstances(Class<T> type, DetachedCriteria criteria)
+ {
+ criteria = alterCriteria(type, criteria);
+ criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
+ return getHibernateTemplate().findByCriteria(criteria);
+ }
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.trails.persistence.PersistenceService#getAllTypes()
+ */
+ public List<Class> getAllTypes()
+ {
+ ArrayList<Class> allTypes = new ArrayList<Class>();
+ for (Object classMetadata : getSessionFactory().getAllClassMetadata().values())
+ {
+ allTypes.add(((ClassMetadata) classMetadata).getMappedClass(EntityMode.POJO));
+ }
+ return allTypes;
+ }
+
+ @Transactional
+ public void reattach(Object model)
+ {
+ getSession().lock(model, LockMode.NONE);
+ }
+
+ public void reattachCollection(Object[] models)
+ {
+ if ( models != null )
+ for ( int i = 0; i < models.length; i++)
+ reattach (models[i]);
+ }
+
+
+ public void mergeCollection(Object[] models)
+ {
+ if ( models != null )
+ for ( int i = 0; i < models.length; i++)
+ merge (models[i]);
+ }
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.trails.persistence.PersistenceService#getInstance(Class<T>)
+ */
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public <T> T getInstance(final Class<T> type)
+ {
+ return (T) getInstance(type, DetachedCriteria.forClass(type));
+ }
+
+ public Serializable getIdentifier(final Object data, final IClassDescriptor classDescriptor)
+ {
+ try
+ {
+ /** This is only until I figure out where are the Callbacks persisting its properties **/
+
+ return (Serializable) Ognl.getValue(classDescriptor.getIdentifierDescriptor().getName(), data);
+
+ } catch (OgnlException e)
+ {
+ return null;
+ }
+ }
+
+
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ private Serializable getIdentifier(final Object data)
+ {
+ return (Serializable) getHibernateTemplate().execute(new HibernateCallback()
+ {
+ public Object doInHibernate(Session session) throws HibernateException, SQLException
+ {
+ return session.getIdentifier(data);
+ }
+ });
+ }
+
+ public boolean isTransient(Object data, IClassDescriptor classDescriptor)
+ {
+ try
+ {
+ return getIdentifier(data, classDescriptor) == null;
+ } catch (TransientObjectException e)
+ {
+ return true;
+ }
+ }
+
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public List getInstances(final Object example, final IClassDescriptor classDescriptor)
+ {
+ return (List) getHibernateTemplate().execute(new HibernateCallback()
+ {
+ public Object doInHibernate(Session session) throws HibernateException, SQLException
+ {
+ //create Criteria instance
+ DetachedCriteria searchCriteria = DetachedCriteria.forClass(Utils.checkForCGLIB(example.getClass()));
+ searchCriteria = alterCriteria(example.getClass(), searchCriteria);
+
+ //loop over the example object's PropertyDescriptors
+ for (IPropertyDescriptor propertyDescriptor : classDescriptor.getPropertyDescriptors())
+ {
+ //only add a Criterion to the Criteria instance if this property is searchable
+ if (propertyDescriptor.isSearchable())
+ {
+ String propertyName = propertyDescriptor.getName();
+ Class propertyClass = propertyDescriptor.getPropertyType();
+ Object value = null;
+ try
+ {
+ value = Ognl.getValue(propertyName, example);
+ } catch (OgnlException e)
+ { /* do nothing! */ }
+
+ //only add a Criterion to the Criteria instance if the value for this property is non-null
+ if (value != null)
+ {
+ if (String.class.isAssignableFrom(propertyClass) && ((String) value).length() > 0)
+ {
+ searchCriteria
+ .add(Restrictions.like(propertyName, value.toString(), MatchMode.ANYWHERE));
+ }
+ /**
+ * 'one'-end of many-to-one, one-to-one
+ *
+ * Just match the identifier
+ */
+ else if (propertyDescriptor.isObjectReference())
+ {
+ Serializable identifierValue = getIdentifier(value,
+ getDescriptorService().getClassDescriptor(propertyDescriptor.getBeanType()));
+ searchCriteria.createCriteria(propertyName).add(Restrictions.idEq(identifierValue));
+ } else if (propertyClass.isPrimitive())
+ {
+ //primitive types: ignore zeroes in case of numeric types, ignore booleans anyway (TODO come up with something...)
+ if (!propertyClass.equals(boolean.class) && ((Number) value).longValue() != 0)
+ {
+ searchCriteria.add(Restrictions.eq(propertyName, value));
+ }
+ } else if (propertyDescriptor.isCollection())
+ {
+ //one-to-many or many-to-many
+ CollectionDescriptor collectionDescriptor =
+ (CollectionDescriptor) propertyDescriptor;
+ IClassDescriptor classDescriptor = getDescriptorService().getClassDescriptor(collectionDescriptor.getElementType());
+ if (classDescriptor != null)
+ {
+ String identifierName = classDescriptor.getIdentifierDescriptor().getName();
+ Collection<Serializable> identifierValues = new ArrayList<Serializable>();
+ Collection associatedItems = (Collection) value;
+ if (associatedItems != null && associatedItems.size() > 0)
+ {
+ for (Object o : associatedItems)
+ {
+ identifierValues.add(getIdentifier(o, classDescriptor));
+ }
+ //add a 'value IN collection' restriction
+ searchCriteria.createCriteria(propertyName)
+ .add(Restrictions.in(identifierName, identifierValues));
+ }
+ }
+ }
+ }
+ }
+ }
+ searchCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
+ return searchCriteria.getExecutableCriteria(session).list();
+ }
+ }, true);
+ }
+
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public int count(Class type, DetachedCriteria detachedCriteria)
+ {
+ // todo hacking useNative is a result of SPR-2499 and will be removed soon
+ boolean useNative = getHibernateTemplate().isExposeNativeSession();
+ getHibernateTemplate().setExposeNativeSession(true);
+ detachedCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
+ final DetachedCriteria criteria = alterCriteria(type, detachedCriteria);
+ Integer result = (Integer) getHibernateTemplate().execute(new HibernateCallback()
+ {
+ public Object doInHibernate(Session session) throws HibernateException, SQLException
+ {
+ Criteria executableCriteria =
+ criteria.getExecutableCriteria(session).setProjection(Projections.rowCount());
+ return executableCriteria.uniqueResult();
+ }
+ });
+ getHibernateTemplate().setExposeNativeSession(useNative);
+ return result;
+ }
+
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public <T> List<T> getInstances(Class<T> type, final DetachedCriteria detachedCriteria, final int startIndex, final int maxResults)
+ {
+ return getInstances(alterCriteria(type, detachedCriteria), startIndex, maxResults);
+ }
+
+ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
+ public List getInstances(final DetachedCriteria detachedCriteria, final int startIndex, final int maxResults)
+ {
+ detachedCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
+ // todo hacking useNative is a result of SPR-2499 and will be removed soon
+ boolean useNative = getHibernateTemplate().isExposeNativeSession();
+ getHibernateTemplate().setExposeNativeSession(true);
+ List result = (List) getHibernateTemplate().execute(new HibernateCallback()
+ {
+ public Object doInHibernate(Session session) throws HibernateException, SQLException
+ {
+ Criteria executableCriteria = detachedCriteria.getExecutableCriteria(session);
+ if (startIndex >= 0)
+ {
+ executableCriteria.setFirstResult(startIndex);
+ }
+ if (maxResults > 0)
+ {
+ executableCriteria.setMaxResults(maxResults);
+ }
+ return executableCriteria.list();
+ }
+ });
+ getHibernateTemplate().setExposeNativeSession(useNative);
+ return result;
+ }
+
+ /**
+ * This hook allows subclasses to modify the query criteria, such as for security
+ *
+ * @param detachedCriteria The original Criteria query
+ * @return The modified Criteria query for execution
+ */
+ protected DetachedCriteria alterCriteria(Class type, DetachedCriteria detachedCriteria)
+ {
+ return detachedCriteria;
+ }
+
+ /**
+ * @see org.trails.persistence.HibernatePersistenceService#saveOrUpdate(java.lang.Object)
+ */
+ @Transactional(readOnly=false)
+ public <T> T merge(T instance)
+ {
+ Object mergedInstance;
+ FlushMode previousFlushMode = getSession().getFlushMode();
+ getSession().setFlushMode(FlushMode.COMMIT);
+ try {
+ mergedInstance = getHibernateTemplate().merge(instance);
+ }
+ catch (DataAccessException dex) {
+ throw new PersistenceException(dex);
+ } finally {
+ getSession().setFlushMode(previousFlushMode);
+ }
+ return (T) mergedInstance;
+ }
+
+ /**
+ * @see org.trails.persistence.HibernatePersistenceService#saveOrUpdate(java.lang.Object)
+ */
+ @Transactional
+ public <T> T saveOrUpdate(T instance) throws ValidationException
+ {
+ try
+ {
+ getHibernateTemplate().saveOrUpdate(instance);
+ return instance;
+ }
+ catch (DataAccessException dex)
+ {
+ throw new PersistenceException(dex);
+ }
+ }
+
+ public void setApplicationContext(ApplicationContext arg0) throws BeansException
+ {
+ this.appContext = arg0;
+
+ }
+}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/java/org/trails/component/HibernateAssociationMgt.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/java/org/trails/component/HibernateAssociationMgt.java (revision 0)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/java/org/trails/component/HibernateAssociationMgt.java (revision 0)
@@ -0,0 +1,63 @@
+package org.trails.component;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tapestry.IAsset;
+import org.apache.tapestry.IPage;
+import org.apache.tapestry.annotations.Asset;
+import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.annotations.InjectObject;
+import org.hibernate.NonUniqueObjectException;
+import org.trails.page.EditPage;
+import org.trails.page.PageType;
+import org.trails.persistence.HibernatePersistenceService;
+import org.trails.util.Utils;
+
+/**
+ * @OneToOne use case. <p/>
+ *
+ * This guy manages the owning side user interface of a OneToOne association.
+ * <p/> Owner-<>-----Association
+ *
+ * @author kenneth.colassi
nhhockeyplayer@...
+ */
+@ComponentClass(allowBody = true, allowInformalParameters = true)
+public abstract class HibernateAssociationMgt extends AssociationMgt {
+ @Asset(value = "/org/trails/component/AssociationMgt.html")
+ public abstract IAsset get$template();
+
+ protected static final Log LOG = LogFactory
+ .getLog(HibernateAssociationMgt.class);
+
+ /**
+ * @todo: remove when the components reuse issue goes away
+ */
+ @InjectObject("service:trails.hibernate.PersistenceService")
+ public abstract HibernatePersistenceService getHibernatePersistenceService();
+
+ /**
+ * @todo: remove when the components reuse issue goes away
+ */
+ @Override
+ public HibernatePersistenceService getPersistenceService() {
+ return getHibernatePersistenceService();
+ }
+
+ public IPage edit(Object member)
+ {
+
+ EditPage editPage = (EditPage) getPageResolver().resolvePage(
+ getPage().getRequestCycle(),
+ Utils.checkForCGLIB(member.getClass()),
+ PageType.EDIT);
+ try
+ {
+ getPersistenceService().reattach(member);
+ } catch (NonUniqueObjectException e)
+ {
+ }
+ editPage.setModel(member);
+ return editPage;
+ }
+
+}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/java/org/trails/record/ReattachReattachPropertyPersistenceStrategy.java
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/java/org/trails/record/ReattachReattachPropertyPersistenceStrategy.java (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/java/org/trails/record/ReattachReattachPropertyPersistenceStrategy.java (working copy)
@@ -13,7 +13,11 @@
protected Object reattach(Object entity)
{
- persistenceService.reattach(entity);
+ try {
+ persistenceService.reattach(entity);
+ } catch (org.hibernate.NonUniqueObjectException nuoe) {
+ persistenceService.merge(entity);
+ }
return entity;
}
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/resources/org/trails/component/HibernateAssociationMgt.jwc
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/resources/org/trails/component/HibernateAssociationMgt.jwc (revision 0)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/resources/org/trails/component/HibernateAssociationMgt.jwc (revision 0)
@@ -0,0 +1,5 @@
+<!DOCTYPE component-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.1//EN" "
http://jakarta.apache.org/tapestry/dtd/Tapestry_4_1.dtd">
+<component-specification class="org.trails.component.HibernateAssociationMgt">
+
+</component-specification>
+
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/resources/org/trails/page/HibernateEditors.page
===================================================================
--- C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/resources/org/trails/page/HibernateEditors.page (revision 920)
+++ C:/Prototype/Mavenized/Product/trails/trunk/trails/modules/trails-hibernate/src/main/resources/org/trails/page/HibernateEditors.page (working copy)
@@ -81,21 +81,18 @@
<binding name="value">model[#this.descriptor.name]</binding>
<binding name="propertyDescriptor">descriptor</binding>
</component>
-
+
<component id="blobFields" type="BlobComponent">
<binding name="model">model</binding>
<binding name="descriptor">descriptor</binding>
</component>
<component id="associationMgt" type="AssociationMgt">
- <binding name="model">model</binding>
- <binding name="value">model[#this.descriptor.name]</binding>
<binding name="owner">model</binding>
<binding name="association">model[#this.descriptor.name]</binding>
<binding name="descriptor">descriptor</binding>
</component>
-
- <!--
+<!--
<component id="associationSelect" type="AssociationSelect">
<binding name="model">model</binding>
<binding name="value">model[#this.descriptor.name]</binding>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_emailBest regards
Ken in nashua