Java Code Examples for org.springframework.orm.jpa.vendor.Database

The following examples show how to use org.springframework.orm.jpa.vendor.Database. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-content   Source File: JpaInfrastructureConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

	HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
	vendorAdapter.setDatabase(Database.HSQL);
	vendorAdapter.setGenerateDdl(true);

	LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
	factory.setJpaVendorAdapter(vendorAdapter);
	factory.setPackagesToScan(packagesToScan());
	factory.setPersistenceUnitName("spring-data-rest-webmvc");
	factory.setDataSource(dataSource());
	factory.afterPropertiesSet();

	return factory;
}
 
Example 2
Source Project: genericdao   Source File: JPAUtil.java    License: Artistic License 2.0 6 votes vote down vote up
/**
 * 获取数据库类型
 */
public static Database getDBType(DataSource dataSource){
	String jdbcUrl = getJdbcUrlFromDataSource(dataSource);
	
	if (StringUtils.contains(jdbcUrl, ":h2:")) {
		return Database.H2 ;
	} else if (StringUtils.contains(jdbcUrl, ":mysql:")) {
		return Database.MYSQL ;
	} else if (StringUtils.contains(jdbcUrl, ":oracle:")) {
		return Database.ORACLE ;
	} else if (StringUtils.contains(jdbcUrl, ":postgresql:")) {
		return Database.POSTGRESQL ;
	} else if (StringUtils.contains(jdbcUrl, ":sqlserver:")) {
		return Database.SQL_SERVER ;
	}
	throw new IllegalArgumentException("Unknown Database of " + jdbcUrl);
}
 
Example 3
Source Project: herd   Source File: DaoSpringModuleConfig.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the Hibernate JPA vendor adapter needed by the entity manager.
 *
 * @return the Hibernate JPA vendor adapter.
 */
private JpaVendorAdapter getHibernateJpaVendorAdapter()
{
    HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
    // Set the database type.
    String databaseType = configurationHelper.getProperty(ConfigurationValue.DATABASE_TYPE);
    if (StringUtils.isBlank(databaseType))
    {
        throw new IllegalStateException(
            String.format("No database type found. Ensure the \"%s\" configuration entry is configured.", ConfigurationValue.DATABASE_TYPE.getKey()));
    }
    Database database = Database.valueOf(databaseType);
    LOGGER.info("jpaTargetDatabase={}", database);
    hibernateJpaVendorAdapter.setDatabase(database);
    hibernateJpaVendorAdapter.setGenerateDdl(false);
    return hibernateJpaVendorAdapter;
}
 
Example 4
Source Project: hawkbit   Source File: JpaTargetManagement.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public JpaTargetManagement(final EntityManager entityManager, final QuotaManagement quotaManagement,
        final TargetRepository targetRepository, final TargetMetadataRepository targetMetadataRepository,
        final RolloutGroupRepository rolloutGroupRepository,
        final DistributionSetRepository distributionSetRepository,
        final TargetFilterQueryRepository targetFilterQueryRepository,
        final TargetTagRepository targetTagRepository, final NoCountPagingRepository criteriaNoCountDao,
        final EventPublisherHolder eventPublisherHolder, final TenantAware tenantAware,
        final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
        final Database database) {
    this.entityManager = entityManager;
    this.quotaManagement = quotaManagement;
    this.targetRepository = targetRepository;
    this.targetMetadataRepository = targetMetadataRepository;
    this.rolloutGroupRepository = rolloutGroupRepository;
    this.distributionSetRepository = distributionSetRepository;
    this.targetFilterQueryRepository = targetFilterQueryRepository;
    this.targetTagRepository = targetTagRepository;
    this.criteriaNoCountDao = criteriaNoCountDao;
    this.eventPublisherHolder = eventPublisherHolder;
    this.tenantAware = tenantAware;
    this.afterCommit = afterCommit;
    this.virtualPropertyReplacer = virtualPropertyReplacer;
    this.database = database;
}
 
