org.eclipse.persistence.config.PersistenceUnitProperties Java Examples

The following examples show how to use org.eclipse.persistence.config.PersistenceUnitProperties. 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 File: Migrate.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
public void migrate3() {
	Map<String, String> properties = new HashMap<String, String>();
	properties.put(PersistenceUnitProperties.JDBC_PASSWORD, Site.DATABASEPASSWORD);
	properties.put(PersistenceUnitProperties.LOGGING_LEVEL, "fine");
	EntityManagerFactory factory = Persistence.createEntityManagerFactory("botlibre", properties);
	EntityManager em = factory.createEntityManager();
	em.getTransaction().begin();
	try {
		em.createNativeQuery("Update ChatChannel set creator_userid = (Select t2.admins_userid from CHAT_ADMINS t2 where t2.chatchannel_id = id)").executeUpdate();
		em.createNativeQuery("Update Forum set creator_userid = (Select t2.admins_userid from forum_ADMINS t2 where t2.forum_id = id)").executeUpdate();
		em.createNativeQuery("Update BotInstance set creator_userid = (Select t2.admins_userid from PANODRAINSTANCE_ADMINS t2 where t2.instances_id = id)").executeUpdate();
		em.getTransaction().commit();
	} catch (Exception exception) {
		exception.printStackTrace();
	} finally {
		if (em.getTransaction().isActive()) {
			em.getTransaction().rollback();
		}
		em.close();
		factory.close();
	}
}
 
Example #2
Source File: RepositoryApplicationConfiguration.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Map<String, Object> getVendorProperties() {

    final Map<String, Object> properties = Maps.newHashMapWithExpectedSize(7);
    // Turn off dynamic weaving to disable LTW lookup in static weaving mode
    properties.put(PersistenceUnitProperties.WEAVING, "false");
    // needed for reports
    properties.put(PersistenceUnitProperties.ALLOW_NATIVE_SQL_QUERIES, "true");
    // flyway
    properties.put(PersistenceUnitProperties.DDL_GENERATION, "none");
    // Embeed into hawkBit logging
    properties.put(PersistenceUnitProperties.LOGGING_LOGGER, "JavaLogger");
    // Ensure that we flush only at the end of the transaction
    properties.put(PersistenceUnitProperties.PERSISTENCE_CONTEXT_FLUSH_MODE, "COMMIT");
    // Enable batch writing
    properties.put(PersistenceUnitProperties.BATCH_WRITING, "JDBC");
    // Batch size
    properties.put(PersistenceUnitProperties.BATCH_WRITING_SIZE, "500");

    return properties;
}
 
Example #3
Source File: TestFactory.java    From cloud-espm-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Get persistence.xml properties
 * 
 * @return properties as Map
 */
private static Map<String, String> getDefaultTestProperties() {
	if (defaultProperties == null) {
		defaultProperties = new HashMap<String, String>();
		defaultProperties.put(PersistenceUnitProperties.JDBC_DRIVER,
				TEST_JDBC_DRIVER);
		if (inMemory) {
			defaultProperties.put(PersistenceUnitProperties.JDBC_URL,
					TEST_JDBC_URL_IN_MEMORY);
		} else {
			defaultProperties.put(PersistenceUnitProperties.JDBC_URL,
					TEST_JDBC_URL);
		}
		defaultProperties.put(PersistenceUnitProperties.JDBC_USER,
				TEST_JDBC_USER);
		defaultProperties.put(PersistenceUnitProperties.JDBC_PASSWORD,
				TEST_JDBC_PASSWORD);
		defaultProperties.put(PersistenceUnitProperties.TARGET_DATABASE,
				TEST_TARGET_DATABASE);
		defaultProperties.put(PersistenceUnitProperties.LOGGING_LEVEL,
				TEST_JPA_LOG_LEVEL);
		defaultProperties.put(PersistenceUnitProperties.DDL_GENERATION,
				PersistenceUnitProperties.DROP_AND_CREATE);
	}
	return defaultProperties;
}
 
