<commit_before>/*******************************************************************************
 * Copyright (c) 2012-2016 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.api.core.jdbc.jpa.eclipselink;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Singleton;

import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.internal.sessions.cdi.EntityListenerInjectionManager;

import javax.naming.NamingException;

/**
 * Allows to use dependency injection in entity listeners.
 *
 * <p>Example:
 * <pre>
 * class WorkspaceEntityListener {
 *
 *      &#064;Inject EventBus bus; <- EventBus will be injected by Guice
 *
 *      &#064;PreRemove
 *      public void preRemove(Workspace workspace) {
 *          bus.post(new BeforeWorkspaceRemovedEvent(workspace));
 *      }
 * }
 *
 * &#064;Entity
 * &#064;EntityListeners(WorkspaceEntityListener.class)
 * class Workspace {
 *      // ...
 * }
 * </pre>
 *
 * @author <NAME>
 */
@Singleton
public class GuiceEntityListenerInjectionManager implements EntityListenerInjectionManager {

    @Inject
    private Injector injector;

    @Override
    public Object createEntityListenerAndInjectDependancies(Class entityListenerClass) throws NamingException {
        try {
            return injector.getInstance(entityListenerClass);
        } catch (RuntimeException x) {<commit_msg>Initialize Jpa before EntityListenerInjectionManager<commit_after>/*******************************************************************************
 * Copyright (c) 2012-2016 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   <NAME>. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.api.core.jdbc.jpa.eclipselink;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Singleton;

import org.eclipse.che.api.core.jdbc.jpa.guice.JpaInitializer;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.internal.sessions.cdi.EntityListenerInjectionManager;

import javax.naming.NamingException;

/**
 * Allows to use dependency injection in entity listeners.
 *
 * <p>Example:
 * <pre>
 * class WorkspaceEntityListener {
 *
 *      &#064;Inject EventBus bus; <- EventBus will be injected by Guice
 *
 *      &#064;PreRemove
 *      public void preRemove(Workspace workspace) {
 *          bus.post(new BeforeWorkspaceRemovedEvent(workspace));
 *      }
 * }
 *
 * &#064;Entity
 * &#064;EntityListeners(WorkspaceEntityListener.class)
 * class Workspace {
 *      // ...
 * }
 * </pre>
 *
 * @author <NAME>
 */
@Singleton
public class GuiceEntityListenerInjectionManager implements EntityListenerInjectionManager {

    @Inject
    private JpaInitializer jpaInitializer;

    @Inject
    private Injector injector;

    @Override
    public Object createEntityListenerAndInjectDependancies(Class entityListenerClass) throws NamingException {
        try {
            return injector.getInstance(entityListenerClass);
        } catch (RuntimeException x) {
{'fraction_non_alphanumeric': 0.17492012779552715, 'fraction_numerical': 0.012779552715654952, 'mean_word_length': 4.329078014184397, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6822583', 'n_tokens_mistral': 1036, 'n_tokens_neox': 994, 'n_words': 238}