当前位置: 首页>>代码示例>>Java>>正文


Java Work类代码示例

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


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

示例1: initializeDatabase

import org.hibernate.jdbc.Work; //导入依赖的package包/类
@Before
public void initializeDatabase() {
	Session session = entityManager.unwrap(Session.class);
	session.doWork(new Work() {
		
		@Override
		public void execute(Connection connection) throws SQLException {
			try {
				File script = new File(getClass().getResource("/data.sql").getFile());
				RunScript.execute(connection, new FileReader(script));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
				throw new RuntimeException("Database initialize script error");
			}
		}
	});
}
 
开发者ID:joaquimsn,项目名称:query-search,代码行数:18,代码来源:BaseJpaTest.java

示例2: executeBatch

import org.hibernate.jdbc.Work; //导入依赖的package包/类
@Transactional(readOnly = false)
public void executeBatch(final String sql, final Object[]... parameters) {
    getSession().doWork(new Work() {

        public void execute(Connection connection) throws SQLException {
            connection.setAutoCommit(false);
            PreparedStatement stmt = connection.prepareStatement(sql);
            for (Object[] arr : parameters) {
                int i = 1;
                for (Object p : arr) {
                    stmt.setObject(i++, p);
                }
                stmt.addBatch();
            }
            stmt.executeBatch();
            connection.commit();
        }
    });
}
 
开发者ID:wolfboys,项目名称:opencron,代码行数:20,代码来源:HibernateDao.java

示例3: tableExists

import org.hibernate.jdbc.Work; //导入依赖的package包/类
public boolean tableExists(Session session, final String table)
{
	final ExtendedDialect locDialect = (ExtendedDialect) this.dialect;
	final Boolean[] hasTable = new Boolean[1];
	session.doWork(new Work()
	{

		@Override
		public void execute(Connection connection) throws SQLException
		{
			ResultSet tables = connection.getMetaData().getTables(null, defaultSchema,
				locDialect.getNameForMetadataQuery(table, false), new String[]{"TABLE"});
			try
			{
				hasTable[0] = tables.next();
			}
			finally
			{
				tables.close();
			}
		}
	});
	return hasTable[0];
}
 
开发者ID:equella,项目名称:Equella,代码行数:25,代码来源:HibernateMigrationHelper.java

示例4: initializeOrUpgradeSchema

import org.hibernate.jdbc.Work; //导入依赖的package包/类
/**
 * Initializes, or upgrades the current QuartzDesk database schema by
 * executing the specified list of SQL scripts.
 *
 * @param scriptUrls    the list of SQL scripts to execute.
 * @param schemaVersion the version of the schema after the specified SQL scripts have been applied.
 */
public void initializeOrUpgradeSchema( final List<URL> scriptUrls, final Version schemaVersion )
{
  Session session = getSessionFactory().getCurrentSession();
  session.doWork( new Work()
  {
    @Override
    public void execute( Connection connection )
        throws SQLException
    {
      DatabaseScriptExecutor scriptExecutor = new DatabaseScriptExecutor();
      scriptExecutor.addScriptUrls( scriptUrls );

      scriptExecutor.executeScripts( connection );

      SchemaUpdate schemaUpdate = new SchemaUpdate()
          .withMajor( schemaVersion.getMajor() )
          .withMinor( schemaVersion.getMinor() )
          .withMaintenance( schemaVersion.getMaintenance() )
          .withAppliedAt( Calendar.getInstance() );

      insertSchemaUpdate( schemaUpdate );
    }
  } );
}
 
开发者ID:quartzdesk,项目名称:quartzdesk-executor,代码行数:32,代码来源:DatabaseSchemaDao.java

示例5: listTables

import org.hibernate.jdbc.Work; //导入依赖的package包/类
/**
 * List tables from database
 */
