javax.persistence.EntityManager.getDelegate()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(309)

本文整理了Java中javax.persistence.EntityManager.getDelegate()方法的一些代码示例,展示了EntityManager.getDelegate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityManager.getDelegate()方法的具体详情如下:
包路径:javax.persistence.EntityManager
类名称:EntityManager
方法名:getDelegate

EntityManager.getDelegate介绍

[英]Return the underlying provider object for the EntityManager, if available. The result of this method is implementation specific. The unwrap method is to be preferred for new applications.
[中]返回EntityManager的基础提供程序对象(如果可用)。此方法的结果是特定于实现的。unwrap方法是新应用程序的首选方法。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testCanUnwrapAopProxy() {
  EntityManager em = entityManagerFactory.createEntityManager();
  EntityManager proxy = ProxyFactory.getProxy(EntityManager.class, new SingletonTargetSource(em));
  assertTrue(em instanceof org.hibernate.jpa.HibernateEntityManager);
  assertFalse(proxy instanceof org.hibernate.jpa.HibernateEntityManager);
  assertTrue(proxy.unwrap(org.hibernate.jpa.HibernateEntityManager.class) != null);
  assertSame(em, proxy.unwrap(org.hibernate.jpa.HibernateEntityManager.class));
  assertSame(em.getDelegate(), proxy.getDelegate());
}

代码示例来源:origin: hibernate/hibernate-orm

