我正在努力迁移应用程序以使用最新版本的quarkus。该应用程序使用来自休眠接口的数据库策略实现多租户。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);
}
catspeake
相关分类