Example #4
Source File: JpaSystemManagement.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Transactional
@Retryable(include = {
        ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteTenant(final String t) {
    final String tenant = t.toUpperCase();
    cacheManager.evictCaches(tenant);
    rolloutStatusCache.evictCaches(tenant);
    tenantAware.runAsTenant(tenant, () -> {
        entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant);
        tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant);
        tenantConfigurationRepository.deleteByTenant(tenant);
        targetRepository.deleteByTenant(tenant);
        targetFilterQueryRepository.deleteByTenant(tenant);
        rolloutRepository.deleteByTenant(tenant);
        targetTagRepository.deleteByTenant(tenant);
        distributionSetTagRepository.deleteByTenant(tenant);
        distributionSetRepository.deleteByTenant(tenant);
        distributionSetTypeRepository.deleteByTenant(tenant);
        softwareModuleRepository.deleteByTenant(tenant);
        artifactRepository.deleteByTenant(tenant);
        softwareModuleTypeRepository.deleteByTenant(tenant);
        return null;
    });
}
 
Example #5
Source File: ReplicationModule.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configure() {
  // Replication stuff
  persistenceProperties.put(
      PersistenceUnitProperties.COORDINATION_PROTOCOL, CacheCoordinationProtocol.JGROUPS);
  persistenceProperties.put(
      PersistenceUnitProperties.COORDINATION_JGROUPS_CONFIG, JGROUPS_CONF_FILE);
  bindConstant().annotatedWith(Names.named("jgroups.config.file")).to(JGROUPS_CONF_FILE);

  bind(RemoteSubscriptionStorage.class).to(DistributedRemoteSubscriptionStorage.class);

  bind(WorkspaceLockService.class)
      .to(org.eclipse.che.multiuser.api.distributed.lock.JGroupsWorkspaceLockService.class);
  bind(WorkspaceStatusCache.class)
      .to(org.eclipse.che.multiuser.api.distributed.cache.JGroupsWorkspaceStatusCache.class);

  Multibinder.newSetBinder(binder(), ServiceTermination.class)
      .addBinding()
      .to(JGroupsServiceTermination.class);

  bind(WorkspaceStopPropagator.class).asEagerSingleton();
}
 
Example #6
Source File: FavoriteCityService.java    From cloud-weatherapp with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link EntityManagerFactory}.
 * 
 * @return The {@link EntityManagerFactory}
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected EntityManagerFactory getEntityManagerFactory()
{
	EntityManagerFactory retVal = null;
	
	try
	{
		Map properties = new HashMap();
		
		DataSource ds = this.getDataSource();
		
        properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, ds);
        
        retVal = Persistence.createEntityManagerFactory("application", properties);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
	}
	
	return retVal;
}
 
Example #7
Source File: KradEclipseLinkEntityManagerFactoryBean.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
   * {@inheritDoc}
   */
  @Override
  protected void loadCustomJpaDefaults(Map<String, String> jpaProperties) {
if (getPersistenceUnitManager().getDefaultJtaDataSource() != null
		&& !jpaProperties.containsKey(PersistenceUnitProperties.TARGET_SERVER)) {
          jpaProperties.put(PersistenceUnitProperties.TARGET_SERVER, JtaTransactionController.class.getName());
      }

if (!jpaProperties.containsKey(PersistenceUnitProperties.SESSION_CUSTOMIZER)) {
	jpaProperties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, KradEclipseLinkCustomizer.class.getName());
}

if (!jpaProperties.containsKey(PersistenceUnitProperties.CACHE_SHARED_DEFAULT)) {
	jpaProperties.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT, "false");
}
  }
 
Example #8
Source File: TenancyEclipseLinkSampleApplication.java    From tenancy-sample with Apache License 2.0 5 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory(DataSource dataSource) {
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setDataSource(dataSource);
    factory.setJpaVendorAdapter(new EclipseLinkJpaVendorAdapter());
    factory.setPackagesToScan(TenancyEclipseLinkSampleApplication.class.getPackage().getName());
    factory.getJpaPropertyMap().put(PersistenceUnitProperties.DDL_GENERATION_MODE, PersistenceUnitProperties.DDL_DATABASE_GENERATION);
    factory.getJpaPropertyMap().put(PersistenceUnitProperties.LOGGING_LEVEL, "FINE");
    factory.getJpaPropertyMap().put(PersistenceUnitProperties.WEAVING, "false");
    factory.getJpaPropertyMap().put(TenantHolder.TENANT_ID, TenantHolder.getTenant());
    factory.afterPropertiesSet();
    return factory.getObject();
}
 