Example 5
public JpaSoftwareModuleManagement(final EntityManager entityManager,
        final DistributionSetRepository distributionSetRepository,
        final SoftwareModuleRepository softwareModuleRepository,
        final SoftwareModuleMetadataRepository softwareModuleMetadataRepository,
        final SoftwareModuleTypeRepository softwareModuleTypeRepository,
        final NoCountPagingRepository criteriaNoCountDao, final AuditorAware<String> auditorProvider,
        final ArtifactManagement artifactManagement, final QuotaManagement quotaManagement,
        final VirtualPropertyReplacer virtualPropertyReplacer, final Database database) {
    this.entityManager = entityManager;
    this.distributionSetRepository = distributionSetRepository;
    this.softwareModuleRepository = softwareModuleRepository;
    this.softwareModuleMetadataRepository = softwareModuleMetadataRepository;
    this.softwareModuleTypeRepository = softwareModuleTypeRepository;
    this.criteriaNoCountDao = criteriaNoCountDao;
    this.auditorProvider = auditorProvider;
    this.artifactManagement = artifactManagement;
    this.quotaManagement = quotaManagement;
    this.virtualPropertyReplacer = virtualPropertyReplacer;
    this.database = database;
}
 
Example 6
Source Project: hawkbit   Source File: RSQLUtilityTest.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void correctRsqlBuildsLikePredicateWithPercentage() {
    reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
    final String correctRsql = "name==a%";
    when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
    when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
    when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class));
    when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
            .thenReturn(mock(Predicate.class));
    when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
            .thenReturn(pathOfString(baseSoftwareModuleRootMock));
    // test
    RSQLUtility.parse(correctRsql, SoftwareModuleFields.class, null, Database.H2)
            .toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);

    // verification
    verify(criteriaBuilderMock, times(1)).and(any(Predicate.class));
    verify(criteriaBuilderMock, times(1)).like(eq(pathOfString(baseSoftwareModuleRootMock)),
            eq("a\\%".toUpperCase()), eq('\\'));
}
 
Example 7
Source Project: hawkbit   Source File: RSQLUtilityTest.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void correctRsqlBuildsLikePredicateWithPercentageSQLServer() {
    reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
    final String correctRsql = "name==a%";
    when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
    when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
    when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
            .thenReturn(pathOfString(baseSoftwareModuleRootMock));
    when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class));
    when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
            .thenReturn(mock(Predicate.class));

    // test
    RSQLUtility.parse(correctRsql, SoftwareModuleFields.class, null, Database.SQL_SERVER)
            .toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);

    // verification
    verify(criteriaBuilderMock, times(1)).and(any(Predicate.class));
    verify(criteriaBuilderMock, times(1)).like(eq(pathOfString(baseSoftwareModuleRootMock)),
            eq("a[%]".toUpperCase()), eq('\\'));
}
 
Example 8
Source Project: Project   Source File: JpaConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
  HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
  adapter.setDatabase(Database.H2);
  adapter.setShowSql(true);
  adapter.setGenerateDdl(false);
  adapter.setDatabasePlatform("org.hibernate.dialect.H2Dialect");
  return adapter;
}
 
Example 9
Source Project: Project   Source File: SpringDataJpaConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public HibernateJpaVendorAdapter jpaVendorAdapter() {
  HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
  adapter.setDatabase(Database.H2);
  adapter.setShowSql(false);
  adapter.setGenerateDdl(true);
  return adapter;
}
 
Example 10
Source Project: Project   Source File: JpaConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
  HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
  adapter.setDatabase(Database.H2);
  adapter.setShowSql(true);
  adapter.setGenerateDdl(false);
  adapter.setDatabasePlatform("org.hibernate.dialect.H2Dialect");
  return adapter;
}
 
Example 11
Source Project: Spring   Source File: JpaConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
	final HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
	hibernateJpaVendorAdapter.setShowSql(true);
	hibernateJpaVendorAdapter.setGenerateDdl(true);
	hibernateJpaVendorAdapter.setDatabase(Database.H2);
	return hibernateJpaVendorAdapter;
}
 
