001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.db;
015
016import ch.qos.logback.classic.db.names.*;
017
018/**
019 * @author Tomasz Nurkiewicz
020 * @since 2010-03-16
021 */
022public class SQLBuilder {
023
024    static String buildInsertPropertiesSQL(DBNameResolver dbNameResolver) {
025        StringBuilder sqlBuilder = new StringBuilder("INSERT INTO ");
026        sqlBuilder.append(dbNameResolver.getTableName(TableName.LOGGING_EVENT_PROPERTY)).append(" (");
027        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.EVENT_ID)).append(", ");
028        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.MAPPED_KEY)).append(", ");
029        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.MAPPED_VALUE)).append(") ");
030        sqlBuilder.append("VALUES (?, ?, ?)");
031        return sqlBuilder.toString();
032    }
033
034    static String buildInsertExceptionSQL(DBNameResolver dbNameResolver) {
035        StringBuilder sqlBuilder = new StringBuilder("INSERT INTO ");
036        sqlBuilder.append(dbNameResolver.getTableName(TableName.LOGGING_EVENT_EXCEPTION)).append(" (");
037        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.EVENT_ID)).append(", ");
038        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.I)).append(", ");
039        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.TRACE_LINE)).append(") ");
040        sqlBuilder.append("VALUES (?, ?, ?)");
041        return sqlBuilder.toString();
042    }
043
044    static String buildInsertSQL(DBNameResolver dbNameResolver) {
045        StringBuilder sqlBuilder = new StringBuilder("INSERT INTO ");
046        sqlBuilder.append(dbNameResolver.getTableName(TableName.LOGGING_EVENT)).append(" (");
047        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.TIMESTMP)).append(", ");
048        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.FORMATTED_MESSAGE)).append(", ");
049        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.LOGGER_NAME)).append(", ");
050        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.LEVEL_STRING)).append(", ");
051        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.THREAD_NAME)).append(", ");
052        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.REFERENCE_FLAG)).append(", ");
053        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG0)).append(", ");
054        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG1)).append(", ");
055        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG2)).append(", ");
056        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG3)).append(", ");
057        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_FILENAME)).append(", ");
058        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_CLASS)).append(", ");
059        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_METHOD)).append(", ");
060        sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_LINE)).append(") ");
061        sqlBuilder.append("VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
062        return sqlBuilder.toString();
063    }
064}