/** * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#getUserDomainMappingsInternal(java.lang.String, * java.lang.String) */ protected Collection<String> getUserDomainMappingsInternal(String user, String domain) throws RecipientRewriteTableException { if (mappings == null) { return null; } else { String maps = mappings.get(user + "@" + domain); if (maps != null) { return RecipientRewriteTableUtil.mappingToCollection(maps); } else { return null; } } }
/** * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#getAllMappingsInternal() */ protected Map<String, Collection<String>> getAllMappingsInternal() throws RecipientRewriteTableException { if (mappings != null && mappings.size() > 0) { Map<String, Collection<String>> mappingsNew = new HashMap<String, Collection<String>>(); Iterator<String> maps = mappings.keySet().iterator(); while (maps.hasNext()) { String key = maps.next(); mappingsNew.put(key, RecipientRewriteTableUtil.mappingToCollection(mappings.get(key).toString())); } return mappingsNew; } else { return null; } }
/** * @throws RecipientRewriteTableException * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#mapAddress(java.lang.String, * java.lang.String) */ protected Collection<String> getUserDomainMappingsInternal(String user, String domain) throws RecipientRewriteTableException { EntityManager entityManager = entityManagerFactory.createEntityManager(); final EntityTransaction transaction = entityManager.getTransaction(); try { transaction.begin(); List<JPARecipientRewrite> virtualUsers = entityManager.createNamedQuery("selectUserDomainMapping").setParameter("user", user).setParameter("domain", domain).getResultList(); transaction.commit(); if (virtualUsers.size() > 0) { return RecipientRewriteTableUtil.mappingToCollection(virtualUsers.get(0).getTargetAddress()); } } catch (PersistenceException e) { getLogger().debug("Failed to get user domain mappings", e); if (transaction.isActive()) { transaction.rollback(); } throw new RecipientRewriteTableException("Error while retrieve mappings", e); } finally { entityManager.close(); } return null; }
/** * @throws RecipientRewriteTableException * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#getAllMappingsInternal() */ protected Map<String, Collection<String>> getAllMappingsInternal() throws RecipientRewriteTableException { EntityManager entityManager = entityManagerFactory.createEntityManager(); final EntityTransaction transaction = entityManager.getTransaction(); Map<String, Collection<String>> mapping = new HashMap<String, Collection<String>>(); try { transaction.begin(); List<JPARecipientRewrite> virtualUsers = entityManager.createNamedQuery("selectAllMappings").getResultList(); transaction.commit(); for (JPARecipientRewrite virtualUser : virtualUsers) { mapping.put(virtualUser.getUser() + "@" + virtualUser.getDomain(), RecipientRewriteTableUtil.mappingToCollection(virtualUser.getTargetAddress())); } if (mapping.size() > 0) return mapping; } catch (PersistenceException e) { getLogger().debug("Failed to get all mappings", e); if (transaction.isActive()) { transaction.rollback(); } throw new RecipientRewriteTableException("Error while retrieve mappings", e); } finally { entityManager.close(); } return null; }