/** * Return a specified persistence unit for the given unit name, * as defined through the "persistenceUnits" map. * @param unitName the name of the persistence unit * @return the corresponding EntityManagerFactory, * or {@code null} if none found * @see #setPersistenceUnits */ @Nullable protected EntityManagerFactory getPersistenceUnit(@Nullable String unitName) { if (this.persistenceUnits != null) { String unitNameForLookup = (unitName != null ? unitName : ""); if (unitNameForLookup.isEmpty()) { unitNameForLookup = this.defaultPersistenceUnitName; } String jndiName = this.persistenceUnits.get(unitNameForLookup); if (jndiName == null && "".equals(unitNameForLookup) && this.persistenceUnits.size() == 1) { jndiName = this.persistenceUnits.values().iterator().next(); } if (jndiName != null) { try { return lookup(jndiName, EntityManagerFactory.class); } catch (Exception ex) { throw new IllegalStateException("Could not obtain EntityManagerFactory [" + jndiName + "] from JNDI", ex); } } } return null; }
return lookup(jndiName, EntityManager.class);
/** * Return a specified persistence unit for the given unit name, * as defined through the "persistenceUnits" map. * @param unitName the name of the persistence unit * @return the corresponding EntityManagerFactory, * or {@code null} if none found * @see #setPersistenceUnits */ @Nullable protected EntityManagerFactory getPersistenceUnit(@Nullable String unitName) { if (this.persistenceUnits != null) { String unitNameForLookup = (unitName != null ? unitName : ""); if (unitNameForLookup.isEmpty()) { unitNameForLookup = this.defaultPersistenceUnitName; } String jndiName = this.persistenceUnits.get(unitNameForLookup); if (jndiName == null && "".equals(unitNameForLookup) && this.persistenceUnits.size() == 1) { jndiName = this.persistenceUnits.values().iterator().next(); } if (jndiName != null) { try { return lookup(jndiName, EntityManagerFactory.class); } catch (Exception ex) { throw new IllegalStateException("Could not obtain EntityManagerFactory [" + jndiName + "] from JNDI", ex); } } } return null; }
return lookup(jndiName, EntityManager.class);
return lookup(jndiName, EntityManager.class);
/** * Return a specified persistence unit for the given unit name, * as defined through the "persistenceUnits" map. * @param unitName the name of the persistence unit * @return the corresponding EntityManagerFactory, * or {@code null} if none found * @see #setPersistenceUnits */ @Nullable protected EntityManagerFactory getPersistenceUnit(@Nullable String unitName) { if (this.persistenceUnits != null) { String unitNameForLookup = (unitName != null ? unitName : ""); if (unitNameForLookup.isEmpty()) { unitNameForLookup = this.defaultPersistenceUnitName; } String jndiName = this.persistenceUnits.get(unitNameForLookup); if (jndiName == null && "".equals(unitNameForLookup) && this.persistenceUnits.size() == 1) { jndiName = this.persistenceUnits.values().iterator().next(); } if (jndiName != null) { try { return lookup(jndiName, EntityManagerFactory.class); } catch (Exception ex) { throw new IllegalStateException("Could not obtain EntityManagerFactory [" + jndiName + "] from JNDI", ex); } } } return null; }