private List<String> listTables(Session session) {
	final List<String> tables = new ArrayList<String>();
	final String[] tableTypes = {"TABLE"};
	final String[] tablePatterns = new String[]{"JBPM_%", "OKM_%", "DEFAULT_%", "VERSION_%", "jbpm_%", "okm_%", "default_%",
			"version_%"};

	session.doWork(new Work() {
		@Override
		public void execute(Connection con) throws SQLException {
			DatabaseMetaData md = con.getMetaData();

			for (String table : tablePatterns) {
				ResultSet rs = md.getTables(null, null, table, tableTypes);

				while (rs.next()) {
					tables.add(rs.getString(3));
				}

				rs.close();
			}
		}
	});

	return tables;
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:29,代码来源:DatabaseQueryServlet.java

示例6: insertSqlFile

import org.hibernate.jdbc.Work; //导入依赖的package包/类
/**
 * Executes the passed sql files on the EntityManager.
 *
 * @param entityManager
 *           the EntityManager
 * @param sqlScripts
 *           sql scripts to execute
 */
public static void insertSqlFile(EntityManager entityManager, final File... sqlScripts) {
   entityManager.unwrap(Session.class).doWork(new Work() {

      @Override
      public void execute(Connection connection) throws SQLException {
         // Setup database
         try {
            for (File file : sqlScripts) {
               LOGGER.debug("INSERTing {}", file.getAbsolutePath());
               Assume.assumeTrue("SQL-Script not found", file.isFile());
               String sql = Resources.toString(file.toURI().toURL(), Charsets.UTF_8);
               executeSqlScript(connection, file.getName(), sql);
               LOGGER.debug("INSERTing {} ... done", file.getAbsolutePath());
            }
         } catch (IOException | ScriptException e) {
            throw new SQLException(e);
         }
      }
   });
}
 
开发者ID:kaiwinter,项目名称:testcontainers-examples,代码行数:29,代码来源:DockerDatabaseTestUtil.java

示例7: insertSqlString

import org.hibernate.jdbc.Work; //导入依赖的package包/类
/**
 * Executes the passed sql queries on the EntityManager.
 *
 * @param entityManager
 *           the EntityManager
 *
 * @param sqlQuery
 *           queries to execute
 */
public static void insertSqlString(EntityManager entityManager, final String... sqlQuery) {
   entityManager.unwrap(Session.class).doWork(new Work() {

      @Override
      public void execute(Connection connection) throws SQLException {
         // Setup database
         try {
            for (String query : sqlQuery) {
               LOGGER.debug("INSERTing '{}'", query);
               executeSqlScript(connection, null, query);
               LOGGER.debug("INSERTing '{}' ... done", query);
            }
         } catch (ScriptException e) {
            throw new SQLException(e);
         }
      }
   });
}
 
开发者ID:kaiwinter,项目名称:testcontainers-examples,代码行数:28,代码来源:DockerDatabaseTestUtil.java

示例8: insertDbUnitTestdata

import org.hibernate.jdbc.Work; //导入依赖的package包/类
/**
 * Inserts test data in DbUnit XML format.
 *
 * @param entityManager
 *           the EntityManager
 * @param dbUnitTestdata
 *           test file stream
 */
public static void insertDbUnitTestdata(EntityManager entityManager, final InputStream dbUnitTestdata) {

   entityManager.unwrap(Session.class).doWork(new Work() {

      @Override
      public void execute(Connection connection) throws SQLException {
         // Insert Testdata
         try {
            LOGGER.debug("INSERTing testdata");
            DatabaseConnection databaseConnection = new DatabaseConnection(connection);
            databaseConnection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
               new MySqlDataTypeFactory());

            FlatXmlDataSet dataSet = new FlatXmlDataSet(
               new FlatXmlProducer(new InputSource(dbUnitTestdata), false, true));
            DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, dataSet);
            LOGGER.debug("INSERTing testdata ... done");
         } catch (DatabaseUnitException e) {
            throw new SQLException(e);
         }
      }

   });
}
 
开发者ID:kaiwinter,项目名称:testcontainers-examples,代码行数:33,代码来源:DockerDatabaseTestUtil.java

示例9: beginTransaction

import org.hibernate.jdbc.Work; //导入依赖的package包/类
@Override
 public Object beginTransaction(final EntityManager entityManager, 
 		final TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException {
 	
 	Session session = (Session) entityManager.getDelegate();
 	if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
 		getSession(entityManager).getTransaction().setTimeout(definition.getTimeout());
 	}
 	entityManager.getTransaction().begin();
 	logger.debug("Transaction started");
 	session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
	 logger.debug("The connection instance is " + connection.toString());
	 logger.debug("The isolation level of the connection is " + connection.getTransactionIsolation() 
			 + " and the isolation level set on the transaction is " + definition.getIsolationLevel() );
	 DataSourceUtils.prepareConnectionForTransaction(connection, definition);
}
 	});
 	return prepareTransaction(entityManager, definition.isReadOnly(), definition.getName());
 }
 
开发者ID:billchen198318,项目名称:bamboobsc,代码行数:22,代码来源:HibernateExtendedJpaDialect.java

示例10: testTablesAndSequences

import org.hibernate.jdbc.Work; //导入依赖的package包/类
/**
 * <p>Check table and sequence naming. Important because sequence handling is customized through
 * {@link PerTableSequenceStyleGenerator} and {@link PerTableSequenceStrategyProvider}.</p>
 * 
 * <p>We check that {@link Person} entity creates a {@code person} table and a {@code person_id_seq} sequence.</p>
 */
