Issue Details (XML | Word | Printable)

Key: TRAILS-82
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Ken in nashua
Reporter: Ken in nashua
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Trails

SINGLETON Annotation required to properly manage these at entity level

Created: 09/Jul/07 05:18 PM   Updated: 04/Oct/07 04:23 PM
Component/s: trails-hibernate
Affects Version/s: 1.1.0
Fix Version/s: 1.1.0

Time Tracking:
Not Specified

Environment: All


 Description  « Hide
SINGLETON Annotation required to properly manage these at entity level.

Why? Management of these KINDS of singletons gets too clouded when you factor in the following:

  • having to maintain seeded entities in xml
  • having to articulate other dependent annotations attributes to alter schema logic
  • having to worry about whether the seeded entity will instantiate based on what other
    foreign keys may prevent it from being instantiated
  • other schematic dependencies based on foreign key

It is better to nail one pojo down as singleton and then it is easier to operate is as an ASO in tapestry or the entity could be operated implicitly as a back end kind of ASO whereby tapestry/hivemind would no longer be needed and the app could just refer to the getInstance(...).

It seems I am leading to Singleton PropertyEditor which might turn out to be a sub-spinnoff from HARD OneToOne property editor but only on the back side of it's logic. It seems like it would behave just like the HARD OneToOne but the back end would mandate only one entity.

So upon completion of the annotation, we could decorate based on this condition and/or add an attribute to the existing OneToOne that would aritculate OneToOne.HARD or OneToOne.SOFT



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Kalle Korhonen added a comment - 11/Jul/07 03:05 AM
I still fail to see any benefit in this annotation. You certainly don't have maintain seeded entities in xml - it's simply one way to seed the database. I have no idea what "having to articulate other dependent annotations attributes to alter schema logic" means. ASOs are not connected to persistent entities. If you just want a single entity, make it's id property always return a static value. If you want a true singleton, implement a static class/method that'll always return a single instance, with values populated either from database using getInstance, XML or in Spring configuration.

Ken in nashua added a comment - 12/Jul/07 05:21 PM
Decided to seed an entity which initially has ID=1

Then make it an ASO and load the ASO off of ID=1

The ASO itself is prevented from replicating itself by making an one of the property fields unique.


Ken in nashua added a comment - 04/Oct/07 04:06 PM
Wanted to offer the actual solution here... a singleton ASO loaded at bootstrap. Not my idea of a pure singleton... but you get the idea.

The solution is based on a pojo named AdminLayout (not provided but you can use your own).

ApplicationContext-seedData.XML
<bean id="adminLayout" class="org.trails.demo.AdminLayout"
lazy-init="true"/>

AdminLayoutFactory.JAVA
public class AdminLayoutFactory implements StateObjectFactory
{
private AdminLayoutDAO layoutDao;

public Object createStateObject()

{ return (AdminLayout) layoutDao.loadSingleton(); }

public void setLayoutDao(AdminLayoutDAO adminLayoutDao)

{ this.layoutDao = adminLayoutDao; }

}

AdminLayoutDAO.JAVA
public class AdminLayoutDAO
{
HibernatePersistenceService persistenceService;

AdminLayout layout = null;

public AdminLayout loadSingleton() throws DataAccessException

{ DetachedCriteria criteria = DetachedCriteria.forClass(AdminLayout.class); criteria.add(Restrictions.eq("id", 1)); layout = persistenceService.getInstance(AdminLayout.class, criteria); return layout; }

public AdminLayout getLayout()

{ return layout; }

public void setLayout(AdminLayout layout)

{ this.layout = layout; }

public HibernatePersistenceService getPersistenceService()

{ return persistenceService; }

public void setPersistenceService(HibernatePersistenceService persistenceService)

{ this.persistenceService = persistenceService; }

}


Ken in nashua added a comment - 04/Oct/07 04:23 PM
<service-point id="adminLayoutFactory" interface="org.apache.tapestry.engine.state.StateObjectFactory">
<invoke-factory>
<construct class="org.trails.demo.service.AdminLayoutFactory">
<set-object property="layoutDao" value="spring:adminLayoutDAO"/>
</construct>
</invoke-factory>
</service-point>