View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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;
15  
16  import ch.qos.logback.classic.db.names.*;
17  
18  /**
19   * @author Tomasz Nurkiewicz
20   * @since 2010-03-16
21   */
22  public class SQLBuilder {
23  
24      static String buildInsertPropertiesSQL(DBNameResolver dbNameResolver) {
25          StringBuilder sqlBuilder = new StringBuilder("INSERT INTO ");
26          sqlBuilder.append(dbNameResolver.getTableName(TableName.LOGGING_EVENT_PROPERTY)).append(" (");
27          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.EVENT_ID)).append(", ");
28          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.MAPPED_KEY)).append(", ");
29          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.MAPPED_VALUE)).append(") ");
30          sqlBuilder.append("VALUES (?, ?, ?)");
31          return sqlBuilder.toString();
32      }
33  
34      static String buildInsertExceptionSQL(DBNameResolver dbNameResolver) {
35          StringBuilder sqlBuilder = new StringBuilder("INSERT INTO ");
36          sqlBuilder.append(dbNameResolver.getTableName(TableName.LOGGING_EVENT_EXCEPTION)).append(" (");
37          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.EVENT_ID)).append(", ");
38          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.I)).append(", ");
39          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.TRACE_LINE)).append(") ");
40          sqlBuilder.append("VALUES (?, ?, ?)");
41          return sqlBuilder.toString();
42      }
43  
44      static String buildInsertSQL(DBNameResolver dbNameResolver) {
45          StringBuilder sqlBuilder = new StringBuilder("INSERT INTO ");
46          sqlBuilder.append(dbNameResolver.getTableName(TableName.LOGGING_EVENT)).append(" (");
47          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.TIMESTMP)).append(", ");
48          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.FORMATTED_MESSAGE)).append(", ");
49          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.LOGGER_NAME)).append(", ");
50          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.LEVEL_STRING)).append(", ");
51          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.THREAD_NAME)).append(", ");
52          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.REFERENCE_FLAG)).append(", ");
53          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG0)).append(", ");
54          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG1)).append(", ");
55          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG2)).append(", ");
56          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG3)).append(", ");
57          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_FILENAME)).append(", ");
58          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_CLASS)).append(", ");
59          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_METHOD)).append(", ");
60          sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_LINE)).append(") ");
61          sqlBuilder.append("VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
62          return sqlBuilder.toString();
63      }
64  }