Example #9
Source File: EclipseLinkJpaVendorAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Map<String, Object> getJpaPropertyMap() {
	Map<String, Object> jpaProperties = new HashMap<>();

	if (getDatabasePlatform() != null) {
		jpaProperties.put(PersistenceUnitProperties.TARGET_DATABASE, getDatabasePlatform());
	}
	else {
		String targetDatabase = determineTargetDatabaseName(getDatabase());
		if (targetDatabase != null) {
			jpaProperties.put(PersistenceUnitProperties.TARGET_DATABASE, targetDatabase);
		}
	}

	if (isGenerateDdl()) {
		jpaProperties.put(PersistenceUnitProperties.DDL_GENERATION,
				PersistenceUnitProperties.CREATE_ONLY);
		jpaProperties.put(PersistenceUnitProperties.DDL_GENERATION_MODE,
				PersistenceUnitProperties.DDL_DATABASE_GENERATION);
	}
	if (isShowSql()) {
		jpaProperties.put(PersistenceUnitProperties.CATEGORY_LOGGING_LEVEL_ +
				org.eclipse.persistence.logging.SessionLog.SQL, Level.FINE.toString());
		jpaProperties.put(PersistenceUnitProperties.LOGGING_PARAMETERS, Boolean.TRUE.toString());
	}

	return jpaProperties;
}
 
Example #10
Source File: Migrate.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
public void migrate7() {
	Map<String, String> properties = new HashMap<String, String>();
	properties.put(PersistenceUnitProperties.JDBC_PASSWORD, Site.DATABASEPASSWORD);
	properties.put(PersistenceUnitProperties.LOGGING_LEVEL, "fine");
	EntityManagerFactory factory = Persistence.createEntityManagerFactory(Site.PERSISTENCE_UNIT, properties);
	EntityManager em = factory.createEntityManager();
	em.getTransaction().begin();
	try {
		em.createNativeQuery("Update ChatChannel set alias = name").executeUpdate();
		em.createNativeQuery("Update Forum set alias = name").executeUpdate();
		em.createNativeQuery("Update BotInstance set alias = name").executeUpdate();
		em.createNativeQuery("Update Graphic set alias = name").executeUpdate();
		em.createNativeQuery("Update Domain set alias = name").executeUpdate();
		em.createNativeQuery("Update IssueTracker set alias = name").executeUpdate();
		em.createNativeQuery("Update Analytic set alias = name").executeUpdate();
		em.createNativeQuery("Update Script set alias = name").executeUpdate();
		em.createNativeQuery("Update Avatar set alias = name").executeUpdate();
		em.getTransaction().commit();
	} catch (Exception exception) {
		exception.printStackTrace();
	} finally {
		if (em.getTransaction().isActive()) {
			em.getTransaction().rollback();
		}
		em.close();
		factory.close();
	}
}
 
Example #11
Source File: EclipseLinkSettings.java    From kumuluzee with MIT License 5 votes vote down vote up
@Override
public Map<String, String> getPersistenceUnitProperties() {

    if (jtaPresent) {
        properties.put(PersistenceUnitProperties.TARGET_SERVER, KumuluzPlatform.class.getName());
    }

    return properties;
}
 
