本文整理汇总了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();
}
示例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("未知的数据库类型");
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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());
}
示例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);
}
}
示例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 ?";
}
}
示例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] + " ~ ?";
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}