Skip to content

Commit

Permalink
feat: add setBasicProperty and setSubstitution to HibernateProperties…
Browse files Browse the repository at this point in the history
….java
  • Loading branch information
Panzer1119 committed Aug 5, 2021
1 parent d330a47 commit bbb6e4d
Showing 1 changed file with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,50 @@ public HibernateProperties(Properties basic, Properties substitutions) {
this.substitutions = substitutions;
}

public Properties createProperties() {
public Properties getBasic() {
return basic;
}

public Properties getSubstitutions() {
return basic;
}

public Properties create() {
if (!substitutions.containsKey(KEY_PORT)) {
if (!basic.containsKey(KEY_DEFAULT_PORT)) {
throw new IllegalArgumentException("Missing port definition and default port definition");
}
substitutions.setProperty(KEY_PORT, basic.getProperty(KEY_DEFAULT_PORT));
setSubstitution(KEY_PORT, getBasicProperty(KEY_DEFAULT_PORT));
}
final Properties substitutedProperties = createSubstitutedProperties(basic, substitutions);
checkDefaultValues(substitutedProperties);
return substitutedProperties;
}

public HibernateProperties setBasicProperty(String key, String value) {
basic.setProperty(key, value);
return this;
}

public String getBasicProperty(String key) {
return basic.getProperty(key);
}

public HibernateProperties setDialect(Class<? extends Dialect> dialect) {
basic.setProperty(KEY_HIBERNATE_DIALECT, dialect.getName());
return setBasicProperty(KEY_HIBERNATE_DIALECT, dialect.getName());
}

public HibernateProperties setSubstitution(String key, String value) {
substitutions.setProperty(key, value);
return this;
}

public String getSubstitution(String key) {
return substitutions.getProperty(key);
}

public HibernateProperties setHost(String host) {
substitutions.setProperty(KEY_HOST, host);
return this;
return setSubstitution(KEY_HOST, host);
}

public HibernateProperties setPort(Integer port) {
Expand All @@ -149,23 +173,19 @@ public HibernateProperties setPort(Integer port) {
}
port = Integer.parseInt(basic.getProperty(KEY_PORT));
}
substitutions.setProperty(KEY_PORT, "" + port);
return this;
return setSubstitution(KEY_PORT, "" + port);
}

public HibernateProperties setDatabase(String database) {
substitutions.setProperty(KEY_DATABASE, database);
return this;
return setSubstitution(KEY_DATABASE, database);
}

public HibernateProperties setUsername(String username) {
substitutions.setProperty(KEY_USERNAME, username);
return this;
return setSubstitution(KEY_USERNAME, username);
}

public HibernateProperties setPassword(String password) {
substitutions.setProperty(KEY_PASSWORD, password);
return this;
return setSubstitution(KEY_PASSWORD, password);
}

}

0 comments on commit bbb6e4d

Please sign in to comment.