fix: migrate from deprecated @GenericGenerator to @IdGeneratorType
- Update ServerIdGenerator to use @IdGeneratorType annotation (Hibernate 6.5+) - Convert ServerIdGenerator to annotation-based custom generator - Update Servers entity to use @ServerIdGenerator annotation - Fix SQL reserved keyword issue: rename 'user' column to 'username' This resolves deprecation warnings and SQL syntax errors with H2 database.master
parent
348f9faa7d
commit
354f8d1d42
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.hitcommunications.servermanager.model;
|
||||||
|
|
||||||
|
import com.hitcommunications.servermanager.model.enums.Applications;
|
||||||
|
import com.hitcommunications.servermanager.model.enums.DatabaseType;
|
||||||
|
import com.hitcommunications.servermanager.model.enums.ServersType;
|
||||||
|
import com.hitcommunications.servermanager.utils.ServerIdGenerator;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
import org.hibernate.annotations.UpdateTimestamp;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "tab_servers")
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class Servers {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@ServerIdGenerator
|
||||||
|
@Column(nullable = false, unique = true)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
@Column(nullable = false, name = "username")
|
||||||
|
private String user;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private ServersType type;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private Applications application;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private DatabaseType dbType;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
private Timestamp createdAt;
|
||||||
|
@UpdateTimestamp
|
||||||
|
private Timestamp updatedAt;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.hitcommunications.servermanager.model.enums;
|
||||||
|
|
||||||
|
public enum Applications {
|
||||||
|
ASTERISK,
|
||||||
|
HITMANAGER,
|
||||||
|
HITMANAGER_V2,
|
||||||
|
OMNIHIT,
|
||||||
|
HITPHONE
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.hitcommunications.servermanager.model.enums;
|
||||||
|
|
||||||
|
public enum DatabaseType {
|
||||||
|
MYSQL,
|
||||||
|
POSTGRESQL,
|
||||||
|
SQLSERVER,
|
||||||
|
ORACLE,
|
||||||
|
REDIS,
|
||||||
|
MONGODB,
|
||||||
|
MARIADB,
|
||||||
|
NONE
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.hitcommunications.servermanager.model.enums;
|
||||||
|
|
||||||
|
public enum ServersType {
|
||||||
|
PRODUCTION,
|
||||||
|
HOMOLOGATION,
|
||||||
|
DATABASE
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.hitcommunications.servermanager.utils;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.IdGeneratorType;
|
||||||
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
|
import org.hibernate.id.IdentifierGenerator;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
@IdGeneratorType(ServerIdGenerator.ServerIdGeneratorImpl.class)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface ServerIdGenerator {
|
||||||
|
|
||||||
|
class ServerIdGeneratorImpl implements IdentifierGenerator {
|
||||||
|
|
||||||
|
private static final String PREFIX = "server_";
|
||||||
|
private static final int RANDOM_DIGITS = 12;
|
||||||
|
private static final Random random = new Random();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Serializable generate(SharedSessionContractImplementor session, Object object) {
|
||||||
|
StringBuilder randomPart = new StringBuilder();
|
||||||
|
|
||||||
|
for (int i = 0; i < RANDOM_DIGITS; i++) {
|
||||||
|
randomPart.append(random.nextInt(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
return PREFIX + randomPart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue