commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hus...@apache.org
Subject cvs commit: jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/sql MockAdaptor.java StorageBeanBase.java StatementUtils.java
Date Fri, 06 Sep 2002 21:47:16 GMT
husted      2002/09/06 14:47:16

  Modified:    scaffold/src/java/org/apache/commons/scaffold/sql
                        StorageBeanBase.java StatementUtils.java
  Added:       scaffold/src/java/org/apache/commons/scaffold/sql
                        MockAdaptor.java
  Log:
  04-SEP-2002
  -----------
  + sql.StorageBeanBase: Add modified, remoteNode, and remoteAddr
  properties (to help manage optimistic locking and/or audting).
  
  28-AUG-2002
  -----------
  + sql.StorageBeanBase: Change TABLE et al to public.
  
  23-AUG-2002
  -----------
  + sql.AccessBase: Revise cast in createKey to avoid going to null.
  + sql.StorageBeanBase: Revise init to support multiple command files.
  + http.SetUp: Add standard servlet for loading a command file.
  + lang.Tokens: Add process complete.
  + sql: Add MockAdaptor
  
  Revision  Changes    Path
  1.6       +143 -31   jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/sql/StorageBeanBase.java
  
  Index: StorageBeanBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/sql/StorageBeanBase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StorageBeanBase.java	23 Aug 2002 14:21:23 -0000	1.5
  +++ StorageBeanBase.java	6 Sep 2002 21:47:16 -0000	1.6
  @@ -2,6 +2,8 @@
   
   
   import java.sql.SQLException;
  +import java.sql.Timestamp;
  +
   import java.util.Collection;
   import java.util.Map;
   import java.util.Properties;
  @@ -112,7 +114,7 @@
       /**
        * [:TODO: Javadoc]
        */
  -    private final static String dot = ".";
  +    public final static String DOT = ".";
   
   
       /**
  @@ -125,7 +127,7 @@
       /**
        * Retrieve command from <code>commands</code> Properties
        */
  -    private final String getCommand(String key)
  +    protected final String getCommand(String key)
           throws PropertiesException {
   
           if (null==commands) throw new PropertiesException();
  @@ -134,7 +136,7 @@
           String prefix = getPrefix();
           if (null!=prefix) {
               StringBuffer sb = new StringBuffer(prefix);
  -            sb.append(dot);
  +            sb.append(DOT);
               sb.append(key);
               command = sb.toString();
           }
  @@ -147,7 +149,7 @@
       /**
        * Retrieve command from <code>commands</code> Properties
        */
  -    private final String getCommandRoot(String key)
  +    protected final String getCommandRoot(String key)
           throws PropertiesException {
   
           if (null==commands) throw new PropertiesException();
  @@ -181,43 +183,43 @@
       /**
        * [:TODO: Javadoc]
        */
  -    private final static String INSERT = "insert";
  +    public final static String INSERT = "insert";
   
   
       /**
        * [:TODO: Javadoc]
        */
  -    private final static String UPDATE = "update";
  +    public final static String UPDATE = "update";
   
   
       /**
        * [:TODO: Javadoc]
        */
  -    private final static String RETRIEVE = "retrieve";
  +    public final static String RETRIEVE = "retrieve";
   
   
       /**
  -     * [:TODO: Javadoc]
  +     * [:TODO: Javadoc] purge
        */
  -    private final static String DELETE = "delete";
  +    public final static String DELETE = "delete";
   
   
       /**
        * [:TODO: Javadoc]
        */
  -    private final static String RESTORE = "restore";
  +    public final static String RESTORE = "restore";
   
   
       /**
  -     * [:TODO: Javadoc]
  +     * [:TODO: Javadoc] delete
        */
  -    private final static String RECYCLE = "recycle";
  +    public final static String RECYCLE = "recycle";
   
   
       /**
        * [:TODO: Javadoc]
        */
  -    private final static String TABLE = "table";
  +    public final static String TABLE = "table";
   
   
       /**
  @@ -453,58 +455,163 @@
   
   // ======================================================== UD Methods
   
  -
       /**
  -     * [:TODO: Javadoc]
  +     * A storage location for the primaryKey object.
  +     * <p>
  +     * Many subclasses may choose to ingore this field and
  +     * use the primaryKey property as a wrapper around
  +     * their own field of a specific type (e.g. Integer).
        */
  -    private int resultCode = 0;
  +    private Object primaryKey = null;
   
   
           // See inteface for JavaDoc
  -    public int getResultCode() {
  -        return resultCode;
  +    public Object getPrimaryKey() {
  +        return this.primaryKey;
       }
   
   
           // See inteface for JavaDoc
  -    public void setResultCode(int resultCode) {
  -        this.resultCode = resultCode;
  +    public void setPrimaryKey(Object primaryKey) {
  +        this.primaryKey = primaryKey;
  +    }
  +
  +
  +    /**
  +     * The timestamp of the last edit.
  +     * <p>
  +     * This can be checked against the edited
  +     * timestamp on the record in storage
  +     * to see if anyone else has alreaded
  +     * edited the record.
  +     */
  +    private Timestamp modified = ConvertUtils.NULL_TIMESTAMP;
  +
  +    /**
  +     * Return the edited timestamp.
  +     * <p>
  +     * @return the edited timestamp.
  +     */
  +    public Timestamp getModified() {
  +        return (this.modified);
  +    }
  +
  +
  +    /**
  +     * Set the edited timestamp.
  +     * @param edited The new edited timestamp.
  +     */
  +    public void setModified(Timestamp modified) {
  +        this.modified = modified;
  +    }
  +
  +
  +    /**
  +     * Check to see if another modified timetamp
  +     * matches the one for this instance.
  +     * Returns true if the timestamps match.
  +     * @returns true if the timestamps match.
  +     * @param edited The new edited timestamp.
  +     */
  +    public boolean isCurrent(Timestamp modified) {
  +        return (modified!=getModified());
  +    }
  +
  +
  +    /**
  +     * The network address of the last editor.
  +     * <p>
  +     * This can be used to track down the
  +     * last editor in case of a conflict.
  +     * To use this feature, record the user's
  +     * ip when they login.
  +     */
  +    private Integer remoteNode = null;
  +
  +
  +    /**
  +     * Return the network address.
  +     * <p>
  +     * @return the network address.
  +     */
  +    public Integer getRemoteNode() {
  +        return (this.remoteNode);
  +    }
  +
  +
  +    /**
  +     * Set the network address.
  +     * @param remoteNode The new remoteNode.
  +     */
  +    public void setRemoteNode(Integer remoteNode) {
  +        this.remoteNode = remoteNode;
  +    }
  +
  +
  +    /**
  +     * Set the networkNode using a String in
  +     * the format usually given
  +     * by the REMOTE_ADDR CGI variable, or
  +     * ServletRequest.getRemoteAddr().
  +     * NOTE: not implemented; returns 0.
  +     * @returns An Integer value based on RemoteAddr string.
  +     */
  +    public void setRemoteAddr(String remoteAddr) {
  +
  +        setRemoteNode(new Integer(0));
  +
  +    }
  +
  +
  +    /**
  +     * Return the String representation
  +     * of an IP address expressed
  +     * as an Integer, into the format usually given
  +     * by the REMOTE_ADDR CGI variable, or
  +     * ServletRequest.getRemoteAddr().
  +     * NOTE: not implemented; returns zeros..
  +     * @returns An Integer value based on RemoteAddr string.
  +     */
  +    public String getRemoteAddr() {
  +
  +        return new String("000.000.000.000");
  +
       }
   
   
       /**
        * [:TODO: Javadoc]
        */
  -    private Object result = this;
  +    private int resultCode = 0;
   
   
           // See inteface for JavaDoc
  -    public Object getResult() {
  -        return result;
  +    public int getResultCode() {
  +        return resultCode;
       }
   
   
           // See inteface for JavaDoc
  -    public void setResult(Object result) {
  -        this.result = result;
  +    public void setResultCode(int resultCode) {
  +        this.resultCode = resultCode;
       }
   
   
       /**
        * [:TODO: Javadoc]
        */
  -    private Object primaryKey = null;
  +    private Object result = this;
   
   
           // See inteface for JavaDoc
  -    public Object getPrimaryKey() {
  -        return this.primaryKey;
  +    public Object getResult() {
  +        return result;
       }
   
   
           // See inteface for JavaDoc
  -    public void setPrimaryKey(Object primaryKey) {
  -        this.primaryKey = primaryKey;
  +    public void setResult(Object result) {
  +        this.result = result;
       }
   
   
  @@ -573,6 +680,11 @@
           }
           else {
               command = getCommand(UPDATE);
  +        }
  +
  +        Timestamp modified = getModified();
  +        if ((null==modified) || (ConvertUtils.NULL_TIMESTAMP==modified)) {
  +            setModified(new Timestamp(System.currentTimeMillis()));
           }
   
           int result = 0;
  
  
  
  1.2       +3 -2      jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/sql/StatementUtils.java
  
  Index: StatementUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/sql/StatementUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StatementUtils.java	14 Aug 2002 17:51:42 -0000	1.1
  +++ StatementUtils.java	6 Sep 2002 21:47:16 -0000	1.2
  @@ -101,8 +101,9 @@
                  result = resultSet.getObject(column);
               }
   
  -        // increment key
  +        // increment key (SQL command handles increment)
           // - int result = executeUpdate(resource,update,key);
  +            if (preparedStatement!=null) preparedStatement.close();
               preparedStatement = connection.prepareStatement(update);
               preparedStatement.setObject(1,key);
               resultCode = preparedStatement.executeUpdate();
  
  
  
  1.1                  jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/sql/MockAdaptor.java
  
  Index: MockAdaptor.java
  ===================================================================
  package org.apache.commons.scaffold.sql;
  
  
  /**
   * MockAdaptor for testing StorageBeans.
   *
   * @author Ted Husted
   * @version $Revision: 1.1 $ $Date: 2002/09/06 21:47:16 $
   */
  
  import java.sql.Connection;
  import java.sql.SQLException;
  import javax.sql.DataSource;
  
  import com.mockobjects.sql.MockDataSource;
  
  
  public class MockAdaptor extends ConnectionAdaptor {
  
  
          // Inherits JavaDoc
      protected DataSource getDataSource(String key)
              throws SQLException {
  
          if (null==datasource) {
              datasource = new MockDataSource();
          }
  
          return datasource;
      }
  
  
  
      /**
       * Set internal datasource field.
       * Call once *before* getPool().
       */
      public void setupDataSource(DataSource datasource) {
  
          this.datasource = datasource;
  
      }
  
  
       // Required
      public MockAdaptor() {
  
          if (null==pool) pool = this;
  
      }
  
  
  } // end MockAdaptor
  
  
  
  
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Scaffold", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message