@Test
public void testTablesAndSequences() {
	EntityManager entityManager = entityManagerUtils.getEntityManager();
	((Session) entityManager.getDelegate()).doWork(new Work() {
		@Override
		public void execute(Connection connection) throws SQLException {
			String expectedTableName = Person.class.getSimpleName().toLowerCase(); // person
			String expectedSequenceName = expectedTableName + "_id_seq"; // person_id_seq
			
			JdbcRelation table = getRelation(connection, configurationProvider.getDefaultSchema(),
					expectedTableName, JdbcDatabaseMetaDataConstants.REL_TYPE_TABLE);
			Assert.assertEquals(expectedTableName, table.getTable_name());
			
			JdbcRelation sequence = getRelation(connection, configurationProvider.getDefaultSchema(),
					expectedSequenceName, JdbcDatabaseMetaDataConstants.REL_TYPE_SEQUENCE);
			Assert.assertEquals(expectedSequenceName, sequence.getTable_name());
		}
	});
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:26,代码来源:TestMetaModel.java

示例11: openSession

import org.hibernate.jdbc.Work; //导入依赖的package包/类
@Test
public void openSession() throws Exception {
	createSessionFactory();
	//
	Session session = sessionFactory.openSession();
	session.doWork(new Work() {
		public void execute(Connection connection) throws SQLException {
			System.out.println("connection: " + connection);
			System.out.println("autoCommit: " + connection.getAutoCommit());
			System.out.println("transactionIsolation: "
					+ connection.getTransactionIsolation());
		}
	});
	System.out.println("flushMode: " + session.getFlushMode());//FlushMode.AUTO
	System.out.println(session);
	assertNotNull(session);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:18,代码来源:HibernateCfgTest.java

示例12: openSession

import org.hibernate.jdbc.Work; //导入依赖的package包/类
@Test
public void openSession() throws Exception {
	createSessionFactory();
	//
	Session session = sessionFactory.openSession();
	session.doWork(new Work() {
		public void execute(Connection connection) throws SQLException {
			System.out.println("connection: " + connection);
			System.out.println("autoCommit: " + connection.getAutoCommit());
			System.out.println("transactionIsolation: " + connection.getTransactionIsolation());
		}
	});
	System.out.println("flushMode: " + session.getFlushMode());
	System.out.println(session);
	assertNotNull(session);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:17,代码来源:CommonDaoImplWithoutSpringTest.java

示例13: openSession

import org.hibernate.jdbc.Work; //导入依赖的package包/类
@Test
public void openSession() throws Exception {
	Configuration config = new Configuration().configure("hibernate.cfg.xml");

	// SessionFactory sessionFactory = config.buildSessionFactory();
	ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties())
			.buildServiceRegistry();
	SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);

	System.out.println("sessionFactory: " + sessionFactory);
	Session session = sessionFactory.openSession();
	session.doWork(new Work() {
		public void execute(Connection connection) throws SQLException {
			System.out.println("connection: " + connection);
			System.out.println("getAutoCommit: " + connection.getAutoCommit());
			System.out.println("getTransactionIsolation: " + connection.getTransactionIsolation());
		}
	});
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:20,代码来源:CommonBeanAdapterTest.java

示例14: beginTransaction

import org.hibernate.jdbc.Work; //导入依赖的package包/类
@Override
public Object beginTransaction(EntityManager entityManager,
        final TransactionDefinition definition) throws PersistenceException,
        SQLException, TransactionException {

    Session session = entityManager.unwrap(Session.class);
    session.doWork(new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {
            DataSourceUtils.prepareConnectionForTransaction(connection, definition);
            if (connection.isReadOnly() && !definition.isReadOnly()) {
                connection.setReadOnly(false);

            }
        }
    });

    entityManager.getTransaction().begin();

    return prepareTransaction(entityManager, definition.isReadOnly(), definition.getName());
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:22,代码来源:HibernateExtendedJpaDialect.java

示例15: runScript

import org.hibernate.jdbc.Work; //导入依赖的package包/类
public void runScript() {
    getSession().doWork(new Work() {
        public void execute(Connection conn) throws SQLException {
            if(JdbcHelper.isExec(conn)) {
                return;
            }
            try {
                String databaseType = JdbcHelper.getDatabaseType(conn);
                String schema = "db/core/schema-" + databaseType + ".sql";
                ScriptRunner runner = new ScriptRunner(conn, true);
                runner.runScript(schema);
            } catch (Exception e) {
                throw new SnakerException(e);
            }
        }
    });
}
 
开发者ID:snakerflow,项目名称:snakerflow,代码行数:18,代码来源:Hibernate4Access.java


注:本文中的org.hibernate.jdbc.Work类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。