public static void main(String[] argv) {
  Map<String, String> configurationOverrides = new HashMap<String, String>();
  EntityManagerFactory emf = Persistence.createEntityManagerFactory( "ConsolePU", configurationOverrides );
  EntityManager entityManager = emf.createEntityManager();
  populateTestData( entityManager );
  entityManager.getTransaction().begin();
  Session sesion = (Session) entityManager.getDelegate();
  System.out.println(
      sesion.createQuery(
          "select e from org.hibernate.envers.demo.Person_versions e " +
              "where " +
              "e.originalId._revision.id =" +
              "(select max(e2.originalId._revision.id) " +
              "from org.hibernate.envers.demo.Person_versions e2 " +
              "where e.originalId.id = :p0) "
      )
          .setParameter( "p0", 1 )
          .list()
  );
  entityManager.getTransaction().commit();
  entityManager.close();
  emf.close();
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@Priority(10)
public void initData() {
  Session session = (Session) em.getDelegate();
  session.createSQLQuery( "DROP TABLE children" ).executeUpdate();
  session.createSQLQuery(

代码示例来源:origin: Impetus/Kundera

/**
 * Sets property of hbase client in form of String
 */
@Test
public void testUsingExternalStringProperty() throws IOException
{
  
    Map<String, Object> puPropertiesString = new HashMap<String, Object>();
    puPropertiesString.put(PersistenceProperties.KUNDERA_BATCH_SIZE, "10");
    em = emf.createEntityManager(puPropertiesString);
    Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
    Client client = clients.get(_PU);
    Assert.assertEquals(((HBaseClient) client).getBatchSize(), 10);
  }

代码示例来源:origin: Impetus/Kundera

@Test
public void test() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
{
  Map<String, Client<ESQuery>> clients = (Map<String, Client<ESQuery>>) em.getDelegate();
  ESClient client = (ESClient) clients.get(PERSISTENCE_UNIT);
  Field factoryField = client.getClass().getDeclaredField("factory");
  if (!factoryField.isAccessible())
  {
    factoryField.setAccessible(true);
  }
  ESClientFactory factory = (ESClientFactory) factoryField.get(client);
  Field propertyReader = ((ESClientFactory) factory).getClass().getSuperclass()
      .getDeclaredField("propertyReader");
  if (!propertyReader.isAccessible())
  {
    propertyReader.setAccessible(true);
  }
  ESClientPropertyReader readerInstance = (ESClientPropertyReader) propertyReader.get(factory);
  Properties props = readerInstance.getConnectionProperties();
  Assert.assertEquals("true", props.get("client.transport.sniff"));
  Assert.assertEquals("false", props.get("discovery.zen.ping.multicast.enabled"));
  Assert.assertEquals("true", props.get("discovery.zen.ping.unicast.enabled"));
  Assert.assertEquals("false", props.get("discovery.zen.multicast.enabled"));
  Assert.assertEquals("true", props.get("discovery.zen.unicast.enabled"));
}

代码示例来源:origin: Impetus/Kundera

private EntityManager createEM()
{
  EntityManager em = emf.createEntityManager();
  Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
  Client client = clients.get("ds_composite_pu");
  ((CassandraClientBase) client).setCqlVersion("3.0.0");
  return em;
}

代码示例来源:origin: Impetus/Kundera

/**
 * @param result
 * @param entityMetadata
 * @param em
 * @return
 */
private List onNativeCassResults(List result, EntityMetadata entityMetadata, EntityManager em) {
  Map<String, Client<Query>> clients = (Map<String, Client<Query>>) em.getDelegate();
  Client client = clients.get(entityMetadata.getPersistenceUnit());
  if((client.getClass().getSimpleName().equals("ThriftClient") || client.getClass().getSimpleName().equals("PelopsClient")
          || client.getClass().getSimpleName().equals("DSClient"))
          && Column.class.equals(result.get(0).getClass())) {
    int count = 0;
    for(Object column : result) {
      Map<Object, Object> valueMap = new HashMap<Object, Object>();
      valueMap.put(PropertyAccessorHelper.getObject(String.class, ((Column) column).getName()), PropertyAccessorHelper.getObject(Long.class, ((Column) column).getValue()));
      result.set(count, valueMap);
      count ++;
    }
         
      }
  return result;
}

代码示例来源:origin: Impetus/Kundera

/**
 * Sets property of hbase client in form of String.
 * 
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
@Test
public void testUsingExternalStringProperty() throws IOException
{
  Map<String, Object> puPropertiesString = new HashMap<String, Object>();
  puPropertiesString.put(PersistenceProperties.KUNDERA_BATCH_SIZE, "10");
  em = emf.createEntityManager(puPropertiesString);
  Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
  Client client = clients.get(HBASE_PU);
  Assert.assertEquals(((HBaseClient) client).getBatchSize(), 10);
}

代码示例来源:origin: Impetus/Kundera

@Test
public void onFilterOperation()
{
  init();
  Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
  Client client = clients.get("hbaseTest");
  Filter f/* = new QualifierFilter() */;
  f = new SingleColumnValueFilter("PERSON_NAME".getBytes(), "PERSON_NAME".getBytes(), CompareOp.EQUAL,
      "vivek".getBytes());
  ((HBaseClient) client).setFilter(f);
  em.clear();
  // find by without where clause.
  Query q = em.createQuery("Select p from " + PersonHBase.class.getSimpleName() + " p");
  List<PersonHBase> results = q.getResultList();
  Assert.assertNotNull(results);
  Assert.assertFalse(results.isEmpty());
  Assert.assertEquals(3, results.size());
}

代码示例来源:origin: Impetus/Kundera

/**
 * @throws java.lang.Exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
  emf = Persistence.createEntityManagerFactory(PU);
  em = emf.createEntityManager();
  Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
  client = (Neo4JClient) clients.get(PU);
}

代码示例来源:origin: Impetus/Kundera

EntityManager em = EMRepository.INSTANCE.getEM(sessionToken);
Map<String, Client<Query>> clients = (Map<String, Client<Query>>) em.getDelegate();
Client client = clients.get(persistenceUnit);

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testPropertiesForTransactionalEntityManager() {
  Properties props = new Properties();
  props.put("foo", "bar");
  EntityManager em = mock(EntityManager.class);
  given(mockEmf.createEntityManager(props)).willReturn(em);
  given(em.getDelegate()).willReturn(new Object());
  given(em.isOpen()).willReturn(true);
  PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor();
  DefaultPrivatePersistenceContextFieldWithProperties transactionalField =
      new DefaultPrivatePersistenceContextFieldWithProperties();
  pabpp.postProcessProperties(null, transactionalField, "bean");
  assertNotNull(transactionalField.em);
  assertNotNull(transactionalField.em.getDelegate());
  verify(em).close();
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@Priority(10)
public void initData() {
  Session session = (Session) em.getDelegate();
  session.createSQLQuery( "DROP TABLE children" ).executeUpdate();
  session

代码示例来源:origin: Impetus/Kundera

@Before
public void setUp() throws Exception
{
  emf = Persistence.createEntityManagerFactory(persistenceUnit);
  em = emf.createEntityManager();
  
  em.getDelegate();
  
}

代码示例来源:origin: Impetus/Kundera

@Test
@PerfTest(invocations = 10)
public void testCRUD()
{
  logger.info("On testInsert");
  EntityManager em = emf.createEntityManager();
  Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
  RedisClient client = (RedisClient) clients.get(REDIS_PU);
  onInsert(client);
  onUpdate(client);
  onDelete(client);
  em.close();
}

代码示例来源:origin: Impetus/Kundera

@Test
public void testPopulateClientProperties()
{
  Map props = new HashMap();
  props.put("core.test.property", "core-test-property-value");
  PersistenceDelegator pd = ((EntityManagerImpl) em).getPersistenceDelegator();
  pd.populateClientProperties(props);
  Map map = em.getProperties();
  Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
  CoreTestClient client = (CoreTestClient) clients.get("kunderatest");
  Assert.assertEquals("core-test-property-value", client.getCoreTestProperty());
}

代码示例来源:origin: Impetus/Kundera

/**
 * @throws java.lang.Exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
  emf = Persistence.createEntityManagerFactory(PU);
  
  kunderaMetadata = ((EntityManagerFactoryImpl)emf).getKunderaMetadataInstance();
  
  em = emf.createEntityManager();
  
  Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
  client = (Neo4JClient) clients.get(PU);
}

代码示例来源:origin: Impetus/Kundera

private void testCountResult()
{
  Map<String, Client> clientMap = (Map<String, Client>) entityManager.getDelegate();
  DSClient tc = (DSClient) clientMap.get(_PU);
  tc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);
  CQLTranslator translator = new CQLTranslator();
  String query = "select count(*) from "
      + translator.ensureCase(new StringBuilder(), "PERSON", false).toString();
  Query q = entityManager.createNativeQuery(query, PersonCassandra.class);
  List noOfRows = q.getResultList();
  Assert.assertEquals(new Long(4),noOfRows.get(0));
  entityManager.clear();
  q = entityManager.createNamedQuery("q");
  noOfRows = q.getResultList();
  Assert.assertEquals(4, noOfRows.size());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testPropertiesForSharedEntityManager2() {
  Properties props = new Properties();
  props.put("foo", "bar");
  EntityManager em = mock(EntityManager.class);
  // only one call made  - the first EM definition wins (in this case the one w/o the properties)
  given(mockEmf.createEntityManager()).willReturn(em);
  given(em.getDelegate()).willReturn(new Object(), 2);
  given(em.isOpen()).willReturn(true);
  PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor();
  DefaultPrivatePersistenceContextFieldWithProperties transactionalFieldWithProperties =
      new DefaultPrivatePersistenceContextFieldWithProperties();
  DefaultPrivatePersistenceContextField transactionalField = new DefaultPrivatePersistenceContextField();
  pabpp.postProcessProperties(null, transactionalFieldWithProperties, "bean1");
  pabpp.postProcessProperties(null, transactionalField, "bean2");
  assertNotNull(transactionalFieldWithProperties.em);
  assertNotNull(transactionalField.em);
  // the EM w/o properties will be created
  assertNotNull(transactionalField.em.getDelegate());
  // bind em to the thread now since it's created
  try {
    TransactionSynchronizationManager.bindResource(mockEmf, new EntityManagerHolder(em));
    assertNotNull(transactionalFieldWithProperties.em.getDelegate());
    verify(em).close();
  }
  finally {
    TransactionSynchronizationManager.unbindResource(mockEmf);
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@Priority(10)
public void initData() {
  Session session = (Session) em.getDelegate();
  session.createSQLQuery( "DROP TABLE children" ).executeUpdate();
  session

相关文章