當前位置: 首頁>>代碼示例>>Java>>正文


Java H2Dialect類代碼示例

本文整理匯總了Java中org.hibernate.dialect.H2Dialect的典型用法代碼示例。如果您正苦於以下問題:Java H2Dialect類的具體用法?Java H2Dialect怎麽用?Java H2Dialect使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


H2Dialect類屬於org.hibernate.dialect包,在下文中一共展示了H2Dialect類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: entityManagerFactory

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
@Bean
public EntityManagerFactory entityManagerFactory() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setDatabase(Database.H2);
    vendorAdapter.setGenerateDdl(jpaGenerateDdl);
    vendorAdapter.setShowSql(jpaShowSql);

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("org.bricket.b4.*.entity");
    factory.setDataSource(dataSource());
    factory.setJpaDialect(jpaDialect());

    Map<String, String> jpaProperties = new HashMap<String, String>();
    jpaProperties.put("hibernate.dialect", H2Dialect.class.getName());
    jpaProperties.put("hibernate.cache.region.factory_class", EhCacheRegionFactory.class.getName());
    jpaProperties.put("hibernate.cache.use_second_level_cache", "true");
    jpaProperties.put("hibernate.cache.use_query_cache", "true");
    jpaProperties.put("hibernate.cache.use_minimal_puts", "true");
    factory.setJpaPropertyMap(jpaProperties);

    factory.afterPropertiesSet();

    return factory.getObject();
}
 
開發者ID:bricket,項目名稱:b4,代碼行數:26,代碼來源:B4CoreRootConfig.java

示例2: getDialect

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
/**
 * 從DataSoure中取出connection, 根據connection的metadata中的jdbcUrl判斷Dialect類型.
 * 僅支持Oracle 10, H2, MySql, PostgreSql, SQLServer,如需更多數據庫類型,請仿照此類自行編寫。
 */
