gpt4 book ai didi

java - Multi-Tenancy 迁移以使用 quarkus

转载 作者:行者123 更新时间:2023-12-04 15:41:56 26 4
gpt4 key购买 nike

我正在努力迁移应用程序以使用最新版本的 quarkus。该应用使用来自 hibernate 接口(interface)的数据库策略实现 Multi-Tenancy 。 Quarkus 建议(如果可能) 避免使用persistence.xml,在给定 quarkus 上下文 ?保留 persistence.xml 还是仅使用 quarkus 推荐的 application.properties

@Singleton
public class HibernateConnectionProviderFactory implements ConnectionProviderFactory {
private Logger logger = Logger.getLogger(getClass().getName());

private static final String TENANT_ID_PLACEHOLDER = "{tenant.id}";

@Inject
@SystemProperty("multitenant.hibernate.connection.url")
private Optional<String> dbUrl;

@Inject
@SystemProperty("multitenant.hibernate.connection.driver_class")
private Optional<String> dbDriverClass;

@Inject
@SystemProperty("multitenant.hibernate.dialect")
private Optional<String> dbDialect;

@Inject
@SystemProperty("multitenant.hibernate.connection.username")
private Optional<String> dbUsername;

@Inject
@SystemProperty("multitenant.hibernate.connection.password")
private Optional<String> dbPassword;

@Inject
@SystemProperty(value = "multitenant.hibernate.schema.generation", defaultValue = "false")
private boolean generateSchema;

@Inject
@SystemProperty("multitenant.default.tenant.id")
private Optional<String> defaultTenantId;

@Inject
private PersistenceUnitDescriptorFactory persistenceUnitDescriptorFactory;

@Inject
private SchemaGenerator schemaGenerator;

private final ConcurrentHashMap<String, ConnectionProvider> providers = new ConcurrentHashMap<>();


@Override
public Optional<ConnectionProvider> getDefaultConnectionProvider() {
return defaultTenantId.map(this::getConnectionProvider);
}

@Override
public ConnectionProvider getConnectionProvider(String tenantId) {
return providers.computeIfAbsent(tenantId, this::createDriverManagerConnectionProvider);
}


private ConnectionProvider createDriverManagerConnectionProvider(String tenantId) {
final PersistenceUnitDescriptor persistenceUnit = persistenceUnitDescriptorFactory.getPersistenceUnitDescriptor(tenantId);
final Map<Object, Object> persistenceProperties = getPersistenceProperties(tenantId, persistenceUnit.getProperties());
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(persistenceProperties).build();

if (generateSchema) {
schemaGenerator.updateSchema(serviceRegistry, persistenceUnit);
}

final ConnectionProvider connectionProvider = serviceRegistry.getService(ConnectionProvider.class);


return connectionProvider;
}
//...
}

最佳答案

目前我们不支持使用 Quarkus application.properties 设置 Hibernate ORM Multi-Tenancy ,因此您应该采用 persistence.xml 方式。

话虽这么说,但如果有足够的吸引力,我们可能会考虑在未来支持它。您能否在 GitHub 上提出问题,以便我们收集对此功能的反馈?

谢谢!

关于java - Multi-Tenancy 迁移以使用 quarkus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57529731/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com