@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()); }
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(); }
@Test @Priority(10) public void initData() { Session session = (Session) em.getDelegate(); session.createSQLQuery( "DROP TABLE children" ).executeUpdate(); session.createSQLQuery(
/** * 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); }
@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")); }
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; }
/** * @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; }
/** * 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); }
@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()); }
/** * @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); }
EntityManager em = EMRepository.INSTANCE.getEM(sessionToken); Map<String, Client<Query>> clients = (Map<String, Client<Query>>) em.getDelegate(); Client client = clients.get(persistenceUnit);
@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(); }
@Test @Priority(10) public void initData() { Session session = (Session) em.getDelegate(); session.createSQLQuery( "DROP TABLE children" ).executeUpdate(); session
@Before public void setUp() throws Exception { emf = Persistence.createEntityManagerFactory(persistenceUnit); em = emf.createEntityManager(); em.getDelegate(); }
@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(); }
@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()); }
/** * @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); }
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()); }
@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); } }
@Test @Priority(10) public void initData() { Session session = (Session) em.getDelegate(); session.createSQLQuery( "DROP TABLE children" ).executeUpdate(); session