public static String getDialect(DataSource dataSource) {
	switch (getDBType(dataSource)) {
		case H2:
			return H2Dialect.class.getName();
		case MYSQL:
			return MySQLDialectWithoutFK.class.getName();
		case ORACLE:
			return Oracle10gDialectWithoutFK.class.getName() ;
		case POSTGRESQL:
			return PostgreSQL9DialectWithoutFK.class.getName() ;
		case SQL_SERVER:
			return SQLServer2008Dialect.class.getName();
	}

	throw new IllegalArgumentException("未知的數據庫類型");
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:21,代碼來源:JPAUtil.java

示例3: determineDatabaseDialectClass

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
/**
 * Determine the Hibernate database dialect class for the given target database.
 * @param database the target database
 * @return the Hibernate database dialect class, or {@code null} if none found
 */
@SuppressWarnings("deprecation")
protected Class<?> determineDatabaseDialectClass(Database database) {
	switch (database) {
		case DB2: return DB2Dialect.class;
		case DERBY: return DerbyDialect.class;  // DerbyDialect deprecated in 4.x
		case H2: return H2Dialect.class;
		case HSQL: return HSQLDialect.class;
		case INFORMIX: return InformixDialect.class;
		case MYSQL: return MySQLDialect.class;
		case ORACLE: return Oracle9iDialect.class;
		case POSTGRESQL: return PostgreSQLDialect.class;  // PostgreSQLDialect deprecated in 4.x
		case SQL_SERVER: return SQLServerDialect.class;
		case SYBASE: return org.hibernate.dialect.SybaseDialect.class;  // SybaseDialect deprecated in 3.6 but not 4.x
		default: return null;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:HibernateJpaVendorAdapter.java

示例4: hibernateDatabaseDialectClass

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
private static Class<?> hibernateDatabaseDialectClass(DatabasePlatform database) {
	switch (database) {
	case DB2:
		return DB2Dialect.class;
	case DB2_AS400:
		return DB2400Dialect.class;
	case DERBY:
		return DerbyTenSevenDialect.class;
	case H2:
		return H2Dialect.class;
	case HSQL:
		return HSQLDialect.class;
	case INFORMIX:
		return InformixDialect.class;
	case MYSQL:
		return MySQL5Dialect.class;
	case ORACLE:
		return Oracle10gDialect.class;
	case POSTGRESQL:
		return PostgreSQL82Dialect.class;
	case SQL_SERVER:
		return SQLServerDialect.class;
	case MARIADB:
		return MySQL5Dialect.class;
	case HANA:
		return HANARowStoreDialect.class;
	case SQLITE:
	case NONE:
	default:
		break;
	}
	return null;
}
 
開發者ID:holon-platform,項目名稱:holon-datastore-jpa,代碼行數:34,代碼來源:EntityManagerFactoryConfigurator.java

示例5: getDialect

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
/**
 * 從DataSoure中取出connection, 根據connection的metadata中的jdbcUrl判斷Dialect類型.
 * 僅支持Oracle, H2, MySql, PostgreSql, SQLServer,如需更多數據庫類型,請仿照此類自行編寫。
 */
public static String getDialect(DataSource dataSource) {
	String jdbcUrl = getJdbcUrlFromDataSource(dataSource);

	// 根據jdbc url判斷dialect
	if (StringUtils.contains(jdbcUrl, ":h2:")) {
		return H2Dialect.class.getName();
	} else if (StringUtils.contains(jdbcUrl, ":mysql:")) {
		return MySQL5InnoDBDialect.class.getName();
	} else if (StringUtils.contains(jdbcUrl, ":oracle:")) {
		return Oracle10gDialect.class.getName();
	} else if (StringUtils.contains(jdbcUrl, ":postgresql:")) {
		return PostgreSQL82Dialect.class.getName();
	} else if (StringUtils.contains(jdbcUrl, ":sqlserver:")) {
		return SQLServer2008Dialect.class.getName();
	} else {
		throw new IllegalArgumentException("Unknown Database of " + jdbcUrl);
	}
}
 
開發者ID:summerDp,項目名稱:dpCms,代碼行數:23,代碼來源:Hibernates.java

示例6: getHibernateDialect

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
private Class<? extends Dialect> getHibernateDialect(final PersistenceUnitContext context) {
    final ConnectionDialect dialect = context.getConnectionDialect();
    switch (dialect) {
    case MSSQLSERVER:
        return SQLServerDialect.class;
    case MYSQL:
        return MySQL5InnoDBDialect.class;
    case POSTGRESQL:
        return PostgreSQL9Dialect.class;
    case ORACLE:
        return Oracle10gDialect.class;
    case H2:
        return H2Dialect.class;
    default:
        throw UnknownArgumentException.newInstance(ConnectionDialect.class, dialect);
    }
}
 
開發者ID:subes,項目名稱:invesdwin-context-persistence,代碼行數:18,代碼來源:HibernateDialectSpecificDelegate.java

示例7: test

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
@Test
public void test() {
    List<LogbackRecorder> recorders = new LinkedList<>();
    recorders.add(LogbackRecorder.forName("org.jboss.logging").reset().capture("ALL"));
    recorders.add(LogbackRecorder.forClass(Dialect.class).reset().capture("ALL"));
    recorders.add(LogbackRecorder.forClass(H2Dialect.class).reset().capture("ALL"));

    Map<Integer, String> registered = new LinkedHashMap<>();

    new FixedH2Dialect() {

        @Override
        protected void registerColumnType(int code, String name) {
            registered.put(code, name);
            super.registerColumnType(code, name);
        }

    };

    assertThat(registered.get(Types.FLOAT)).isEqualTo("real");

    recorders.forEach(LogbackRecorder::release);
}
 
開發者ID:jhipster,項目名稱:jhipster,代碼行數:24,代碼來源:FixedH2DialectTest.java

示例8: testGetDialect

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
@Test
public void testGetDialect() throws SQLException {
	DataSource mockDataSource = mock(DataSource.class);
	Connection mockConnection = mock(Connection.class);
	DatabaseMetaData mockMetaData = mock(DatabaseMetaData.class);

	when(mockDataSource.getConnection()).thenReturn(mockConnection);
	when(mockConnection.getMetaData()).thenReturn(mockMetaData);

	when(mockMetaData.getURL()).thenReturn("jdbc:h2:file:~/test;AUTO_SERVER=TRUE");
	String dialect = Hibernates.getDialect(mockDataSource);
	assertThat(dialect).isEqualTo(H2Dialect.class.getName());

	when(mockMetaData.getURL()).thenReturn("jdbc:mysql://localhost:3306/test");
	dialect = Hibernates.getDialect(mockDataSource);
	assertThat(dialect).isEqualTo(MySQL5InnoDBDialect.class.getName());

	when(mockMetaData.getURL()).thenReturn("jdbc:oracle:thin:@127.0.0.1:1521:XE");
	dialect = Hibernates.getDialect(mockDataSource);
	assertThat(dialect).isEqualTo(Oracle10gDialect.class.getName());
}
 
開發者ID:pengqiuyuan,項目名稱:g2,代碼行數:22,代碼來源:HibernatesTest.java

示例9: getDialect

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
/**
 * 從DataSoure中取出connection, 根據connection的metadata中的jdbcUrl判斷Dialect類型.
 * 僅支持Oracle, H2, MySql, PostgreSql, SQLServer,如需更多數據庫類型,請仿照此類自行編寫。
 */
public static String getDialect(DataSource dataSource) {
    String jdbcUrl = getJdbcUrlFromDataSource(dataSource);

    // 根據jdbc url判斷dialect
    if (StringUtils.contains(jdbcUrl, ":h2:")) {
        return H2Dialect.class.getName();
    } else if (StringUtils.contains(jdbcUrl, ":mysql:")) {
        return MySQL5InnoDBDialect.class.getName();
    } else if (StringUtils.contains(jdbcUrl, ":oracle:")) {
        return Oracle10gDialect.class.getName();
    } else if (StringUtils.contains(jdbcUrl, ":postgresql:")) {
        return PostgreSQL82Dialect.class.getName();
    } else if (StringUtils.contains(jdbcUrl, ":sqlserver:")) {
        return SQLServer2008Dialect.class.getName();
    } else {
        throw new IllegalArgumentException("Unknown Database of " + jdbcUrl);
    }
}
 
開發者ID:shawn-gogh,項目名稱:myjavacode,代碼行數:23,代碼來源:Hibernates.java

示例10: toSqlString

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {

	String[] columns = criteriaQuery.findColumns(getPropiedad(), criteria);
	if (columns.length != 1) {
		throw new HibernateException(
				"NumberLike may only be used with single-column properties");
	}
	SessionFactoryImplementor factory = criteriaQuery.getFactory();

	if (factory.getDialect() instanceof H2Dialect) {
		return "cast(cast(" + columns[0] + " as int) as VARCHAR) "
				+ "like ?";
	} else {
		// XXX ver consistencia entre bases de datos
		return columns[0] + "::text like ?";
	}
}
 
開發者ID:fpuna-cia,項目名稱:karaku,代碼行數:19,代碼來源:NumberLike.java

示例11: toSqlString

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {

	String[] columns = criteriaQuery.findColumns(getPath(), criteria);
	if (columns.length != 1) {
		throw new HibernateException(
				"Regex may only be used with single-column properties");
	}
	SessionFactoryImplementor factory = criteriaQuery.getFactory();

	if (factory.getDialect() instanceof H2Dialect) {
		return columns[0] + " regexp ?";
	} else {
		// XXX ver consistencia entre bases de datos
		return columns[0] + " ~ ?";
	}
}
 
開發者ID:fpuna-cia,項目名稱:karaku,代碼行數:18,代碼來源:Regex.java

示例12: determineDatabaseDialectClass

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
/**
 * Determine the Hibernate database dialect class for the given target database.
 * @param database the target database
 * @return the Hibernate database dialect class, or {@code null} if none found
 */
protected Class determineDatabaseDialectClass(Database database) {
	switch (database) {
		case DB2: return DB2Dialect.class;
		case DERBY: return DerbyDialect.class;
		case H2: return H2Dialect.class;
		case HSQL: return HSQLDialect.class;
		case INFORMIX: return InformixDialect.class;
		case MYSQL: return MySQLDialect.class;
		case ORACLE: return Oracle9iDialect.class;
		case POSTGRESQL: return PostgreSQLDialect.class;
		case SQL_SERVER: return SQLServerDialect.class;
		case SYBASE: return SybaseDialect.class;
		default: return null;
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:21,代碼來源:HibernateJpaVendorAdapter.java

示例13: testProvideDispose

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
/**
 * Test provide and dispose.
 */
@Test
public void testProvideDispose() {
    HibernateServiceRegistryFactory factory = new
            HibernateServiceRegistryFactory();

    ServiceRegistry serviceRegistry = factory.provide();

    Dialect d = new MetadataSources(serviceRegistry)
            .buildMetadata().getDatabase().getDialect();
    Assert.assertTrue(d instanceof H2Dialect);

    // This shouldn't actually do anything, but is included here for
    // coverage.
    factory.dispose(serviceRegistry);
}
 
開發者ID:krotscheck,項目名稱:jersey2-toolkit,代碼行數:19,代碼來源:HibernateServiceRegistryFactoryTest.java

示例14: testBinder

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
/**
 * Test the application binder.
 */
@Test
public void testBinder() {

    ResourceConfig config = new ResourceConfig();
    config.register(TestFeature.class);

    // Make sure it's registered
    Assert.assertTrue(config.isRegistered(TestFeature.class));

    // Create a fake application.
    ApplicationHandler handler = new ApplicationHandler(config);
    ServiceRegistry serviceRegistry = handler
            .getServiceLocator().getService(ServiceRegistry.class);
    Assert.assertNotNull(serviceRegistry);

    // Make sure it's reading from the same place.
    Dialect d = new MetadataSources(serviceRegistry)
            .buildMetadata().getDatabase().getDialect();
    Assert.assertTrue(d instanceof H2Dialect);

    // Make sure it's a singleton...
    ServiceRegistry serviceRegistry2 = handler
            .getServiceLocator().getService(ServiceRegistry.class);
    Assert.assertSame(serviceRegistry, serviceRegistry2);
}
 
開發者ID:krotscheck,項目名稱:jersey2-toolkit,代碼行數:29,代碼來源:HibernateServiceRegistryFactoryTest.java

示例15: testGetDialect

import org.hibernate.dialect.H2Dialect; //導入依賴的package包/類
@Test
public void testGetDialect() throws SQLException {
	DataSource mockDataSource = Mockito.mock(DataSource.class);
	Connection mockConnection = Mockito.mock(Connection.class);
	DatabaseMetaData mockMetaData = Mockito.mock(DatabaseMetaData.class);

	Mockito.when(mockDataSource.getConnection()).thenReturn(mockConnection);
	Mockito.when(mockConnection.getMetaData()).thenReturn(mockMetaData);

	Mockito.when(mockMetaData.getURL()).thenReturn("jdbc:h2:file:~/test;AUTO_SERVER=TRUE");
	String dialect = Hibernates.getDialect(mockDataSource);
	assertEquals(H2Dialect.class.getName(), dialect);

	Mockito.when(mockMetaData.getURL()).thenReturn("jdbc:mysql://localhost:3306/test");
	dialect = Hibernates.getDialect(mockDataSource);
	assertEquals(MySQL5InnoDBDialect.class.getName(), dialect);

	Mockito.when(mockMetaData.getURL()).thenReturn("jdbc:oracle:thin:@127.0.0.1:1521:XE");
	dialect = Hibernates.getDialect(mockDataSource);
	assertEquals(Oracle10gDialect.class.getName(), dialect);
}
 
開發者ID:Michaelleolee,項目名稱:appengine,代碼行數:22,代碼來源:HibernatesTest.java


注:本文中的org.hibernate.dialect.H2Dialect類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。