Example #12
Source File: WsMasterModule.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void configureSingleUserMode(Map<String, String> persistenceProperties) {
  persistenceProperties.put(
      PersistenceUnitProperties.EXCEPTION_HANDLER_CLASS,
      "org.eclipse.che.core.db.h2.jpa.eclipselink.H2ExceptionHandler");
  bind(TokenValidator.class).to(org.eclipse.che.api.local.DummyTokenValidator.class);
  bind(MachineTokenProvider.class).to(MachineTokenProvider.EmptyMachineTokenProvider.class);

  bind(DataSource.class).toProvider(org.eclipse.che.core.db.h2.H2DataSourceProvider.class);

  install(new org.eclipse.che.api.user.server.jpa.UserJpaModule());
  install(new org.eclipse.che.api.workspace.server.jpa.WorkspaceJpaModule());

  bind(org.eclipse.che.api.user.server.CheUserCreator.class);

  bindConstant().annotatedWith(Names.named("che.agents.auth_enabled")).to(false);

  bind(org.eclipse.che.security.oauth.shared.OAuthTokenProvider.class)
      .to(org.eclipse.che.security.oauth.OAuthAuthenticatorTokenProvider.class);
  bind(OAuthAPI.class).to(EmbeddedOAuthAPI.class);

  bind(RemoteSubscriptionStorage.class)
      .to(org.eclipse.che.api.core.notification.InmemoryRemoteSubscriptionStorage.class);
  bind(WorkspaceLockService.class)
      .to(org.eclipse.che.api.workspace.server.DefaultWorkspaceLockService.class);
  bind(WorkspaceStatusCache.class)
      .to(org.eclipse.che.api.workspace.server.DefaultWorkspaceStatusCache.class);

  install(new org.eclipse.che.api.workspace.activity.inject.WorkspaceActivityModule());
}
 
Example #13
Source File: JpaEntityManagerFactory.java    From cloud-personslist-scenario with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the singleton EntityManagerFactory instance for accessing the
 * default database.
 * 
 * @return the singleton EntityManagerFactory instance
 * @throws NamingException
 *             if a naming exception occurs during initialization
 * @throws SQLException
 *             if a database occurs during initialization
 */
public static synchronized EntityManagerFactory getEntityManagerFactory()
		throws NamingException, SQLException {
	if (entityManagerFactory == null) {
		InitialContext ctx = new InitialContext();
		DataSource ds = (DataSource) ctx.lookup(DATA_SOURCE_NAME);
		Map<String, Object> properties = new HashMap<String, Object>();
		properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, ds);
		entityManagerFactory = Persistence.createEntityManagerFactory(
				PERSISTENCE_UNIT_NAME, properties);
	}
	return entityManagerFactory;
}
 
Example #14
Source File: JpaConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Override
protected Map<String, Object> getVendorProperties() {
    HashMap<String, Object> map = new HashMap<>();
    map.put(PersistenceUnitProperties.WEAVING, detectWeavingMode());
    map.put(PersistenceUnitProperties.DDL_GENERATION, "drop-and-create-tables");
    return map;
}
 
Example #15
Source File: Database.java    From desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void load(ConfigNode node) throws ConfigException {
    File dbFileName = new File(Config.getInstance().getConfDir() + File.separator + Constants.CONFIG_DATABASE_DIRNAME + File.separator + Constants.CONFIG_DATABASE_FILENAME);

    // Override database location with [confdir]/db/stacksync
    properties.setProperty(PersistenceUnitProperties.JDBC_URL,
            String.format(Constants.CONFIG_DATABASE_URL_FORMAT, dbFileName.getAbsolutePath()));
    
    properties.setProperty(PersistenceUnitProperties.JDBC_DRIVER,
            String.format(Constants.CONFIG_DATABASE_DRIVER, dbFileName.getAbsolutePath()));

    // Adjust generation strategy
    // - if DB folder exists, we assume the tables have been created
    // - if not, we need to create them
    if (!dbFileName.exists()) {
        properties.setProperty(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.CREATE_ONLY);
    } else {
        properties.setProperty(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.NONE);
    }

    // Override other values (if defined in config!)
    if (node != null) {
        for (ConfigNode property : node.findChildrenByXpath("property")) {
            properties.setProperty(property.getAttribute("name"), property.getAttribute("value"));
        }
    }

    //check directory
    File serviceProperties = new File(dbFileName.getAbsolutePath() + File.separator + "service.properties");
    if (!serviceProperties.exists()) {
        File databaseFolder = new File(Config.getInstance().getConfDir() + File.separator + Constants.CONFIG_DATABASE_DIRNAME);

        FileUtil.deleteRecursively(databaseFolder);
        databaseFolder.mkdirs();
    }
    
    // Load!
    entityManagerFactory = Persistence.createEntityManagerFactory(Constants.CONFIG_DATABASE_PERSISTENCE_UNIT, properties);
}
 
