mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
完善hibernate配置
This commit is contained in:
@@ -21,6 +21,7 @@ public class HibernateConfig {
|
||||
@Override
|
||||
public void customize(Map<String, Object> hibernateProperties) {
|
||||
hibernateProperties.put(AvailableSettings.DIALECT, MyPostgreSQLDialect.class.getCanonicalName());
|
||||
// hibernateProperties.put(AvailableSettings.SCHEMA_MANAGEMENT_TOOL, MultithreadHibernateSchemaManagementTool.class.getCanonicalName());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.lihongjie.coal.spring.config;
|
||||
|
||||
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
|
||||
import org.hibernate.tool.schema.internal.HibernateSchemaManagementTool;
|
||||
import org.hibernate.tool.schema.internal.exec.GenerationTarget;
|
||||
import org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase;
|
||||
import org.hibernate.tool.schema.internal.exec.JdbcContext;
|
||||
import org.hibernate.tool.schema.spi.ScriptSourceInput;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinTask;
|
||||
|
||||
public class MultithreadHibernateSchemaManagementTool extends HibernateSchemaManagementTool {
|
||||
|
||||
@Override
|
||||
protected GenerationTarget buildDatabaseTarget(JdbcContext jdbcContext, boolean needsAutoCommit) {
|
||||
return new MTGenerationTargetToDatabase( getDdlTransactionIsolator( jdbcContext ), true, needsAutoCommit );
|
||||
}
|
||||
|
||||
public static class MTGenerationTargetToDatabase extends GenerationTargetToDatabase{
|
||||
|
||||
|
||||
private DdlTransactionIsolator ddlTransactionIsolator;
|
||||
private boolean releaseAfterUse;
|
||||
private boolean autocommit;
|
||||
|
||||
private List<ForkJoinTask> tasks;
|
||||
public MTGenerationTargetToDatabase(DdlTransactionIsolator ddlTransactionIsolator) {
|
||||
super(ddlTransactionIsolator);
|
||||
}
|
||||
|
||||
public MTGenerationTargetToDatabase(DdlTransactionIsolator ddlTransactionIsolator, boolean releaseAfterUse) {
|
||||
super(ddlTransactionIsolator, releaseAfterUse);
|
||||
}
|
||||
|
||||
public MTGenerationTargetToDatabase(DdlTransactionIsolator ddlTransactionIsolator, boolean releaseAfterUse, boolean autocommit) {
|
||||
super(ddlTransactionIsolator, releaseAfterUse, autocommit);
|
||||
this.ddlTransactionIsolator = ddlTransactionIsolator;
|
||||
this.releaseAfterUse = releaseAfterUse;
|
||||
this.autocommit = autocommit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeScript(ScriptSourceInput scriptSource) {
|
||||
super.beforeScript(scriptSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String command) {
|
||||
|
||||
ForkJoinTask<?> task = ForkJoinPool.commonPool().submit(() -> {
|
||||
|
||||
|
||||
GenerationTargetToDatabase database = new GenerationTargetToDatabase(ddlTransactionIsolator, true, autocommit);
|
||||
|
||||
database.prepare();
|
||||
database.accept(command);
|
||||
|
||||
database.release();
|
||||
});
|
||||
|
||||
this.tasks.add(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
|
||||
this.tasks.forEach(x -> {
|
||||
try {
|
||||
x.get();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package cn.lihongjie.coal.user.entity;
|
||||
import cn.lihongjie.coal.role.entity.RoleEntity;
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
@@ -25,30 +26,20 @@ public class UserEntity extends OrgCommonEntity {
|
||||
private String email;
|
||||
|
||||
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
@ManyToMany()
|
||||
@JoinTable(indexes = {@jakarta.persistence.Index(name = "idx_user_roles_users_id", columnList = "users_id"), @jakarta.persistence.Index(name = "idx_user_roles_roles_id", columnList = "roles_id")})
|
||||
private List<RoleEntity> roles;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Comment("机构管理员标识")
|
||||
private Boolean orgAdmin;
|
||||
|
||||
|
||||
|
||||
@Comment("系统管理员标识")
|
||||
private Boolean sysAdmin;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ management:
|
||||
enabled: true
|
||||
readinessstate:
|
||||
enabled: true
|
||||
|
||||
spring:
|
||||
|
||||
|
||||
@@ -81,6 +80,9 @@ spring:
|
||||
enable-statistics: true
|
||||
application:
|
||||
name: coal
|
||||
flyway:
|
||||
enabled: true
|
||||
baseline-on-migrate: true
|
||||
logging:
|
||||
file:
|
||||
path: /data/logs
|
||||
|
||||
Reference in New Issue
Block a user