private static CompassSessionEventListener findCompassSessionEventListener(EntityManager em) throws CompassException { return findCompassSessionEventListener(((JpaEntityManager) NativeJpaHelper.extractNativeJpa(em)).getServerSession()); }
/** * @see org.seasar.framework.jpa.Dialect#getConnection(javax.persistence.EntityManager) */ public Connection getConnection(EntityManager em) { Object delegate = em.getDelegate(); JpaEntityManager eclipselinkEm = JpaEntityManager.class.cast(delegate); ServerSession session = eclipselinkEm.getServerSession(); return session.getLogin().getConnector().connect( new Properties(), session); }
/** * Returns the current Compass session associated with the {@link javax.persistence.EntityManager}. * Compass Session is associated with an Entity Manager when a transaction is started and removed when the * transaction commits/rollsback. * * <p>The session can be used to perform searches that needs to take into account current transactional changes * or to perform additional Compass operations that are not reflected by the mirroring feature. */ public static CompassSession getCurrentCompassSession(EntityManager em) { JpaEntityManager nativeEm = (JpaEntityManager) NativeJpaHelper.extractNativeJpa(em); return findCompassSessionEventListener(nativeEm.getServerSession()).getCurrentCompassSession(nativeEm.getUnitOfWork()); }
public EntityInformation[] locate(EntityManagerFactory entityManagerFactory, JpaGpsDevice device) throws JpaGpsDeviceException { CompassGpsInterfaceDevice gps = (CompassGpsInterfaceDevice) device.getGps(); JpaEntityManager entityManager = (JpaEntityManager) entityManagerFactory.createEntityManager(); Session session = entityManager.getServerSession(); entityManager.close(); ArrayList<EntityInformation> entitiesList = new ArrayList<EntityInformation>(); Map descriptors = session.getDescriptors(); for (Object o : descriptors.values()) { ClassDescriptor classDescriptor = (ClassDescriptor) o; String entityname = classDescriptor.getJavaClassName(); if (!gps.hasMappingForEntityForIndex((entityname))) { if (log.isDebugEnabled()) { log.debug("Entity [" + entityname + "] does not have compass mapping, filtering it out"); } continue; } if (shouldFilter(entityname, classDescriptor, device)) { continue; } Class<?> clazz = classDescriptor.getJavaClass(); ResourceMapping resourceMapping = gps.getMappingForEntityForIndex(entityname); EntityInformation entityInformation = new EntityInformation(clazz, classDescriptor.getAlias(), resourceMapping.getSubIndexHash().getSubIndexes()); entitiesList.add(entityInformation); if (log.isDebugEnabled()) { log.debug("Entity [" + entityname + "] will be indexed"); } } return entitiesList.toArray(new EntityInformation[entitiesList.size()]); }
public void removeLifecycle(EntityManagerFactory entityManagerFactory, JpaGpsDevice device) throws JpaGpsDeviceException { CompassGpsInterfaceDevice gps = (CompassGpsInterfaceDevice) device.getGps(); JpaEntityManager entityManager = (JpaEntityManager) entityManagerFactory.createEntityManager(); Session session = entityManager.getServerSession(); entityManager.close(); Map descriptors = session.getDescriptors(); for (Object o : descriptors.values()) { ClassDescriptor classDescriptor = (ClassDescriptor) o; Class mappedClass = classDescriptor.getJavaClass(); // if we have a parent class that is mapped in JPA and in Compass, then don't add an event listner // since we will add it to the parent descriptor and it will notify this class as well if (classDescriptor.isChildDescriptor()) { Class parentClass = classDescriptor.getInheritancePolicy().getParentDescriptor().getJavaClass(); if (gps.hasMappingForEntityForMirror(parentClass, Cascade.ALL)) { classDescriptor.getDescriptorEventManager().removeListener(dummyEventListener); continue; } } if (gps.hasMappingForEntityForMirror(mappedClass, Cascade.ALL)) { classDescriptor.getDescriptorEventManager().removeListener(eventListener); } } } }
public void injectLifecycle(EntityManagerFactory entityManagerFactory, JpaGpsDevice device) throws JpaGpsDeviceException { CompassGpsInterfaceDevice gps = (CompassGpsInterfaceDevice) device.getGps(); if (eventListener == null) { eventListener = new TopLinkEssentialsEventListener(device); } JpaEntityManager entityManager = (JpaEntityManager) entityManagerFactory.createEntityManager(); Session session = entityManager.getServerSession(); entityManager.close(); Map descriptors = session.getDescriptors(); for (Object o : descriptors.values()) { ClassDescriptor classDescriptor = (ClassDescriptor) o; Class mappedClass = classDescriptor.getJavaClass(); // if we have a parent class that is mapped in JPA and in Compass, then don't add an event listner // since we will add it to the parent descriptor and it will notify this class as well if (classDescriptor.isChildDescriptor()) { Class parentClass = classDescriptor.getInheritancePolicy().getParentDescriptor().getJavaClass(); if (gps.hasMappingForEntityForMirror(parentClass, Cascade.ALL)) { // we need to inject a dummy listener, just so it will kick in the listener notifications classDescriptor.getDescriptorEventManager().addListener(dummyEventListener); continue; } } if (gps.hasMappingForEntityForMirror(mappedClass, Cascade.ALL)) { classDescriptor.getDescriptorEventManager().addListener(eventListener); } } }