Example #16
Source File: MultiTenantJpaTransactionManager.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void doBegin(final Object transaction, final TransactionDefinition definition) {
    super.doBegin(transaction, definition);

    final String currentTenant = tenantAware.getCurrentTenant();
    if (currentTenant != null) {
        final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager
                .getResource(getEntityManagerFactory());
        final EntityManager em = emHolder.getEntityManager();
        em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase());
    }
}
 
Example #17
Source File: EclipselinkDdlGenerationMojo.java    From eclipselink-maven-plugin with Apache License 2.0 5 votes vote down vote up
private Map<String, Object> buildCfg()
{
    final Map<String, Object> cfg = new TreeMap<>();

    // No action towards the database
    cfg.put(PersistenceUnitProperties.SCHEMA_GENERATION_DATABASE_ACTION, PersistenceUnitProperties.SCHEMA_GENERATION_NONE_ACTION);

    // Create scripts
    cfg.put(PersistenceUnitProperties.SCHEMA_GENERATION_SCRIPTS_ACTION, action);
    cfg.put(PersistenceUnitProperties.SCHEMA_GENERATION_CREATE_SOURCE, PersistenceUnitProperties.SCHEMA_GENERATION_METADATA_SOURCE);
    cfg.put(PersistenceUnitProperties.SCHEMA_GENERATION_DROP_SOURCE, PersistenceUnitProperties.SCHEMA_GENERATION_METADATA_SOURCE);
    cfg.put(PersistenceUnitProperties.SCHEMA_GENERATION_SCRIPTS_CREATE_TARGET, ddlTargetFile);
    cfg.put(PersistenceUnitProperties.SCHEMA_GENERATION_SCRIPTS_DROP_TARGET, ddlDropTargetFile);
    cfg.put(PersistenceUnitProperties.SCHEMA_DATABASE_PRODUCT_NAME, databaseProductName);
    cfg.put(PersistenceUnitProperties.WEAVING, "false");

    if (databaseMajorVersion != null)
    {
        cfg.put(PersistenceUnitProperties.SCHEMA_DATABASE_MAJOR_VERSION, databaseMajorVersion);
    }

    if (databaseMinorVersion != null)
    {
        cfg.put(PersistenceUnitProperties.SCHEMA_DATABASE_MINOR_VERSION, databaseMinorVersion);
    }

    return cfg;
}
 
Example #18
Source File: JpaEntityManagerFactory.java    From cloud-espm-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the singleton EntityManagerFactory instance for accessing the
 * default database.
 * 
 * @return the singleton EntityManagerFactory instance
 * @throws NamingException
 *             if a naming exception occurs during initialization
 * @throws SQLException
 *             if a database occurs during initialization
 */
public static synchronized EntityManagerFactory getEntityManagerFactory()
		throws NamingException, SQLException {
	if (entityManagerFactory == null) {
		InitialContext ctx = new InitialContext();
		DataSource ds = (DataSource) ctx.lookup(DATA_SOURCE_NAME);
		Map<String, Object> properties = new HashMap<String, Object>();
		properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, ds);
		entityManagerFactory = Persistence.createEntityManagerFactory(
				PERSISTENCE_UNIT_NAME, properties);
		Utility.setEntityManagerFactory(entityManagerFactory);
	}
	return entityManagerFactory;
}
 
