Java PersistenceContext类代码示例(javax.persistence.persistencecontext典型用法代码示例汇总)

本文整理汇总了Java中javax.persistence.PersistenceContext的典型用法代码示例。如果您正苦于以下问题:Java PersistenceContext类的具体用法?Java PersistenceContext怎么用?Java PersistenceContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Java PersistenceContext类代码示例(javax.persistence.persistencecontext典型用法代码示例汇总)

PersistenceContext类属于javax.persistence包,在下文中一共展示了PersistenceContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: loadDiscountRate

import javax.persistence.PersistenceContext; //导入依赖的package包/类
@PersistenceContext
public static void loadDiscountRate(EntityManager entityManager){
    DiscountRate dr1 = new DiscountRate('H');
    DiscountRate dr2 = new DiscountRate('M');
    DiscountRate dr3 = new DiscountRate('L');
    DiscountRate dr4 = new DiscountRate('N');
    
    dr1.setRate(0.08);
    dr2.setRate(0.04);
    dr3.setRate(0.02);
    dr4.setRate(0.00);
    
    entityManager.persist(dr1);
    entityManager.persist(dr2);
    entityManager.persist(dr3);
    entityManager.persist(dr4);
} 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:18,代码来源:DataAppLoader.java

示例2: loadRole

import javax.persistence.PersistenceContext; //导入依赖的package包/类
@PersistenceContext
public static void loadRole(EntityManager entityManager) {
    Role r = new Role('E');
    r.setDescription("Sales Executive, National");
    entityManager.persist(r);
    
    r = new Role('D');
    r.setDescription("District Manager");
    entityManager.persist(r);
    
    r = new Role('T');
    r.setDescription("Sales, Territory");
    entityManager.persist(r);
    
    r = new Role('A');
    r.setDescription("Sales, Associate");
    entityManager.persist(r);
} 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:DataAppLoader.java

示例3: decorateContext

import javax.persistence.PersistenceContext; //导入依赖的package包/类
private <X> AnnotatedField<X> decorateContext(AnnotatedField<X> field) {
    final PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
    final UniqueIdentifier identifier = UniqueIdentifierLitteral.random();

    Set<Annotation> templateQualifiers = new HashSet<>();
    templateQualifiers.add(ServiceLiteral.SERVICE);
    if (hasUnitName(persistenceContext)) {
        templateQualifiers.add(new FilterLiteral("(osgi.unit.name=" + persistenceContext.unitName() + ")"));
    }
    Bean<JpaTemplate> bean = manager.getExtension(OsgiExtension.class)
            .globalDependency(JpaTemplate.class, templateQualifiers);

    Set<Annotation> qualifiers = new HashSet<>();
    qualifiers.add(identifier);
    Bean<EntityManager> b = new SimpleBean<>(EntityManager.class, Dependent.class, Collections.singleton(EntityManager.class), qualifiers, () -> {
        CreationalContext<JpaTemplate> context = manager.createCreationalContext(bean);
        JpaTemplate template = (JpaTemplate) manager.getReference(bean, JpaTemplate.class, context);
        return EntityManagerProducer.create(template);
    });
    beans.add(b);

    Set<Annotation> fieldAnnotations = new HashSet<>();
    fieldAnnotations.add(InjectLiteral.INJECT);
    fieldAnnotations.add(identifier);
    return new SyntheticAnnotatedField<>(field, fieldAnnotations);
} 
开发者ID:apache,项目名称:aries-jpa,代码行数:27,代码来源:PersistenceAnnotatedType.java

示例4: init

import javax.persistence.PersistenceContext; //导入依赖的package包/类
/**
 * Injects the {@code EntityManager} instance required to invoke our
 * transactional daos. The EntityManager instance can only be injected into
 * the Spring Beans, we cannot create a Spring Bean for the Committees EJB
 * otherwise.
 *
 * @param entityManager Spring controlled EntityManager instance
 */
@PersistenceContext
public void init(final EntityManager entityManager) {
    // Create the Notification Spy, and inject it
    final Notifications notitications = NotificationSpy.getInstance();
    final NotificationManagerScheduler notificationBean = new NotificationManagerScheduler();
    notificationBean.setNotifications(notitications);

    // Create a new SessionRequestBean instance with our entityManager
    final SessionRequestBean sessionRequestBean = new SessionRequestBean();
    sessionRequestBean.setEntityManager(entityManager);
    sessionRequestBean.setSettings(Beans.settings());
    sessionRequestBean.postConstruct();

    // Create an Committees EJB, and inject the EntityManager & Notification Spy
    final CommitteeBean committeeBean = new CommitteeBean();
    committeeBean.setEntityManager(entityManager);
    committeeBean.setNotificationManager(notificationBean);
    committeeBean.setSessionRequestBean(sessionRequestBean);
    committeeBean.setSettings(Beans.settings());
    committeeBean.postConstruct();

    // Set our Committees implementation to the Committees EJB,
    // running withing a "Spring Container".
    client = committeeBean;
} 
开发者ID:IWSDevelopers,项目名称:iws,代码行数:34,代码来源:CommitteeSpringClient.java

示例5: init

import javax.persistence.PersistenceContext; //导入依赖的package包/类
/**
 * Injects the {@code EntityManager} instance required to invoke our
 * transactional DAOs. The EntityManager instance can only be injected into
 * the Spring Beans, we cannot create a Spring Bean for the Exchange EJB
 * otherwise.
 *
 * @param entityManager Spring controlled EntityManager instance
 */
@PersistenceContext
public void init(final EntityManager entityManager) {
    // Create the Notification Spy, and inject it
    final Notifications notitications = NotificationSpy.getInstance();
    final NotificationManagerScheduler notificationBean = new NotificationManagerScheduler();
    notificationBean.setNotifications(notitications);

    // Create a new SessionRequestBean instance with our entityManager
    final SessionRequestBean sessionRequestBean = new SessionRequestBean();
    sessionRequestBean.setEntityManager(entityManager);
    sessionRequestBean.setSettings(Beans.settings());
    sessionRequestBean.postConstruct();

    // Create an Exchange EJB, and inject the EntityManager & Notification Spy
    final ExchangeBean exchangeBean = new ExchangeBean();
    exchangeBean.setEntityManager(entityManager);
    exchangeBean.setNotificationManager(notificationBean);
    exchangeBean.setSessionRequestBean(sessionRequestBean);
    exchangeBean.setSettings(Beans.settings());
    exchangeBean.postConstruct();

    // Set our Exchange implementation to the Exchange EJB, running within
    // a "Spring Container".
    client = exchangeBean;
} 
开发者ID:IWSDevelopers,项目名称:iws,代码行数:34,代码来源:ExchangeSpringClient.java

示例6: init

import javax.persistence.PersistenceContext; //导入依赖的package包/类
/**
 * Injects the {@code EntityManager} instance required to invoke our
 * transactional DAOs. The EntityManager instance can only be injected into
 * the Spring Beans, we cannot create a Spring Bean for the Access EJB
 * otherwise.
 *
 * @param entityManager Spring controlled EntityManager instance
 */
@PersistenceContext
public void init(final EntityManager entityManager) {
    // Create the Notification Spy, and inject it
    final Notifications notitications = NotificationSpy.getInstance();
    final NotificationManagerScheduler notificationBean = new NotificationManagerScheduler();
    notificationBean.setNotifications(notitications);

    // Create a new SessionRequestBean instance with our entityManager
    final SessionRequestBean sessionRequestBean = new SessionRequestBean();
    sessionRequestBean.setEntityManager(entityManager);
    sessionRequestBean.setSettings(Beans.settings());
    sessionRequestBean.postConstruct();

    // Create an Access EJB, and inject the EntityManager & Notification Spy
    final AccessBean accessBean = new AccessBean();
    accessBean.setEntityManager(entityManager);
    accessBean.setNotificationManager(notificationBean);
    accessBean.setSessionRequestBean(sessionRequestBean);
    accessBean.setSettings(Beans.settings());
    accessBean.postConstruct();

    // Set our Access implementation to the Access EJB, running within a
    // "Spring Container".
    client = accessBean;
} 
开发者ID:IWSDevelopers,项目名称:iws,代码行数:34,代码来源:AccessSpringClient.java

示例7: init

import javax.persistence.PersistenceContext; //导入依赖的package包/类
/**
 * Injects the {@code EntityManager} instance required to invoke our
 * transactional DAOs. The EntityManager instance can only be injected into
 * the Spring Beans, we cannot create a Spring Bean for the Committees EJB
 * otherwise.
 *
 * @param entityManager Spring controlled EntityManager instance
 */
@PersistenceContext
public void init(final EntityManager entityManager) {
    // Create the Notification Spy, and inject it
    final Notifications notifications = NotificationSpy.getInstance();
    final NotificationManagerScheduler notificationBean = new NotificationManagerScheduler();
    notificationBean.setNotifications(notifications);

    // Create a new SessionRequestBean instance with our entityManager
    final SessionRequestBean sessionRequestBean = new SessionRequestBean();
    sessionRequestBean.setEntityManager(entityManager);
    sessionRequestBean.setSettings(Beans.settings());
    sessionRequestBean.postConstruct();

    // Create an Committees EJB, and inject the EntityManager & Notification Spy
    final StorageBean storageBean = new StorageBean();
    storageBean.setEntityManager(entityManager);
    storageBean.setNotificationManager(notificationBean);
    storageBean.setSessionRequestBean(sessionRequestBean);
    storageBean.setSettings(Beans.settings());
    storageBean.postConstruct();

    // Set our Committees implementation to the Committees EJB,
    // running withing a "Spring Container".
    client = storageBean;
} 
开发者ID:IWSDevelopers,项目名称:iws,代码行数:34,代码来源:StorageSpringClient.java

示例8: init

import javax.persistence.PersistenceContext; //导入依赖的package包/类
/**
 * Injects the {@code EntityManager} instance required to invoke our
 * transactional DAOs. The EntityManager instance can only be injected into
 * the Spring Beans, we cannot create a Spring Bean for the Exchange EJB
 * otherwise.
 *
 * @param entityManager Spring controlled EntityManager instance
 */
@PersistenceContext
public void init(final EntityManager entityManager) {
    // Create the Notification Spy, and inject it
    final Notifications notitications = NotificationSpy.getInstance();
    final NotificationManagerScheduler notificationBean = new NotificationManagerScheduler();
    notificationBean.setNotifications(notitications);

    // Create a new SessionRequestBean instance with our entityManager
    final SessionRequestBean sessionRequestBean = new SessionRequestBean();
    sessionRequestBean.setEntityManager(entityManager);
    sessionRequestBean.setSettings(Beans.settings());
    sessionRequestBean.postConstruct();

    // Create an Exchange EJB, and inject the EntityManager & Notification Spy
    final StudentBean studentBean = new StudentBean();
    studentBean.setEntityManager(entityManager);
    studentBean.setNotificationManager(notificationBean);
    studentBean.setSessionRequestBean(sessionRequestBean);
    studentBean.setSettings(Beans.settings());
    studentBean.postConstruct();

    // Set our Exchange implementation to the Exchange EJB, running withing
    // a "Spring Container".
    client = studentBean;
} 
开发者ID:IWSDevelopers,项目名称:iws,代码行数:34,代码来源:StudentSpringClient.java

示例9: init

import javax.persistence.PersistenceContext; //导入依赖的package包/类
/**
 * Injects the {@code EntityManager} instance required to invoke our
 * transactional DAOs. The EntityManager instance can only be injected into
 * the Spring Beans, we cannot create a Spring Bean for the Administration
 * EJB otherwise.
 *
 * @param entityManager Spring controlled EntityManager instance
 */
