View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2011, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.db.names;
15  
16  /**
17   * Adds custom prefix/suffix to table and column names.
18   *
19   * @author Tomasz Nurkiewicz
20   * @since 0.9.20
21   */
22  public class SimpleDBNameResolver implements DBNameResolver {
23  
24    private String tableNamePrefix = "";
25  
26    private String tableNameSuffix = "";
27  
28    private String columnNamePrefix = "";
29  
30    private String columnNameSuffix = "";
31  
32    public <N extends Enum<?>> String getTableName(N tableName) {
33      return tableNamePrefix + tableName.name().toLowerCase() + tableNameSuffix;
34    }
35  
36    public <N extends Enum<?>> String getColumnName(N columnName) {
37      return columnNamePrefix + columnName.name().toLowerCase() + columnNameSuffix;
38    }
39  
40    public void setTableNamePrefix(String tableNamePrefix) {
41      this.tableNamePrefix = tableNamePrefix != null? tableNamePrefix : "";
42    }
43  
44    public void setTableNameSuffix(String tableNameSuffix) {
45      this.tableNameSuffix = tableNameSuffix != null? tableNameSuffix : "";
46    }
47  
48    public void setColumnNamePrefix(String columnNamePrefix) {
49      this.columnNamePrefix = columnNamePrefix != null? columnNamePrefix : "";
50    }
51  
52    public void setColumnNameSuffix(String columnNameSuffix) {
53      this.columnNameSuffix = columnNameSuffix != null? columnNameSuffix : "";
54    }
55  }