Example #19
Source File: EclipseLinkJpaVendorAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Map<String, Object> getJpaPropertyMap() {
	Map<String, Object> jpaProperties = new HashMap<>();

	if (getDatabasePlatform() != null) {
		jpaProperties.put(PersistenceUnitProperties.TARGET_DATABASE, getDatabasePlatform());
	}
	else {
		String targetDatabase = determineTargetDatabaseName(getDatabase());
		if (targetDatabase != null) {
			jpaProperties.put(PersistenceUnitProperties.TARGET_DATABASE, targetDatabase);
		}
	}

	if (isGenerateDdl()) {
		jpaProperties.put(PersistenceUnitProperties.DDL_GENERATION,
				PersistenceUnitProperties.CREATE_ONLY);
		jpaProperties.put(PersistenceUnitProperties.DDL_GENERATION_MODE,
				PersistenceUnitProperties.DDL_DATABASE_GENERATION);
	}
	if (isShowSql()) {
		jpaProperties.put(PersistenceUnitProperties.CATEGORY_LOGGING_LEVEL_ +
				org.eclipse.persistence.logging.SessionLog.SQL, Level.FINE.toString());
		jpaProperties.put(PersistenceUnitProperties.LOGGING_PARAMETERS, Boolean.TRUE.toString());
	}

	return jpaProperties;
}
 
Example #20
Source File: EclipseLinkJpaConfig.java    From griffin with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<String, Object> getVendorProperties() {
    Map<String, Object> map = new HashMap<>();
    map.put(PersistenceUnitProperties.WEAVING, "false");
    map.put(PersistenceUnitProperties.DDL_GENERATION,
        "create-or-extend-tables");
    return map;
}
 
Example #21
Source File: EclipseLinkJpaConfigForTest.java    From griffin with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<String, Object> getVendorProperties() {
    Map<String, Object> map = new HashMap<>();
    map.put(PersistenceUnitProperties.WEAVING, "false");
    map.put(PersistenceUnitProperties.DDL_GENERATION,
            "create-or-extend-tables");
    return map;
}
 
Example #22
Source File: JpaConfiguration.java    From example-ddd-with-spring-data-jpa with Apache License 2.0 5 votes vote down vote up
@Bean
protected Map<String, Object> getVendorProperties() {
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put(PersistenceUnitProperties.WEAVING, Boolean.FALSE.toString());
    map.put(PersistenceUnitProperties.LOGGING_LEVEL, "FINE");
    return map;
}
 
Example #23
Source File: EclipseLinkJpaVendorAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> getJpaPropertyMap() {
	Map<String, Object> jpaProperties = new HashMap<String, Object>();

	if (getDatabasePlatform() != null) {
		jpaProperties.put(PersistenceUnitProperties.TARGET_DATABASE, getDatabasePlatform());
	}
	else if (getDatabase() != null) {
		String targetDatabase = determineTargetDatabaseName(getDatabase());
		if (targetDatabase != null) {
			jpaProperties.put(PersistenceUnitProperties.TARGET_DATABASE, targetDatabase);
		}
	}

	if (isGenerateDdl()) {
		jpaProperties.put(PersistenceUnitProperties.DDL_GENERATION,
				PersistenceUnitProperties.CREATE_ONLY);
		jpaProperties.put(PersistenceUnitProperties.DDL_GENERATION_MODE,
				PersistenceUnitProperties.DDL_DATABASE_GENERATION);
	}
	if (isShowSql()) {
		jpaProperties.put(PersistenceUnitProperties.CATEGORY_LOGGING_LEVEL_ +
				org.eclipse.persistence.logging.SessionLog.SQL, Level.FINE.toString());
	}

	return jpaProperties;
}
 
Example #24
Source File: EclipseLinkJpaVendorAdapter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String, Object> getJpaPropertyMap() {
	Map<String, Object> jpaProperties = new HashMap<String, Object>();

	if (getDatabasePlatform() != null) {
		jpaProperties.put(PersistenceUnitProperties.TARGET_DATABASE, getDatabasePlatform());
	}
	else if (getDatabase() != null) {
		String targetDatabase = determineTargetDatabaseName(getDatabase());
		if (targetDatabase != null) {
			jpaProperties.put(PersistenceUnitProperties.TARGET_DATABASE, targetDatabase);
		}
	}

	if (isGenerateDdl()) {
		jpaProperties.put(PersistenceUnitProperties.DDL_GENERATION,
				PersistenceUnitProperties.CREATE_ONLY);
		jpaProperties.put(PersistenceUnitProperties.DDL_GENERATION_MODE,
				PersistenceUnitProperties.DDL_DATABASE_GENERATION);
	}
	if (isShowSql()) {
		jpaProperties.put(PersistenceUnitProperties.CATEGORY_LOGGING_LEVEL_ +
				org.eclipse.persistence.logging.SessionLog.SQL, Level.FINE.toString());
	}

	return jpaProperties;
}
 
