db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql SqlSelectMNStatement.java SqlInsertMNStatement.java SqlDeleteMNStatement.java SqlMNStatement.java
Date Thu, 12 Dec 2002 22:57:36 GMT
brj         2002/12/12 14:57:36

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlSelectMNStatement.java SqlInsertMNStatement.java
                        SqlDeleteMNStatement.java SqlMNStatement.java
  Log:
  refactoring
  
  Revision  Changes    Path
  1.2       +1 -118    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectMNStatement.java
  
  Index: SqlSelectMNStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectMNStatement.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SqlSelectMNStatement.java	8 Dec 2002 13:28:17 -0000	1.1
  +++ SqlSelectMNStatement.java	12 Dec 2002 22:57:35 -0000	1.2
  @@ -54,11 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -import java.sql.Time;
  -import java.util.ArrayList;
  -import java.util.Date;
  -import java.util.List;
  -
   import org.apache.ojb.broker.util.logging.Logger;
   
   /**
  @@ -97,117 +92,5 @@
   
   		return stmt.toString();
   	}
  -
  -    /**
  -     * Appends to the statement a comma separated list of column names.
  -     *
  -     * @param columns defines the columns to be selected (for reports)
  -     * @return list of column names
  -     */
  -    private List appendListOfColumns(String[] columns, StringBuffer stmt)
  -    {
  -        ArrayList columnList = new ArrayList();
  -
  -        for (int i = 0; i < columns.length; i++)
  -        {
  -            if (i > 0)
  -            {
  -                stmt.append(",");
  -            }
  -            stmt.append(columns[i]);
  -            columnList.add(columns[i]);
  -        }
  -        return columnList;
  -    }
  -
  -	/**
  -	 * applies single quotes to DATE, TIME, CHAR, or STRING columns
  -	 */
  -	protected static String quoteIfNeeded(String str, String dbtype)
  -	{
  -		String[] quotables = { "DATE", "TIME", "CHAR", "STRING" };
  -		boolean test = false;
  -		for (int i = 0; i < quotables.length; i++)
  -		{
  -			if (dbtype.startsWith(quotables[i]))
  -			{
  -				test = true;
  -				break;
  -			}
  -		}
  -		if (test)
  -		{
  -			str = escapeSingleQuotes(str);
  -			return "'" + str + "'";
  -		}
  -		else
  -		{
  -			return str;
  -		}
  -	}
  -
  -	/**
  -	 * replace single quotes (') by an escape sequence (\')
  -	 *
  -	 */
  -	private static String escapeSingleQuotes(String str)
  -	{
  -		String result = str;
  -		if (str.indexOf("'") != -1)
  -		{
  -			StringBuffer buf = new StringBuffer();
  -			char c;
  -			for (int i = 0; i < str.length(); i++)
  -			{
  -				c = str.charAt(i);
  -				if (c == '\'')
  -				{
  -					buf.append("\\'");
  -				}
  -				else
  -				{
  -					buf.append(c);
  -				}
  -			}
  -			result = buf.toString();
  -		}
  -		return result;
  -	}
  -
  -	/**
  -	 * Generate a sql where-clause matching the contraints defined by the vector of
  -	 * Values given for the vector of fields
  -	 *
  -	 * @param vecFields vector containing all columns used in WHERE clause
  -	 * @param vecValues vector containing the Values for the above columns,
  -	 *          if vecValues == null, a prepared Statement clause is generated
  -	 */
  -	private void appendWhereClause(Object[] values, StringBuffer stmt, Object[] columns)
  -	{
  -		stmt.append(" WHERE ");
  -
  -		for (int i = 0; i < columns.length; i++)
  -		{
  -			Class c = values[i].getClass();
  -			String ct = "noquote";
  -			if (c == String.class || c == char.class || c == Date.class || c == Time.class)
  -			{
  -				ct = "STRING";
  -			}
  -
  -			Object val = quoteIfNeeded(values[i].toString(), ct);
  -
  -			if (i > 0)
  -			{
  -				stmt.append(" AND ");
  -			}
  -			stmt.append("(");
  -			stmt.append(columns[i]);
  -			stmt.append(" = ");
  -			stmt.append(val);
  -			stmt.append(")");
  -		}
  -	}
  -
   
   }
  
  
  
  1.4       +1 -26     jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlInsertMNStatement.java
  
  Index: SqlInsertMNStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlInsertMNStatement.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SqlInsertMNStatement.java	9 Oct 2002 10:46:50 -0000	1.3
  +++ SqlInsertMNStatement.java	12 Dec 2002 22:57:36 -0000	1.4
  @@ -54,9 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -import java.util.ArrayList;
  -import java.util.List;
  -
   import org.apache.ojb.broker.util.logging.Logger;
   
   /**
  @@ -104,28 +101,6 @@
               stmt.append(val);
           }
           stmt.append(" ) ");
  -    }
  -
  -    /**
  -     * Appends to the statement a comma separated list of column names.
  -     *
  -     * @param columns defines the columns to be selected (for reports)
  -     * @return list of column names
  -     */
  -    private List appendListOfColumns(String[] columns, StringBuffer stmt)
  -    {
  -        ArrayList columnList = new ArrayList();
  - 
  -        for (int i = 0; i < columns.length; i++)
  -        {
  -            if (i > 0)
  -            {
  -                stmt.append(",");
  -            }
  -            stmt.append(columns[i]);
  -            columnList.add(columns[i]);
  -        }
  -        return columnList;
       }
   
   	/**
  
  
  
  1.4       +1 -94     jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteMNStatement.java
  
  Index: SqlDeleteMNStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteMNStatement.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SqlDeleteMNStatement.java	9 Oct 2002 10:46:50 -0000	1.3
  +++ SqlDeleteMNStatement.java	12 Dec 2002 22:57:36 -0000	1.4
  @@ -54,9 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -import java.sql.Time;
  -import java.util.Date;
  -
   import org.apache.ojb.broker.util.logging.Logger;
   
   /**
  @@ -90,95 +87,5 @@
   
   		return stmt.toString();
   	}
  -
  -	/**
  -	 * applies single quotes to DATE, TIME, CHAR, or STRING columns
  -	 */
  -	protected static String quoteIfNeeded(String str, String dbtype)
  -	{
  -		String[] quotables = { "DATE", "TIME", "CHAR", "STRING" };
  -		boolean test = false;
  -		for (int i = 0; i < quotables.length; i++)
  -		{
  -			if (dbtype.startsWith(quotables[i]))
  -			{
  -				test = true;
  -				break;
  -			}
  -		}
  -		if (test)
  -		{
  -			str = escapeSingleQuotes(str);
  -			return "'" + str + "'";
  -		}
  -		else
  -		{
  -			return str;
  -		}
  -	}
  -
  -	/**
  -	 * replace single quotes (') by an escape sequence (\')
  -	 *
  -	 */
  -	private static String escapeSingleQuotes(String str)
  -	{
  -		String result = str;
  -		if (str.indexOf("'") != -1)
  -		{
  -			StringBuffer buf = new StringBuffer();
  -			char c;
  -			for (int i = 0; i < str.length(); i++)
  -			{
  -				c = str.charAt(i);
  -				if (c == '\'')
  -				{
  -					buf.append("\\'");
  -				}
  -				else
  -				{
  -					buf.append(c);
  -				}
  -			}
  -			result = buf.toString();
  -		}
  -		return result;
  -	}
  -
  -	/**
  -	 * Generate a sql where-clause matching the contraints defined by the vector of
  -	 * Values given for the vector of fields
  -	 *
  -	 * @param vecFields vector containing all columns used in WHERE clause
  -	 * @param vecValues vector containing the Values for the above columns,
  -	 *          if vecValues == null, a prepared Statement clause is generated
  -	 */
  -	private void appendWhereClause(Object[] values, StringBuffer stmt, Object[] columns)
  -	{
  -		stmt.append(" WHERE ");
  -
  -		for (int i = 0; i < columns.length; i++)
  -		{
  -			Class c = values[i].getClass();
  -			String ct = "noquote";
  -			if (c == String.class || c == char.class || c == Date.class || c == Time.class)
  -			{
  -				ct = "STRING";
  -			}
  -
  -			Object val = quoteIfNeeded(values[i].toString(), ct);
  -
  -			if (i > 0)
  -			{
  -				stmt.append(" AND ");
  -			}
  -			stmt.append("(");
  -			stmt.append(columns[i]);
  -			stmt.append(" = ");
  -			stmt.append(val);
  -			stmt.append(")");
  -		}
  -	}
  -
   
   }
  
  
  
  1.4       +118 -1    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlMNStatement.java
  
  Index: SqlMNStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlMNStatement.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SqlMNStatement.java	9 Oct 2002 10:46:50 -0000	1.3
  +++ SqlMNStatement.java	12 Dec 2002 22:57:36 -0000	1.4
  @@ -1,5 +1,10 @@
   package org.apache.ojb.broker.accesslayer.sql;
   
  +import java.sql.Time;
  +import java.util.ArrayList;
  +import java.util.Date;
  +import java.util.List;
  +
   import org.apache.ojb.broker.util.logging.Logger;
   
   /* ====================================================================
  @@ -124,6 +129,118 @@
   	protected Logger getLogger()
   	{
   		return m_logger;
  +	}
  +
  +	/**
  +	 * applies single quotes to DATE, TIME, CHAR, or STRING columns
  +	 */
  +	protected static String quoteIfNeeded(String str, String dbtype)
  +	{
  +		String[] quotables = { "DATE", "TIME", "CHAR", "STRING" };
  +		boolean test = false;
  +		for (int i = 0; i < quotables.length; i++)
  +		{
  +			if (dbtype.startsWith(quotables[i]))
  +			{
  +				test = true;
  +				break;
  +			}
  +		}
  +		if (test)
  +		{
  +			str = escapeSingleQuotes(str);
  +			return "'" + str + "'";
  +		}
  +		else
  +		{
  +			return str;
  +		}
  +	}
  +
  +	/**
  +	 * replace single quotes (') by an escape sequence (\')
  +	 *
  +	 */
  +	private static String escapeSingleQuotes(String str)
  +	{
  +		String result = str;
  +		if (str.indexOf("'") != -1)
  +		{
  +			StringBuffer buf = new StringBuffer();
  +			char c;
  +			for (int i = 0; i < str.length(); i++)
  +			{
  +				c = str.charAt(i);
  +				if (c == '\'')
  +				{
  +					buf.append("\\'");
  +				}
  +				else
  +				{
  +					buf.append(c);
  +				}
  +			}
  +			result = buf.toString();
  +		}
  +		return result;
  +	}
  +
  +	/**
  +	 * Generate a sql where-clause matching the contraints defined by the vector of
  +	 * Values given for the vector of fields
  +	 *
  +	 * @param vecFields vector containing all columns used in WHERE clause
  +	 * @param vecValues vector containing the Values for the above columns,
  +	 *          if vecValues == null, a prepared Statement clause is generated
  +	 */
  +	protected void appendWhereClause(Object[] values, StringBuffer stmt, Object[] columns)
  +	{
  +		stmt.append(" WHERE ");
  +	
  +		for (int i = 0; i < columns.length; i++)
  +		{
  +			Class c = values[i].getClass();
  +			String ct = "noquote";
  +			if (c == String.class || c == char.class || c == Date.class || c == Time.class)
  +			{
  +				ct = "STRING";
  +			}
  +	
  +			Object val = SqlMNStatement.quoteIfNeeded(values[i].toString(), ct);
  +	
  +			if (i > 0)
  +			{
  +				stmt.append(" AND ");
  +			}
  +			stmt.append("(");
  +			stmt.append(columns[i]);
  +			stmt.append(" = ");
  +			stmt.append(val);
  +			stmt.append(")");
  +		}
  +	}
  +
  +	/**
  +	 * Appends to the statement a comma separated list of column names.
  +	 *
  +	 * @param columns defines the columns to be selected (for reports)
  +	 * @return list of column names
  +	 */
  +	protected List appendListOfColumns(String[] columns, StringBuffer stmt)
  +	{
  +	    ArrayList columnList = new ArrayList();
  +	
  +	    for (int i = 0; i < columns.length; i++)
  +	    {
  +	        if (i > 0)
  +	        {
  +	            stmt.append(",");
  +	        }
  +	        stmt.append(columns[i]);
  +	        columnList.add(columns[i]);
  +	    }
  +	    return columnList;
  +	
   	}    
   
   
  
  
  

Mime
View raw message