protected void insertProperties(Map<String, String> mergedMap, Connection connection, long eventId) throws SQLException { Set<String> propertiesKeys = mergedMap.keySet(); if (propertiesKeys.size() > 0) { PreparedStatement insertPropertiesStatement = null; try { insertPropertiesStatement = connection.prepareStatement(insertPropertiesSQL); for (String key : propertiesKeys) { String value = mergedMap.get(key); insertPropertiesStatement.setLong(1, eventId); insertPropertiesStatement.setString(2, key); insertPropertiesStatement.setString(3, value); if (cnxSupportsBatchUpdates) { insertPropertiesStatement.addBatch(); } else { insertPropertiesStatement.execute(); } } if (cnxSupportsBatchUpdates) { insertPropertiesStatement.executeBatch(); } } finally { closeStatement(insertPropertiesStatement); } } }
@Override public void start() { if (dbNameResolver == null) dbNameResolver = new DefaultDBNameResolver(); insertExceptionSQL = SQLBuilder.buildInsertExceptionSQL(dbNameResolver); insertPropertiesSQL = SQLBuilder.buildInsertPropertiesSQL(dbNameResolver); insertSQL = SQLBuilder.buildInsertSQL(dbNameResolver); super.start(); }
@Override public void start() { if (dataSource == null) { addWarn("WARNING: No data source specified"); } else { discoverConnectionProperties(); if (!supportsGetGeneratedKeys() && getSQLDialectCode() == SQLDialectCode.UNKNOWN_DIALECT) { addWarn("Connection does not support GetGeneratedKey method and could not discover the dialect."); } } super.start(); }
/** * Learn relevant information about this connection source. * */ public void discoverConnectionProperties() { Connection connection = null; try { connection = getConnection(); if (connection == null) { addWarn("Could not get a connection"); return; } DatabaseMetaData meta = connection.getMetaData(); DBUtil util = new DBUtil(); util.setContext(getContext()); supportsGetGeneratedKeys = util.supportsGetGeneratedKeys(meta); supportsBatchUpdates = util.supportsBatchUpdates(meta); dialectCode = DBUtil.discoverSQLDialect(meta); addInfo("Driver name="+meta.getDriverName()); addInfo("Driver version="+meta.getDriverVersion()); addInfo("supportsGetGeneratedKeys="+supportsGetGeneratedKeys); } catch (SQLException se) { addWarn("Could not discover the dialect to use.", se); } finally { DBHelper.closeConnection(connection); } }
PreparedStatement insertStatement = null; try { connection = connectionSource.getConnection(); connection.setAutoCommit(false); String EVENT_ID_COL_NAME = "EVENT_ID"; if (connectionSource.getSQLDialectCode() == SQLDialectCode.POSTGRES_DIALECT) { EVENT_ID_COL_NAME = EVENT_ID_COL_NAME.toLowerCase(); insertStatement = connection.prepareStatement(getInsertSQL(), new String[] { EVENT_ID_COL_NAME }); } else { insertStatement = connection.prepareStatement(getInsertSQL()); subAppend(eventObject, connection, insertStatement); eventId = selectEventId(insertStatement, connection); secondarySubAppend(eventObject, connection, eventId); addError("problem appending event", sqle); } finally { DBHelper.closeStatement(insertStatement); DBHelper.closeConnection(connection);
@Override public void start() { if (connectionSource == null) { throw new IllegalStateException( "DBAppender cannot function without a connection source"); } sqlDialect = DBUtil .getDialectFromCode(connectionSource.getSQLDialectCode()); if (getGeneratedKeysMethod() != null) { cnxSupportsGetGeneratedKeys = connectionSource.supportsGetGeneratedKeys(); } else { cnxSupportsGetGeneratedKeys = false; } cnxSupportsBatchUpdates = connectionSource.supportsBatchUpdates(); if (!cnxSupportsGetGeneratedKeys && (sqlDialect == null)) { throw new IllegalStateException( "DBAppender cannot function if the JDBC driver does not support getGeneratedKeys method *and* without a specific SQL dialect"); } // all nice and dandy on the eastern front super.start(); }
public Connection getConnection() throws SQLException { Connection conn = null; try { if (dataSource == null) { dataSource = lookupDataSource(); } if(getUser() != null) { addWarn("Ignoring property [user] with value ["+getUser()+"] for obtaining a connection from a DataSource."); } conn = dataSource.getConnection(); } catch (final NamingException ne) { addError("Error while getting data source", ne); throw new SQLException("NamingException while looking up DataSource: " + ne.getMessage()); } catch (final ClassCastException cce) { addError("ClassCastException while looking up DataSource.", cce); throw new SQLException("ClassCastException while looking up DataSource: " + cce.getMessage()); } return conn; }
if (cnxSupportsGetGeneratedKeys) { try { rs = (ResultSet) getGeneratedKeysMethod().invoke(insertStatement, (Object[]) null); gotGeneratedKeys = true; addWarn( "IllegalAccessException invoking PreparedStatement.getGeneratedKeys", ex); idStatement = connection.createStatement(); idStatement.setMaxRows(1); String selectInsertIdStr = sqlDialect.getSelectInsertId(); rs = idStatement.executeQuery(selectInsertIdStr); DBHelper.closeStatement(idStatement);
/** * @see ch.qos.logback.core.db.ConnectionSource#getConnection() */ public Connection getConnection() throws SQLException { if (dataSource == null) { addError("WARNING: No data source specified"); return null; } if (getUser() == null) { return dataSource.getConnection(); } else { return dataSource.getConnection(getUser(), getPassword()); } }
public void start() { if (jndiLocation == null) { addError("No JNDI location specified for JNDIConnectionSource."); } discoverConnectionProperties(); }
/** * @see ch.qos.logback.core.db.ConnectionSource#getConnection() */ public Connection getConnection() throws SQLException { if (getUser() == null) { return DriverManager.getConnection(url); } else { return DriverManager.getConnection(url, getUser(), getPassword()); } }
public void start() { try { if (driverClass != null) { Class.forName(driverClass); discoverConnectionProperties(); } else { addError("WARNING: No JDBC driver specified for logback DriverManagerConnectionSource."); } } catch (final ClassNotFoundException cnfe) { addError("Could not load JDBC driver class: " + driverClass, cnfe); } }
addWarn("dsClassName is a required parameter"); ec.addError("dsClassName is a required parameter"); ctx.rebind("dataSource", ds); } catch (Exception oops) { addError( "Could not bind datasource. Reported error follows.", oops); ec.addError("Could not not bind datasource of type [" + dsClassName + "].");
private DataSource lookupDataSource() throws NamingException, SQLException { addInfo("Looking up ["+jndiLocation+"] in JNDI"); DataSource ds; Context initialContext = new InitialContext(); Object obj = initialContext.lookup(jndiLocation); // PortableRemoteObject was introduced in JDK 1.3. We won't use it. // ds = (DataSource)PortableRemoteObject.narrow(obj, DataSource.class); ds = (DataSource) obj; if (ds == null) { throw new SQLException("Failed to obtain data source from JNDI location " + jndiLocation); } else { return ds; } } }
@Override public void start() { if (dataSource == null) { addWarn("WARNING: No data source specified"); } else { discoverConnectionProperties(); if (!supportsGetGeneratedKeys() && getSQLDialectCode() == SQLDialectCode.UNKNOWN_DIALECT) { addWarn("Connection does not support GetGeneratedKey method and could not discover the dialect."); } } super.start(); }
protected void insertThrowable(IThrowableProxy tp, Connection connection, long eventId) throws SQLException { PreparedStatement exceptionStatement = null; try { exceptionStatement = connection.prepareStatement(insertExceptionSQL); short baseIndex = 0; while (tp != null) { baseIndex = buildExceptionStatement(tp, baseIndex, exceptionStatement, eventId); tp = tp.getCause(); } if (cnxSupportsBatchUpdates) { exceptionStatement.executeBatch(); } } finally { closeStatement(exceptionStatement); } } }
@Override public void start() { if (dbNameResolver == null) dbNameResolver = new DefaultDBNameResolver(); insertExceptionSQL = SQLBuilder.buildInsertExceptionSQL(dbNameResolver); insertPropertiesSQL = SQLBuilder.buildInsertPropertiesSQL(dbNameResolver); insertSQL = SQLBuilder.buildInsertSQL(dbNameResolver); super.start(); }
@Override public void start() { if (dataSource == null) { addWarn("WARNING: No data source specified"); } else { discoverConnectionProperties(); if (!supportsGetGeneratedKeys() && getSQLDialectCode() == SQLDialectCode.UNKNOWN_DIALECT) { addWarn("Connection does not support GetGeneratedKey method and could not discover the dialect."); } } super.start(); }
protected void insertProperties(Map<String, String> mergedMap, Connection connection, long eventId) throws SQLException { Set<String> propertiesKeys = mergedMap.keySet(); if (propertiesKeys.size() > 0) { PreparedStatement insertPropertiesStatement = null; try { insertPropertiesStatement = connection .prepareStatement(insertPropertiesSQL); for (String key : propertiesKeys) { String value = mergedMap.get(key); insertPropertiesStatement.setLong(1, eventId); insertPropertiesStatement.setString(2, key); insertPropertiesStatement.setString(3, value); if (cnxSupportsBatchUpdates) { insertPropertiesStatement.addBatch(); } else { insertPropertiesStatement.execute(); } } if (cnxSupportsBatchUpdates) { insertPropertiesStatement.executeBatch(); } } finally { closeStatement(insertPropertiesStatement); } } }
protected void insertThrowable(IThrowableProxy tp, Connection connection, long eventId) throws SQLException { PreparedStatement exceptionStatement = null; try { exceptionStatement = connection.prepareStatement(insertExceptionSQL); short baseIndex = 0; while (tp != null) { baseIndex = buildExceptionStatement(tp, baseIndex, exceptionStatement, eventId); tp = tp.getCause(); } if (cnxSupportsBatchUpdates) { exceptionStatement.executeBatch(); } } finally { closeStatement(exceptionStatement); } } }