Example #25
Source File: WsMasterModule.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
private void configureMultiUserMode(
    Map<String, String> persistenceProperties, String infrastructure) {
  if (OpenShiftInfrastructure.NAME.equals(infrastructure)
      || KubernetesInfrastructure.NAME.equals(infrastructure)) {
    install(new ReplicationModule(persistenceProperties));
    bind(
        org.eclipse.che.multiuser.permission.workspace.infra.kubernetes
            .BrokerServicePermissionFilter.class);
    configureJwtProxySecureProvisioner(infrastructure);
  } else {
    bind(RemoteSubscriptionStorage.class)
        .to(org.eclipse.che.api.core.notification.InmemoryRemoteSubscriptionStorage.class);
    bind(WorkspaceLockService.class)
        .to(org.eclipse.che.api.workspace.server.DefaultWorkspaceLockService.class);
    bind(WorkspaceStatusCache.class)
        .to(org.eclipse.che.api.workspace.server.DefaultWorkspaceStatusCache.class);
  }

  if (OpenShiftInfrastructure.NAME.equals(infrastructure)) {
    bind(OpenShiftClientConfigFactory.class).to(IdentityProviderConfigFactory.class);
  }

  persistenceProperties.put(
      PersistenceUnitProperties.EXCEPTION_HANDLER_CLASS,
      "org.eclipse.che.core.db.postgresql.jpa.eclipselink.PostgreSqlExceptionHandler");

  bind(TemplateProcessor.class).to(STTemplateProcessorImpl.class);
  bind(DataSource.class).toProvider(org.eclipse.che.core.db.JndiDataSourceProvider.class);

  install(new org.eclipse.che.multiuser.api.permission.server.jpa.SystemPermissionsJpaModule());
  install(new org.eclipse.che.multiuser.api.permission.server.PermissionsModule());
  install(
      new org.eclipse.che.multiuser.permission.workspace.server.WorkspaceApiPermissionsModule());
  install(
      new org.eclipse.che.multiuser.permission.workspace.server.jpa
          .MultiuserWorkspaceJpaModule());
  install(new MultiUserWorkspaceActivityModule());

  // Permission filters
  bind(org.eclipse.che.multiuser.permission.system.SystemServicePermissionsFilter.class);
  bind(org.eclipse.che.multiuser.permission.system.JvmServicePermissionsFilter.class);
  bind(
      org.eclipse.che.multiuser.permission.system.SystemEventsSubscriptionPermissionsCheck.class);

  Multibinder<String> binder =
      Multibinder.newSetBinder(binder(), String.class, Names.named(SYSTEM_DOMAIN_ACTIONS));
  binder.addBinding().toInstance(UserServicePermissionsFilter.MANAGE_USERS_ACTION);
  bind(org.eclipse.che.multiuser.permission.user.UserProfileServicePermissionsFilter.class);
  bind(org.eclipse.che.multiuser.permission.user.UserServicePermissionsFilter.class);
  bind(org.eclipse.che.multiuser.permission.logger.LoggerServicePermissionsFilter.class);

  bind(org.eclipse.che.multiuser.permission.factory.FactoryPermissionsFilter.class);
  bind(org.eclipse.che.multiuser.permission.devfile.DevfilePermissionsFilter.class);
  bind(org.eclipse.che.multiuser.permission.workspace.activity.ActivityPermissionsFilter.class);
  bind(AdminPermissionInitializer.class).asEagerSingleton();
  bind(
      org.eclipse.che.multiuser.permission.resource.filters.ResourceServicePermissionsFilter
          .class);
  bind(
      org.eclipse.che.multiuser.permission.resource.filters
          .FreeResourcesLimitServicePermissionsFilter.class);

  install(new ResourceModule());
  install(new OrganizationApiModule());
  install(new OrganizationJpaModule());

  install(new KeycloakModule());

  install(new MachineAuthModule());
  bind(RequestTokenExtractor.class).to(ChainedTokenExtractor.class);

  // User and profile - use profile from keycloak and other stuff is JPA
  bind(PasswordEncryptor.class).to(PBKDF2PasswordEncryptor.class);
  bind(UserDao.class).to(JpaUserDao.class);
  bind(PreferenceDao.class).to(JpaPreferenceDao.class);
  bind(PermissionChecker.class).to(PermissionCheckerImpl.class);

  bindConstant().annotatedWith(Names.named("che.agents.auth_enabled")).to(true);
}
 