@PersistenceContext
public void init(final EntityManager entityManager) {
    // Create the Notification Spy, and inject it
    final Notifications notitications = NotificationSpy.getInstance();
    final NotificationManagerScheduler notificationBean = new NotificationManagerScheduler();
    notificationBean.setNotifications(notitications);

    // Create a new SessionRequestBean instance with our entityManager
    final SessionRequestBean sessionRequestBean = new SessionRequestBean();
    sessionRequestBean.setEntityManager(entityManager);
    sessionRequestBean.setSettings(Beans.settings());
    sessionRequestBean.postConstruct();

    // Create an Administration EJB, and inject the EntityManager & Notification Spy
    final AdministrationBean administrationBean = new AdministrationBean();
    administrationBean.setEntityManager(entityManager);
    administrationBean.setNotificationManager(notificationBean);
    administrationBean.setSessionRequestBean(sessionRequestBean);
    administrationBean.setSettings(Beans.settings());
    administrationBean.postConstruct();

    // Set our Administration implementation to the Administration EJB,
    // running withing a "Spring Container".
    client = administrationBean;
} 
开发者ID:IWSDevelopers,项目名称:iws,代码行数:34,代码来源:AdministrationSpringClient.java

示例10: testClassWithPersistenceContextWithKonfiguredUnitNameSpecified

import javax.persistence.PersistenceContext; //导入依赖的package包/类
@Test
public void testClassWithPersistenceContextWithKonfiguredUnitNameSpecified() throws Exception {
    // GIVEN
    final JCodeModel jCodeModel = new JCodeModel();
    final JPackage jp = jCodeModel.rootPackage();
    final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
    final JFieldVar ruleField = jClass.field(JMod.PUBLIC, JpaUnitRule.class, "rule");
    ruleField.annotate(Rule.class);
    final JInvocation instance = JExpr._new(jCodeModel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()"));
    ruleField.init(instance);
    final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em");
    final JAnnotationUse jAnnotation = emField.annotate(PersistenceContext.class);
    jAnnotation.param("unitName", "test-unit-1");
    final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
    jMethod.annotate(Test.class);

    buildModel(testFolder.getRoot(), jCodeModel);
    compileModel(testFolder.getRoot());

    final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name());
    final BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(cut);

    final RunListener listener = mock(RunListener.class);
    final RunNotifier notifier = new RunNotifier();
    notifier.addListener(listener);

    // WHEN
    runner.run(notifier);

    // THEN
    final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class);
    verify(listener).testStarted(descriptionCaptor.capture());
    assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
    assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));

    verify(listener).testFinished(descriptionCaptor.capture());
    assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
    assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
} 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:40,代码来源:JpaUnitRuleTest.java

示例11: getPersistenceContextProperties

import javax.persistence.PersistenceContext; //导入依赖的package包/类
private static Map<String, Object> getPersistenceContextProperties(final PersistenceContext persistenceContext) {
    final Map<String, Object> properties = new HashMap<>();
    for (final PersistenceProperty property : persistenceContext.properties()) {
        String propertyValue = property.value();
        Matcher matcher = PROPERTY_PATTERN.matcher(propertyValue);

        while(matcher.find()) {
            String p = matcher.group();
            String systemProperty = p.substring(2, p.length() - 1);
            propertyValue = propertyValue.replace(p, System.getProperty(systemProperty, p));
        }

        properties.put(property.name(), propertyValue);
    }
    return properties;
} 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:17,代码来源:JpaUnitContext.java

示例12: generateModel

import javax.persistence.PersistenceContext; //导入依赖的package包/类
@BeforeClass
public static void generateModel() throws Exception {
    final JCodeModel jCodeModel = new JCodeModel();
    final JPackage jp = jCodeModel.rootPackage();
    final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
    JAnnotationUse jAnnotationUse = jClass.annotate(InitialDataSets.class);
    jAnnotationUse.param("value", "Script.file");
    jClass.annotate(Cleanup.class);
    final JFieldVar jField = jClass.field(JMod.PRIVATE, String.class, "testField");
    jField.annotate(PersistenceContext.class);
    final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
    jAnnotationUse = jMethod.annotate(InitialDataSets.class);
    jAnnotationUse.param("value", "InitialDataSets.file");
    jAnnotationUse = jMethod.annotate(ApplyScriptsAfter.class);
    jAnnotationUse.param("value", "ApplyScriptsAfter.file");

    buildModel(testFolder.getRoot(), jCodeModel);

    compileModel(testFolder.getRoot());

    cut = loadClass(testFolder.getRoot(), jClass.name());
} 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:23,代码来源:AnnotationInspectorTest.java