Example 12
Source Project: java-specialagent   Source File: SpringDataITest.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
  final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
  vendorAdapter.setDatabase(Database.H2);
  vendorAdapter.setGenerateDdl(true);

  final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
  em.setDataSource(dataSource());
  em.setPackagesToScan("io.opentracing.contrib.specialagent.test.spring.data");
  em.setJpaVendorAdapter(vendorAdapter);
  return em;
}
 
Example 13
Source Project: activiti6-boot2   Source File: DatabaseConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "entityManagerFactory")
public EntityManagerFactory entityManagerFactory() {
  LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
  entityManagerFactoryBean.setDataSource(dataSource());
  entityManagerFactoryBean.setPackagesToScan("org.activiti.rest.api.jpa.model");
  entityManagerFactoryBean.setPersistenceUnitName("test");
  HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
  hibernateJpaVendorAdapter.setShowSql(false);
  hibernateJpaVendorAdapter.setGenerateDdl(true);
  hibernateJpaVendorAdapter.setDatabase(Database.H2);
  entityManagerFactoryBean.setJpaVendorAdapter(hibernateJpaVendorAdapter);
  entityManagerFactoryBean.afterPropertiesSet();
  return entityManagerFactoryBean.getObject();
}
 
Example 14
Source Project: loc-framework   Source File: LocJpaConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
  AbstractJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
  adapter.setShowSql(jpaProperties.isShowSql());
  adapter.setDatabase(Database.MYSQL);
  adapter.setDatabasePlatform(jpaProperties.getDatabasePlatform());
  adapter.setGenerateDdl(jpaProperties.isGenerateDdl());
  return adapter;
}
 
Example 15
@Bean
LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {

	HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
	adapter.setDatabase(Database.HSQL);
	adapter.setGenerateDdl(true);

	LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
	factoryBean.setDataSource(dataSource);
	factoryBean.setJpaVendorAdapter(adapter);
	factoryBean.setPackagesToScan("org.springframework.events.jpa");

	return factoryBean;
}
 
Example 16
@Bean
protected EclipseLinkJpaVendorAdapter jpaVendorAdapter() {
    EclipseLinkJpaVendorAdapter adapter = new EclipseLinkJpaVendorAdapter();
    adapter.setDatabase(Database.MYSQL);
    adapter.setShowSql(true);
    adapter.setGenerateDdl(false);
    return adapter;
}
 
Example 17
Source Project: spring-content   Source File: EnableCmisTest.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
	HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
	vendorAdapter.setDatabase(Database.H2);
	vendorAdapter.setGenerateDdl(true);

	LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
	factory.setJpaVendorAdapter(vendorAdapter);
	factory.setPackagesToScan("org.springframework.content.cmis.integration");
	factory.setDataSource(dataSource());

	return factory;
}
 
Example 18
Source Project: spring-content   Source File: JpaConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
	HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
	vendorAdapter.setDatabase(Database.H2);
	vendorAdapter.setGenerateDdl(true);

	LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
	factory.setJpaVendorAdapter(vendorAdapter);
	factory.setPackagesToScan("org.springframework.content.cmis.support");
	factory.setDataSource(dataSource());

	return factory;
}
 
Example 19
Source Project: spring-content   Source File: RenditionsConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setDatabase(Database.H2);
    vendorAdapter.setGenerateDdl(true);

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("internal.org.springframework.renditions.context");
    factory.setDataSource(dataSource());

    return factory;
}
 
Example 20
Source Project: spring-content   Source File: ElasticsearchConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setDatabase(Database.H2);
    vendorAdapter.setGenerateDdl(true);

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("org.springframework.content.elasticsearch");
    factory.setDataSource(dataSource());

    return factory;
}
 
Example 21
Source Project: spring-content   Source File: EnableJpaStoresTest.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
	HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
	vendorAdapter.setDatabase(Database.HSQL);
	vendorAdapter.setGenerateDdl(true);

	LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
	factory.setJpaVendorAdapter(vendorAdapter);
	factory.setPackagesToScan(getClass().getPackage().getName());
	factory.setDataSource(dataSource());

	return factory;
}
 
