mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-29 10:43:06 +08:00
refactor(postgresql): Optimize sequence-related functions and code structures
This commit is contained in:
@ -347,8 +347,8 @@ public class PostgreSQLMetaData extends DefaultMetaService implements MetaData {
|
||||
|
||||
stringBuilder.append(CREATE_SEQUENCE).append(getMetaDataName(nspname, relname)).append(NEW_LINE);
|
||||
|
||||
if (databaseProductVersion >= 10.0) {
|
||||
stringBuilder.append(AS).append(getMetaDataName(typname)).append(NEW_LINE);
|
||||
if (Double.compare(databaseProductVersion, 10.0) >= 0) {
|
||||
stringBuilder.append(AS).append(typname).append(NEW_LINE);
|
||||
}
|
||||
|
||||
Optional.ofNullable(seqstart).ifPresent(v -> stringBuilder.append(START_WITH).append(v).append(NEW_LINE));
|
||||
@ -375,7 +375,7 @@ public class PostgreSQLMetaData extends DefaultMetaService implements MetaData {
|
||||
|
||||
Optional.ofNullable(rolname).ifPresent(v -> stringBuilder.append(ALTER_SEQUENCE)
|
||||
.append(getMetaDataName(nspname, relname))
|
||||
.append(OWNED_BY).append(getMetaDataName(v)).append(SEMICOLON));
|
||||
.append(OWNER_TO).append(getMetaDataName(v)).append(SEMICOLON));
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
});
|
||||
|
@ -242,11 +242,11 @@ public class PostgreSQLSqlBuilder extends DefaultSqlBuilder {
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public String buildCreateSequenceSql(Sequence sequence) {
|
||||
|
||||
Double databaseProductVersion = Double.valueOf(Chat2DBContext.getConnection().getMetaData().getDatabaseProductVersion());
|
||||
|
||||
double databaseProductVersion = Double.parseDouble(Chat2DBContext.getConnection().getMetaData().getDatabaseProductVersion());
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
sqlBuilder.append(CREATE_SEQUENCE).append(getMetaDataName(sequence.getNspname(), sequence.getRelname())).append("\n ");
|
||||
if (databaseProductVersion >= 10.0) {
|
||||
if (Double.compare(databaseProductVersion, 10.0) >= 0) {
|
||||
sqlBuilder.append(AS).append(sequence.getTypname()).append("\n ");
|
||||
}
|
||||
Optional.ofNullable(sequence.getSeqstart()).ifPresent(v -> sqlBuilder.append(START_WITH).append(v).append("\n "));
|
||||
@ -273,7 +273,7 @@ public class PostgreSQLSqlBuilder extends DefaultSqlBuilder {
|
||||
|
||||
Optional.ofNullable(sequence.getRolname()).ifPresent(v -> sqlBuilder.append(ALTER_SEQUENCE)
|
||||
.append(getMetaDataName(sequence.getNspname(), sequence.getRelname()))
|
||||
.append(OWNED_BY).append(getMetaDataName(v)).append(SEMICOLON));
|
||||
.append(OWNER_TO).append(getMetaDataName(v)).append(SEMICOLON));
|
||||
return sqlBuilder.toString();
|
||||
}
|
||||
|
||||
|
@ -12,14 +12,14 @@ public class SequenceCommonConst {
|
||||
}
|
||||
|
||||
public static final String CREATE_SEQUENCE = "CREATE SEQUENCE ";
|
||||
public static final String START_WITH = " START WITH ";
|
||||
public static final String INCREMENT_BY = " INCREMENT BY ";
|
||||
public static final String MAXVALUE = " MAXVALUE ";
|
||||
public static final String MINVALUE = " MINVALUE ";
|
||||
public static final String CYCLE = " CYCLE ";
|
||||
public static final String NO_CYCLE = " NO CYCLE ";
|
||||
public static final String CACHE = " CACHE ";
|
||||
public static final String RESTART_WITH = " RESTART WITH ";
|
||||
public static final String START_WITH = "\tSTART WITH ";
|
||||
public static final String INCREMENT_BY = "\tINCREMENT BY ";
|
||||
public static final String MAXVALUE = "\tMAXVALUE ";
|
||||
public static final String MINVALUE = "\tMINVALUE ";
|
||||
public static final String CYCLE = "\tCYCLE ";
|
||||
public static final String NO_CYCLE = "\tNO CYCLE ";
|
||||
public static final String CACHE = "\tCACHE ";
|
||||
public static final String RESTART_WITH = "\tRESTART WITH ";
|
||||
public static final String ALTER_SEQUENCE = "ALTER SEQUENCE ";
|
||||
public static final String COMMENT_ON_SEQUENCE = "COMMENT ON SEQUENCE ";
|
||||
public static final String RENAME_TO = " RENAME TO ";
|
||||
|
Reference in New Issue
Block a user