SessionImpl sessionImpl = (SessionImpl) session; Connection conn = sessionImpl.connection();
SessionImpl sessionImpl = (SessionImpl) session; Connection conn = sessionImpl.connection();
SessionImpl sessionImpl = (SessionImpl) session; Connection conn = sessionImpl.connection();
SessionImpl sessionImpl = (SessionImpl) session; Connection conn = sessionImpl.connection();
String v_param_1 = "param_1"; SessionImpl session = (SessionImpl) sessionFactory.openSession(); CallableStatement callableStatement = session.connection().prepareCall("call P_MYSTORE(?,?)"); callableStatement.setString(1, v_param_1); callableStatement.registerOutParameter(2, OracleTypes.VARCHAR); callableStatement.execute(); //get out param from store String v_param_2 = callableStatement.getString(2);
@Override public Connection getConnection() { SessionImpl session = (SessionImpl)entityManager.unwrap(Session.class); return session.connection(); }
public Session getCurrentSession(String schema) { Session session = getSessionFactory().getCurrentSession(); if (StringUtils.isNotEmpty(schema)) { SessionImpl sessionImpl = (SessionImpl) session; try { String currentSchema = sessionImpl.connection().getSchema(); if (!schema.equals(currentSchema)) { sessionImpl.connection().setSchema(schema); CoreResources.tenantSchema.set(schema); //CoreResources.setSchema(sessionImpl.connection()); } } catch (SQLException e) { logger.error(e.getMessage(), e); } } return session; }
public void commitAndContinue() { try { session.flush(); SessionImpl sessionImpl = (SessionImpl) session; Connection c = sessionImpl.connection(); c.commit(); if (!c.getAutoCommit()) { c.setAutoCommit(false); } } catch (SQLException e) { throw new SingularFlowException(e); } }
public void commitAndContinue() { try { session.flush(); SessionImpl sessionImpl = (SessionImpl) session; Connection c = sessionImpl.connection(); c.commit(); if (!c.getAutoCommit()) { c.setAutoCommit(false); } } catch (SQLException e) { throw new SingularFlowException(e); } }
@Override public Connection getConnection() { SessionImpl session = (SessionImpl)entityManager.unwrap(Session.class); return session.connection(); }
public void commitAndContinue() { try { session.flush(); SessionImpl sessionImpl = (SessionImpl) session; Connection c = sessionImpl.connection(); c.commit(); if (!c.getAutoCommit()) { c.setAutoCommit(false); } } catch (SQLException e) { throw new SingularFlowException(e); } }
public void setConnectionSchemaName(String schemaName) throws Exception { ((SessionImpl) getCurrentSession()).connection().setSchema(schemaName); CoreResources.setRequestSchema(schemaName); CoreResources.tenantSchema.set(schemaName); } }
String currentSchema = sessionImpl.connection().getSchema(); if (!tenant.equals(currentSchema)) { sessionImpl.connection().setSchema(tenant); if (StringUtils.isNotEmpty(schema)) { try { sessionImpl.connection().setSchema(schema); } catch (SQLException e) { logger.error(e.getMessage(), e);
Connection c = ((SessionImpl) em.getDelegate()).connection(); Statement s = c.createStatement(); s.execute("SET DATABASE REFERENTIAL INTEGRITY FALSE");
/** * unfortunately there is no standard way to get jdbc connection from JPA entity manager * * @return JDBC connection */ private Connection createConnection() { try { EntityTransaction tx = this.em.getTransaction(); if (isHibernatePresentOnClasspath() && em.getDelegate() instanceof Session) { connection = ((SessionImpl) em.unwrap(Session.class)).connection(); } else { /** * see here:http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager */ tx.begin(); connection = em.unwrap(Connection.class); tx.commit(); } } catch (Exception e) { throw new RuntimeException("Could not create database connection", e); } return connection; }
private void init(String unitName) { if (emf == null) { log.debug("creating emf for unit {}", unitName); Map<String,String> dbConfig = getDbPropertyConfig(); log.debug("using dbConfig '{}' to create emf", dbConfig); emf = dbConfig == null ? Persistence.createEntityManagerFactory(unitName) : Persistence.createEntityManagerFactory(unitName, dbConfig); em = emf.createEntityManager(); tx = em.getTransaction(); if (isHibernateOnClasspath() && em.getDelegate() instanceof Session) { conn = ((SessionImpl) em.unwrap(Session.class)).connection(); } else{ /** * see here:http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager */ tx.begin(); conn = em.unwrap(Connection.class); tx.commit(); } } emf.getCache().evictAll(); }
@Test public void testTableInitialization() throws SQLException { Connection c = ((SessionImpl) DBManager.getInstance().getCurrentEntityManager().getDelegate()).connection(); Statement s = c.createStatement(); Set<String> tables = new LinkedHashSet<>(); ResultSet rs = s.executeQuery("select table_name " + "from INFORMATION_SCHEMA.system_tables " + "where table_type='TABLE' and table_schem='PUBLIC'"); while (rs.next()) { if (!rs.getString(1).startsWith("DUAL_")) { tables.add(rs.getString(1)); } } rs.close(); s.close(); Assert.assertTrue(tables.contains("KVPair_table".toUpperCase())); }
@Test public void testDirectSQLInsertFollowedByClear() throws SQLException { String tableName = "KVPair_table"; Connection c = ((SessionImpl) DBManager.getInstance().getCurrentEntityManager().getDelegate()).connection(); Statement s = c.createStatement(); ResultSet rs = null; s.executeUpdate("INSERT INTO KVPair_table VALUES 'a', 'b'"); rs = s.executeQuery("SELECT * from "+tableName); Assert.assertTrue(rs.next()); rs.close(); s.close(); DBManager.getInstance().clearDatabase(); s = c.createStatement(); rs = s.executeQuery("SELECT * from " + tableName); Assert.assertFalse(rs.next()); // no data rs.close(); s.close(); }
@Test public void testDirectSQLModifications() throws SQLException { String tableName = "KVPair_table"; Connection c = ((SessionImpl) DBManager.getInstance().getCurrentEntityManager().getDelegate()).connection(); Statement s = c.createStatement(); ResultSet rs = s.executeQuery("select * from "+tableName); Assert.assertFalse(rs.next()); // no data rs.close(); s.executeUpdate("INSERT INTO KVPair_table VALUES 'a', 'b'"); rs = s.executeQuery("SELECT * from "+tableName); Assert.assertTrue(rs.next()); String a = rs.getString(1); String b = rs.getString(2); rs.close(); Assert.assertEquals("a", a); Assert.assertEquals("b", b); s.executeUpdate("DELETE from " + tableName); rs = s.executeQuery("select * from "+tableName); Assert.assertFalse(rs.next()); // no data s.close(); }
/** * Open a connection for the current thread. * * @param name * Name of the DB * @return A valid SQL connection */ public static Connection getConnection(String name) { try { if (JPA.isEnabled()) { return ((SessionImpl) ((HibernateEntityManager) JPA.em(name)).getSession()).connection(); } Connection localConnection = getLocalConnection(name); if (localConnection != null) { return localConnection; } // We have no connection Connection connection = getDataSource(name).getConnection(); registerLocalConnection(name, connection); return connection; } catch (NullPointerException e) { if (getDataSource(name) == null) { throw new DatabaseException("No database found. Check the configuration of your application.", e); } throw e; } catch (Exception e) { // Exception throw new DatabaseException(e.getMessage()); } }