DatabaseConfigurationImpl.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright © 2019 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.cli.config.impl;
  20. import org.apache.commons.configuration2.Configuration;
  21. import com.l2jserver.cli.config.DatabaseConfiguration;
  22. /**
  23. * Database configuration implementation.
  24. * @author Zoey76
  25. */
  26. public class DatabaseConfigurationImpl implements DatabaseConfiguration {
  27. private static final String PREFIX = ".db.";
  28. private String section;
  29. private Configuration config;
  30. public DatabaseConfigurationImpl(String section, Configuration config) {
  31. this.config = config;
  32. this.section = section;
  33. }
  34. @Override
  35. public String name() {
  36. return config.getString(section + PREFIX + "name");
  37. }
  38. @Override
  39. public String host() {
  40. return config.getString(section + PREFIX + "host");
  41. }
  42. @Override
  43. public int port() {
  44. return config.getInt(section + PREFIX + "port");
  45. }
  46. @Override
  47. public String user() {
  48. return config.getString(section + PREFIX + "user");
  49. }
  50. @Override
  51. public String password() {
  52. return config.getString(section + PREFIX + "password");
  53. }
  54. @Override
  55. public DatabaseConfiguration withName(String name) {
  56. config.setProperty(section + PREFIX + "name", name);
  57. return this;
  58. }
  59. @Override
  60. public DatabaseConfiguration withHost(String host) {
  61. config.setProperty(section + PREFIX + "host", host);
  62. return this;
  63. }
  64. @Override
  65. public DatabaseConfiguration withPort(int port) {
  66. config.setProperty(section + PREFIX + "port", port);
  67. return this;
  68. }
  69. @Override
  70. public DatabaseConfiguration withUser(String user) {
  71. config.setProperty(section + PREFIX + "user", user);
  72. return this;
  73. }
  74. @Override
  75. public DatabaseConfiguration withPassword(String password) {
  76. config.setProperty(section + PREFIX + "password", password);
  77. return this;
  78. }
  79. }