Example 22
Source Project: Spring-Framework-Essentials   Source File: AppConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
    HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setShowSql(true);
    adapter.setGenerateDdl(true);
    adapter.setDatabase(Database.H2);
    adapter.setDatabasePlatform("org.hibernate.dialect.H2Dialect");
    return adapter;
}
 
Example 23
Source Project: Spring-Framework-Essentials   Source File: AppConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
    HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setShowSql(true);
    adapter.setGenerateDdl(true);
    adapter.setDatabase(Database.MYSQL);
    return adapter;
}
 
Example 24
Source Project: flowable-engine   Source File: DatabaseConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "entityManagerFactory")
public EntityManagerFactory entityManagerFactory(DataSource dataSource) {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource);
    entityManagerFactoryBean.setPackagesToScan("org.flowable.rest.api.jpa.model");
    entityManagerFactoryBean.setPersistenceUnitName("test");
    HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
    hibernateJpaVendorAdapter.setShowSql(false);
    hibernateJpaVendorAdapter.setGenerateDdl(true);
    hibernateJpaVendorAdapter.setDatabase(Database.H2);
    entityManagerFactoryBean.setJpaVendorAdapter(hibernateJpaVendorAdapter);
    entityManagerFactoryBean.afterPropertiesSet();
    return entityManagerFactoryBean.getObject();
}
 
Example 25
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

  LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
  factory.setDataSource(dataSource());
  factory.setMappingResources("META-INF/orm.xml");
  factory.setPackagesToScan("com.cosium.spring.data.jpa.entity.graph");

  HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
  jpaVendorAdapter.setDatabase(Database.H2);
  jpaVendorAdapter.setGenerateDdl(true);
  factory.setJpaVendorAdapter(jpaVendorAdapter);

  return factory;
}
 
Example 26
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
	HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
	hibernateJpaVendorAdapter.setShowSql(true);
	hibernateJpaVendorAdapter.setGenerateDdl(true);
	hibernateJpaVendorAdapter.setDatabase(Database.MYSQL);
	return hibernateJpaVendorAdapter;
}
 
Example 27
Source Project: hawkbit   Source File: JpaTargetTagManagement.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public JpaTargetTagManagement(final TargetTagRepository targetTagRepository,
        final TargetRepository targetRepository, final VirtualPropertyReplacer virtualPropertyReplacer,
        final Database database) {
    this.targetTagRepository = targetTagRepository;
    this.targetRepository = targetRepository;
    this.virtualPropertyReplacer = virtualPropertyReplacer;
    this.database = database;
}
 
Example 28
Source Project: hawkbit   Source File: RSQLUtility.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private RSQLSpecification(final String rsql, final Class<A> enumType,
        final VirtualPropertyReplacer virtualPropertyReplacer, final Database database) {
    this.rsql = rsql;
    this.enumType = enumType;
    this.virtualPropertyReplacer = virtualPropertyReplacer;
    this.database = database;
}
 
Example 29
Source Project: hawkbit   Source File: RSQLUtility.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private JpqQueryRSQLVisitor(final Root<T> root, final CriteriaBuilder cb, final Class<A> enumType,
        final VirtualPropertyReplacer virtualPropertyReplacer, final Database database,
        final CriteriaQuery<?> query) {
    this.root = root;
    this.cb = cb;
    this.query = query;
    this.enumType = enumType;
    this.virtualPropertyReplacer = virtualPropertyReplacer;
    this.simpleTypeConverter = new SimpleTypeConverter();
    this.database = database;
    this.joinsNeeded = false;
}
 
Example 30
Source Project: hawkbit   Source File: RSQLUtility.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private String toSQL(final String transformedValue) {
    final String escaped;

    if (database == Database.SQL_SERVER) {
        escaped = transformedValue.replace("%", "[%]").replace("_", "[_]");
    } else {
        escaped = transformedValue.replace("%", ESCAPE_CHAR + "%").replace("_", ESCAPE_CHAR + "_");
    }

    return escaped.replace(LIKE_WILDCARD, '%').toUpperCase();
}