001    package org.tynamo.jpa.sample.pages;
002    
003    import org.tynamo.jpa.annotations.CommitAfter;
004    import org.tynamo.jpa.sample.domain.TestEntity;
005    import org.tynamo.jpa.sample.services.TestService;
006    import org.apache.tapestry5.annotations.Property;
007    import org.apache.tapestry5.ioc.annotations.Inject;
008    
009    import javax.persistence.EntityManager;
010    import java.util.Date;
011    import java.util.List;
012    
013    /** Start page of application sample. */
014    public class Index {
015    
016            @Inject private EntityManager em;
017            @Inject private TestService testService;
018            @Property private TestEntity testEntity;
019    
020            public Date getCurrentTime() {
021                    return new Date();
022            }
023    
024            @CommitAfter
025            public void onActionFromAddEntity() {
026                    TestEntity te = new TestEntity();
027                    te.setValue(new Date().getTime()+"");
028                    em.persist(te);
029            }
030    
031            public void onActionFromDelEntity(long id) {
032                    testService.removeTestEntity(id);
033            }
034    
035            public List<TestEntity> getEntities() {
036                    return em.createQuery("select e from TestEntity e").getResultList();
037            }
038    
039            public int getEntityCount() {
040                    return em.createQuery("select e from TestEntity e").getResultList().size();
041            }
042    }