0 Replies Latest reply: Oct 29, 2013 8:43 AM by ppssrr RSS

    coherence test

    ppssrr

      public class EntityPersistenceContainerService {

       

          private static Map<String, EntityPersistenceService<?>> persitenceContainer = new WeakHashMap<>(); 

          protected IDao dao ;

       

          public EntityPersistenceContainerService(){

             

          }

         

       

          /**

           *

           * @param t

           * @return

           * @throws Exception

           */

          public <T> boolean persist(T t) throws Exception {

              @SuppressWarnings("unchecked")

              Class<T> clazz = (Class<T>)t.getClass();

       

              EntityPersistenceService<T> persistService = getPersistService(clazz);

              return persistService.persist(t);

          }

       

          public <T> List<T> select(T t) throws Exception{

              @SuppressWarnings("unchecked")

              Class<T> clazz = (Class<T>)t.getClass();

             

              EntityPersistenceService<T> persistService = getPersistService(clazz);

              return persistService.select(t);

       

          }

         

       

          public <T> List<T> selectAll(Class<T> clazz) throws Exception{

              EntityPersistenceService<T> persistService = getPersistService(clazz);

              return persistService.selectAll();

          }

         

         

          public <T> List<T> select(SQLQuery<T> query)  throws Exception{

              EntityPersistenceService<T> persistService = getPersistService(query.getDomainClass());

             

              return persistService.queryBy(query);

          }

       

         

           <T> EntityPersistenceService<T> getPersistService(Class<T> clazz) throws Exception{

              EntityPersistenceService<?> persistService = persitenceContainer.get(clazz.getName());

              if (persistService != null

                  && clazz.getName().equals( persistService.getDomainClassName() )){

                 

                  @SuppressWarnings("unchecked")

                  EntityPersistenceService<T> persistenceService = (EntityPersistenceService<T>)persistService;

                  return persistenceService;

              }

              DomainMapping domainMapping = DomainMappingProcessor.processAnnotations( clazz );

              SQLStatementGenerator.generateStatment( domainMapping );

       

             

              EntityPersistenceService<T> persistenceService;

              if (domainMapping.isComposite()){

                  persistenceService = new EntityCompositePersistenceService<>(domainMapping,clazz,this);

              }

              else{

                  persistenceService = new EntityPersistenceService<>(domainMapping,clazz,this);

              }

              domainMapping.updateFields(clazz);

              persitenceContainer.put( clazz.getName(), persistenceService);

              return persistenceService;

             

          }

       

          public void setDao( IDao dao){

              this.dao = dao;

          }

       

      }