Package org.jpox.store.rdbms

Source Code of org.jpox.store.rdbms.SQLWarnings

/**********************************************************************
Copyright (c) 2003 Andy Jefferson and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributors:
    ...
**********************************************************************/
package org.jpox.store.rdbms;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import java.sql.SQLWarning;

import org.jpox.exceptions.JPOXDataStoreException;
import org.jpox.util.JPOXLogger;
import org.jpox.util.Localiser;

/**
* Utilities for handling SQL Warnings
*
* @version $Revision: 1.1 $
**/
public class SQLWarnings
{
    private static final Localiser LOCALISER = Localiser.getInstance("org.jpox.store.rdbms.Localisation",
        RDBMSManager.class.getClassLoader());

    /**
     * Logs SQL warnings to the common log.
     * Should be called after any operation on a JDBC <tt>Statement</tt> or <tt>ResultSet</tt> object.
     * @param warning the value returned from getWarnings().
     */
    public static void log(SQLWarning warning)
    {
        while (warning != null)
        {
            JPOXLogger.DATASTORE.warn(LOCALISER.msg("052700", warning));
            warning = warning.getNextWarning();
        }
    }

    /**
     * Utility to log all warning for the specified Connection.
     * @param conn The connection to the datastore
     **/
    public static void log(Connection conn)
    {
        try
        {
            log(conn.getWarnings());
        }
        catch (SQLException e)
        {
            throw new JPOXDataStoreException(LOCALISER.msg("052701",conn),e);
        }
    }

    /**
     * Utility to log all warning for the specified Statement.
     * @param stmt The statement
     **/
    public static void log(Statement stmt)
    {
        try
        {
            log(stmt.getWarnings());
        }
        catch (SQLException e)
        {
            throw new JPOXDataStoreException(LOCALISER.msg("052702",stmt), e);
        }
    }

    /**
     * Utility to log all warning for the specified ResultSet.
     * @param rs The ResultSet
     **/
    public static void log(ResultSet rs)
    {
        try
        {
            log(rs.getWarnings());
        }
        catch (SQLException e)
        {
            throw new JPOXDataStoreException(LOCALISER.msg("052703",rs), e);
        }
    }
}
TOP

Related Classes of org.jpox.store.rdbms.SQLWarnings

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.