Example #26
Source File: ElexisEntityManger.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public synchronized EntityManager getEntityManager(boolean managed){
	// do lazy initialization on first access
	if (factory == null) {
		// try to initialize
		if (factoryBuilder != null) {
			// make sure database is up to date
			LiquibaseDBInitializer initializer = new LiquibaseDBInitializer(dataSource);
			initializer.init();
			LiquibaseDBUpdater updater = new LiquibaseDBUpdater(dataSource);
			updater.update();
			// initialize the entity manager factory
			HashMap<String, Object> props = new HashMap<String, Object>();
			props.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.NONE);
			props.put("gemini.jpa.providerConnectedDataSource", dataSource);
			props.put("javax.persistence.nonJtaDataSource", dataSource);
			// we keep EntityManager instances possibly for the whole application lifecycle
			// so enable GC to clear entities from EntityManager cache
			props.put(EntityManagerProperties.PERSISTENCE_CONTEXT_REFERENCE_MODE, "WEAK");
			this.factory = factoryBuilder.createEntityManagerFactory(props);
		} else {
			throw new IllegalStateException("No EntityManagerFactoryBuilder available");
		}
	}
	
	if (factory != null) {
		if (managed) {
			EntityManager em = threadLocal.get();
			if (em == null || !em.isOpen()) {
				em = createManagedEntityManager();
			} else {
				// save happens in separate EntityManager
				// clear L1 cache, use L2 cache -> detach current L1 cache objects
				em.clear();
			}
			return em;
		} else {
			return factory.createEntityManager();
		}
	} else {
		throw new IllegalStateException("No EntityManagerFactory available");
	}
}
 
Example #27
Source File: EspmJpaConfig.java    From cloud-espm-cloud-native with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String, Object> getVendorProperties() {
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put(PersistenceUnitProperties.WEAVING, getWeavingMode());
    return map;
}
 
Example #28
Source File: EntityManagerFactoryProvider.java    From cloud-sfsf-benefits-ext with Apache License 2.0 4 votes vote down vote up
private EntityManagerFactory createEntityManagerFactory(DataSource dataSource) {
	final Map<Object, Object> properties = new HashMap<>();
	properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, dataSource);
	return Persistence.createEntityManagerFactory("com.sap.hana.cloud.samples.benefits", properties); //$NON-NLS-1$
}
 
Example #29
Source File: DDLGenerator.java    From gazpachoquest with GNU General Public License v3.0 4 votes vote down vote up
public void addHSQLettings(Map<String, String> persistProperties) {
    persistProperties.put(PersistenceUnitProperties.JDBC_DRIVER, "org.hsqldb.jdbcDriver");
    persistProperties.put(PersistenceUnitProperties.JDBC_URL, "jdbc:hsqldb:mem:testdb");
    persistProperties.put(PersistenceUnitProperties.JDBC_USER, "sa");
    persistProperties.put(PersistenceUnitProperties.JDBC_PASSWORD, "");
}
 
Example #30
Source File: DDLGenerator.java    From gazpachoquest with GNU General Public License v3.0 4 votes vote down vote up
public void addPostgresSettings(Map<String, String> persistProperties) {
    persistProperties.put(PersistenceUnitProperties.JDBC_DRIVER, "org.postgresql.Driver");
    persistProperties.put(PersistenceUnitProperties.JDBC_URL, "jdbc:postgresql://localhost:5432/gazpachoquest");
    persistProperties.put(PersistenceUnitProperties.JDBC_USER, "postgres");
    persistProperties.put(PersistenceUnitProperties.JDBC_PASSWORD, "admin");
}