Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2014 Tomas Rodriguez 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 com.github.talberto.easybeans.atg;
 
 import java.util.Map;
 
 import  javax.transaction.TransactionManager;
 
 
 import  atg.dtm.TransactionDemarcation;
 import  atg.dtm.TransactionDemarcationException;
 import  atg.nucleus.GenericService;
 

Author(s):
Tomas Rodriguez (rodriguez@progiweb.com)
 
 public class NucleusEntityManager extends GenericService implements EntityManager {
 
   protected Logger mLog = LoggerFactory.getLogger(this.getClass());
   protected Map<Class<?>, RepositoryBeanMapper<?>> mMapperForType = Maps.newConcurrentMap();
   protected TransactionManager mTransactionManager;
   
   @Override
   public <T> T find(Class<T> pTypeObject pPk) {
     .trace("Entering find");
     return findMapperFor(pType).find(pPk);
   }
 
   private <T> RepositoryBeanMapper<T> findMapperFor(Class<T> pType) {
     .trace("Entering findMapperFor({})"pType);
     // Look first in the map
     .debug("Looking for a RepositoryBeanMapper for the type {}"pType);
     @SuppressWarnings("unchecked")
     RepositoryBeanMapper<T> mapper = (RepositoryBeanMapper<T>) .get(pType);
     if(mapper == null) {
       .debug("RepositoryBeanMapper for type {} not found, creating one"pType);
       mapper = RepositoryBeanMapper.from(thispType);
       .put(pTypemapper);
     }
     return mapper;
   }
   
   @Override
   public <T> String create(T pBean) {
     .trace("Entering create");
     TransactionDemarcation td = new TransactionDemarcation();
     boolean rollback = true;
     try {
       td.begin(, TransactionDemarcation.REQUIRED);
       @SuppressWarnings("unchecked")
       Class<T> type = (Class<T>) pBean.getClass();
       String id = findMapperFor(type).create(pBean);
       rollback = false;
       return id;
     } catch (TransactionDemarcationException e) {
       throw new MappingException(e);
     } finally {
       try {
         td.end(rollback);
       } catch (TransactionDemarcationException e) {
         throw new MappingException(e);
       }
     }
   }
 
   @Override
   public <T> void update(T pBean) {
     .trace("Entering update");
     TransactionDemarcation td = new TransactionDemarcation();
     boolean rollback = true;
     try {
       td.begin(, TransactionDemarcation.REQUIRED);
       @SuppressWarnings("unchecked")
       Class<T> type = (Class<T>) pBean.getClass();
       findMapperFor(type).update(pBean);
       rollback = false;
     } catch (TransactionDemarcationException e) {
      throw new MappingException(e);
    } finally {
      try {
        td.end(rollback);
      } catch (TransactionDemarcationException e) {
        throw new MappingException(e);
      }
    }
  }

  

Returns:
the transactionManager
  public TransactionManager getTransactionManager() {
    return ;
  }

  

Parameters:
pTransactionManager the transactionManager to set
  public void setTransactionManager(TransactionManager pTransactionManager) {
     = pTransactionManager;
  }
  public <T> void delete(T pBean) {
    .trace("Entering delete");
    TransactionDemarcation td = new TransactionDemarcation();
    boolean rollback = true;
    try {
      td.begin(, TransactionDemarcation.REQUIRED);
      @SuppressWarnings("unchecked")
      Class<T> type = (Class<T>) pBean.getClass();
      findMapperFor(type).delete(pBean);
      rollback = false;
    } catch (TransactionDemarcationException e) {
      throw new MappingException(e);
    } finally {
      try {
        td.end(rollback);
      } catch (TransactionDemarcationException e) {
        throw new MappingException(e);
      }
    }
  }
New to GrepCode? Check out our FAQ X