<commit_before>package org.compass.gps.device.jpa.lifecycle;

import java.util.Iterator;
import java.util.Map;
import java.util.Vector;

import javax.persistence.EntityManagerFactory;

import oracle.toplink.essentials.descriptors.ClassDescriptor;
import oracle.toplink.essentials.descriptors.DescriptorEvent;
import oracle.toplink.essentials.descriptors.DescriptorEventListener;
import oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl;
import oracle.toplink.essentials.sessions.Session;

import org.compass.gps.device.jpa.AbstractDeviceJpaEntityListener;
import org.compass.gps.device.jpa.JpaGpsDevice;
import org.compass.gps.device.jpa.JpaGpsDeviceException;

public class TopLinkEssentialsJpaEntityLifecycleInjector implements JpaEntityLifecycleInjector {

    private class TopLinkEssentialsEventListener extends AbstractDeviceJpaEntityListener implements DescriptorEventListener {

        private JpaGpsDevice device;

        public TopLinkEssentialsEventListener(JpaGpsDevice device) {
            this.device = device;
        }
        
        @Override
        protected JpaGpsDevice getDevice() {
            return this.device;
        }
        
        public void postUpdate(DescriptorEvent event) {
            postUpdate(event.getObject());
        }

        public void postDelete(DescriptorEvent event) {
            postRemove(event.getObject());
        }

        public void postInsert(DescriptorEvent event) {
            postPersist(event.getObject());
        }

        // things we don't use

        public void aboutToDelete(DescriptorEvent event) {
        }

        public void aboutToInsert(DescriptorEvent event) {
        }

        public void aboutToUpdate(DescriptorEvent event) {
        }

        public boolean isOverriddenEvent(DescriptorEvent event, Vector eventManagers) {
            return false;
        }

        public void postBuild(DescriptorEvent event) {
        }

        public void postClone(DescriptorEvent event) {
        }

        public void postMerge(DescriptorEvent event) {
        }

        public void postRefresh(DescriptorEvent event) {
        }

        public void postWrite(DescriptorEvent event) {
        }

        public void preDelete(DescriptorEvent event) {
        }

        public void preInsert(DescriptorEvent event) {
        }

        public void prePersist(DescriptorEvent event) {
        }

        public void preRemove(DescriptorEvent event) {
        }

        public void preUpdate(DescriptorEvent event) {
        }

        public void preUpdateWithChanges(DescriptorEvent event) {
        }

        public void preWrite(DescriptorEvent event) {
        }
        
    }
    
    public void injectLifecycle(EntityManagerFactory entityManagerFactory, JpaGpsDevice device) throws JpaGpsDeviceException {
        EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) entityManagerFactory;
        Session session = emf.getServerSession();
        Map descriptors = session.getDescriptors();
        TopLinkEssentialsEventListener eventListener = new TopLinkEssentialsEventListener(device);
        for (Iterator it = descriptors.values().iterator(); it.hasNext();) {
            ClassDescriptor classDescriptor = (ClassDescriptor) it.next();
            classDescriptor.getDescriptorEventManager().addListener(eventListener);
        }
    }
}<commit_msg>more support for toplink essentials<commit_after>package org.compass.gps.device.jpa.lifecycle;

import java.util.Iterator;
import java.util.Map;
import java.util.Vector;

import javax.persistence.EntityManagerFactory;

import oracle.toplink.essentials.descriptors.ClassDescriptor;
import oracle.toplink.essentials.descriptors.DescriptorEvent;
import oracle.toplink.essentials.descriptors.DescriptorEventListener;
import oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl;
import oracle.toplink.essentials.sessions.Session;

import org.compass.gps.device.jpa.AbstractDeviceJpaEntityListener;
import org.compass.gps.device.jpa.JpaGpsDevice;
import org.compass.gps.device.jpa.JpaGpsDeviceException;
import org.compass.gps.CompassGpsInterfaceDevice;
import org.compass.core.impl.InternalCompass;

public class TopLinkEssentialsJpaEntityLifecycleInjector implements JpaEntityLifecycleInjector {

    private class TopLinkEssentialsEventListener extends AbstractDeviceJpaEntityListener implements DescriptorEventListener {

        private JpaGpsDevice device;

        public TopLinkEssentialsEventListener(JpaGpsDevice device) {
            this.device = device;
        }

        @Override
        protected JpaGpsDevice getDevice() {
            return this.device;
        }

        public void postUpdate(DescriptorEvent event) {
            postUpdate(event.getObject());
        }

        public void postDelete(DescriptorEvent event) {
            postRemove(event.getObject());
        }

        public void postInsert(DescriptorEvent event) {
            postPersist(event.getObject());
        }

        // things we don't use

        public void aboutToDelete(DescriptorEvent event) {
        }

        public void aboutToInsert(DescriptorEvent event) {
        }

        public void aboutToUpdate(DescriptorEvent event) {
        }

        public boolean isOverriddenEvent(DescriptorEvent event, Vector eventManagers) {
            return false;
        }

        public void postBuild(DescriptorEvent event) {
        }

        public void postClone(DescriptorEvent event) {
        }

        public void postMerge(DescriptorEvent event) {
        }

        public void postRefresh(DescriptorEvent event) {
        }

        public void postWrite(DescriptorEvent event) {
        }

        public void preDelete(DescriptorEvent event) {
        }

        public void preInsert(DescriptorEvent event) {
        }

        public void prePersist(DescriptorEvent event) {
        }

        public void preRemove(DescriptorEvent event) {
        }

        public void preUpdate(DescriptorEvent event) {
        }

        public void preUpdateWithChanges(DescriptorEvent event) {
        }

        public void preWrite(DescriptorEvent event) {
        }

    }

    public void injectLifecycle(EntityManagerFactory entityManagerFactory, JpaGpsDevice device) throws JpaGpsDeviceException {
        EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) entityManagerFactory;
        Session session = emf.getServerSession();
        Map descriptors = session.getDescriptors();
        TopLinkEssentialsEventListener eventListener = new TopLinkEssentialsEventListener(device);
        InternalCompass compass = (InternalCompass) ((CompassGpsInterfaceDevice) device.getGps()).getMirrorCompass();
        for (Iterator it = descriptors.values().iterator(); it.hasNext();) {
            ClassDescriptor classDescriptor = (ClassDescriptor) it.next();
            Class mappedClass = classDescriptor.getClass();
            if (compass.getMapping().getRootMappingByClass(mappedClass) != null) {
                classDescriptor.getDescriptorEventManager().addListener(eventListener);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07221833449965011, 'fraction_numerical': 0.00027991602519244227, 'mean_word_length': 2.9633943427620633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2021363', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1763, 'n_words': 361}