示例13: testFieldAnnotationInspection

import javax.persistence.PersistenceContext; //导入依赖的package包/类
@Test
public void testFieldAnnotationInspection() throws Exception {
    // GIVEN
    final Field field = cut.getDeclaredField("testField");
    final Method method = cut.getDeclaredMethod("testMethod");

    // WHEN
    final AnnotationInspector<PersistenceContext> ai = new AnnotationInspector<>(cut, PersistenceContext.class);

    // THEN
    assertThat(ai.fetchFromField(field), notNullValue());
    assertThat(ai.fetchFromMethod(method), nullValue());
    assertThat(ai.fetchUsingFirst(method), nullValue());
    assertThat(ai.fetchAll().size(), equalTo(1));
    assertThat(ai.getAnnotatedFields().size(), equalTo(1));
    assertThat(ai.getAnnotatedFields(), hasItem(field));
    assertThat(ai.getAnnotatedMethods().isEmpty(), equalTo(Boolean.TRUE));
    assertThat(ai.getAnnotationOnClassLevel(), nullValue());
    assertThat(ai.isDefinedOnField(field), equalTo(Boolean.TRUE));
    assertThat(ai.isDefinedOnAnyField(), equalTo(Boolean.TRUE));
    assertThat(ai.isDefinedOnMethod(method), equalTo(Boolean.FALSE));
    assertThat(ai.isDefinedOnAnyMethod(), equalTo(Boolean.FALSE));
    assertThat(ai.isDefinedOnClassLevel(), equalTo(Boolean.FALSE));
} 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:25,代码来源:AnnotationInspectorTest.java

示例14: inject

import javax.persistence.PersistenceContext; //导入依赖的package包/类
@Override
public void inject(Object result, Field field) {
    try {

        String unitName = field.getAnnotation(PersistenceContext.class).unitName();
        if (StringUtils.isEmpty(unitName))
            unitName = PersistenceUnitProvider.DEFAULT_DS;

        if (!field.getType().equals(EntityManager.class)) {

            log.error("Failed to create PersistenceContext, type of field is not a EntityManager");
            return;
        }

        EntityManager em = provider.getProvider().createEntityManager();

        field.setAccessible(true);
        field.set(result, em);
    } catch (Exception e) {

        log.error("Failed to create PersistenceContext", e);
    }
} 
开发者ID:jspare-projects,项目名称:jspare-container,代码行数:24,代码来源:PersistenceContextInjectStrategy.java

示例15: if

import javax.persistence.PersistenceContext; //导入依赖的package包/类
@Override
public ResourceReferenceFactory<EntityManager> registerPersistenceContextInjectionPoint
        (InjectionPoint injectionPoint) {

    PersistenceUnitHolder holder = PersistenceUnitHolder.getInstance();

    PersistenceContext pc = injectionPoint.getAnnotated().getAnnotation(PersistenceContext
            .class);
    String unitName = pc.unitName();

    if (unitName.isEmpty()) {

        unitName = holder.getDefaultUnitName();

        if (unitName.isEmpty()) {
            throw new NoDefaultPersistenceUnit();
        }
    }

    PersistenceWrapper wrapper = holder.getEntityManagerFactory(unitName);

    return new PersistenceContextResourceFactory(unitName, wrapper.getEntityManagerFactory(),
            wrapper.getTransactionType(), pc.synchronization());
} 
开发者ID:kumuluz,项目名称:kumuluzee,代码行数:25,代码来源:JpaService.java

本文标签属性:

示例:示例图

代码:代码生成器

java:java游戏

PersistenceContext:PersistenceContext

上一篇:C++ gamma_distribution类代码示例
下一篇:90后单身人数比例2022(2022年中国独居人口)(2022年中国90后单身人口数量为**2.2亿)

为您推荐