avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl AbstractColumn.java
Date Wed, 14 Nov 2001 17:05:33 GMT
hammant     01/11/14 09:05:33

  Modified:    apps/db/src/java/org/apache/avalon/db/basic/actions
                        BasicCreateQueryable.java BasicSelect.java
               apps/db/src/java/org/apache/avalon/db/basic/data
                        BasicTable.java
               apps/db/src/java/org/apache/avalon/db/data Column.java
               apps/db/src/java/org/apache/avalon/db/data/impl
                        AbstractColumn.java
  Log:
  Columns are producers of data
  
  Revision  Changes    Path
  1.7       +4 -3      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateQueryable.java
  
  Index: BasicCreateQueryable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicCreateQueryable.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BasicCreateQueryable.java	2001/11/14 02:47:22	1.6
  +++ BasicCreateQueryable.java	2001/11/14 17:05:32	1.7
  @@ -37,7 +37,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   public abstract class BasicCreateQueryable extends AbstractAction implements CreateTable
{
   
  @@ -58,7 +58,7 @@
                   NodeList subColumnsNodes = subRootNodes.item(f).getChildNodes();
                   for (int x = 0 ; x < subColumnsNodes.getLength(); x++) {
                       if (subColumnsNodes.item(x).getNodeName().equals("column")) {
  -                        columns.add(createColumn(subColumnsNodes.item(x)));
  +                        columns.add(createColumn(subColumnsNodes.item(x), x));
                       } else {
                           throw new ActionException("Only 'column' allowed as a node under
'columns' node");
                       }
  @@ -75,7 +75,7 @@
   
       }
   
  -    protected Column createColumn(Node columnNode) throws ActionException {
  +    protected Column createColumn(Node columnNode, int ix) throws ActionException {
           String sqlFieldType = columnNode.getAttributes().getNamedItem("type").getNodeValue();
           String fieldName = columnNode.getAttributes().getNamedItem("name").getNodeValue();
           Column column = null;
  @@ -101,6 +101,7 @@
           } else {
               throw new ActionException("Column type " + sqlFieldType + " not recognised");
           }
  +        column.setIndex(ix);
           return column;
       }
   }
  
  
  
  1.23      +28 -16    jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicSelect.java
  
  Index: BasicSelect.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/BasicSelect.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- BasicSelect.java	2001/11/14 15:57:07	1.22
  +++ BasicSelect.java	2001/11/14 17:05:32	1.23
  @@ -20,6 +20,8 @@
   import org.apache.avalon.db.utils.RhinoHelper;
   import org.apache.avalon.db.utils.StringUtils;
   import org.apache.avalon.db.data.ValidationException;
  +import org.apache.avalon.db.data.Table;
  +import org.apache.avalon.db.data.Column;
   
   import org.apache.avalon.framework.logger.LogEnabled;
   
  @@ -47,7 +49,7 @@
       private int mParamCount;
       private StringBuffer mWhereBuffer = new StringBuffer();
       private BasicTable mTable = null;
  -    private String[] mCols;
  +    private Column[] mCols;
       private String[] mTablenames;
   
       final static String OPERATORS[][] = {
  @@ -67,8 +69,8 @@
   
       public void initialize() throws ActionException {
           getLogger().debug("BasicSelect.initialize()");
  -        mCols = parseSelect(mRootElement);
           mTablenames = parseFrom(mRootElement);
  +        mCols = convertColumns(parseSelect(mRootElement));
           parseLXSQL(mRootElement);
           getLogger().debug("cols.length=" + mCols.length);
           getLogger().debug("tablenames.length=" + mTablenames.length);
  @@ -91,20 +93,13 @@
                   /** iterate rows and select only the needed cols */
                   BasicRow row = (BasicRow)it.next();
                   if (testRow(row)) {
  -                    if(((String)mCols[0]).equals("*")) {
  -                        getLogger().debug("wildcard select");
  -                        selectedRow = new Object[row.getColumsLength()];
  -                        for (int j=0; j < row.getColumsLength(); j++) {
  -                           selectedRow[j] = row.getValue(j);
  -                        }
  -                    } else {
  -                        getLogger().debug("specific select=" + mCols);
  -                        selectedRow = new Object[mCols.length];
  -                        for (int j=0; j < mCols.length; j++) {
  -                            getLogger().debug("mCols[" + j + "]=" + mCols[j]);
  -                            getLogger().debug("row.getValue(mCols[" + j + "]=" + row.getValue(mCols[j]));
  -                            selectedRow[j] = row.getValue(mCols[j]);
  -                        }
  +                    getLogger().debug("specific select=" + mCols);
  +                    selectedRow = new Object[mCols.length];
  +                    for (int j=0; j < mCols.length; j++) {
  +                        getLogger().debug("mCols[" + j + "]=" + mCols[j]);
  +                        Object o = mCols[j].getValue(row);
  +                        getLogger().debug("mCols[j].getValue(row) j=" + j + ", " + o );
  +                        selectedRow[j] = o;
                       }
                       selectedRows.add(selectedRow);
                   }
  @@ -360,4 +355,21 @@
       public void setParamCount(int i) {
           this.mParamCount = i;
       }
  +
  +    protected Column[] convertColumns(String[] columnNames) {
  +
  +        BasicTable table = (BasicTable)mDatabasePersistor.getQueryable(mTablenames[0]);
  +
  +        //TODO * could be with other contrived columns
  +        if (columnNames[0].equals("*")) {
  +            return table.getColumns();
  +        }
  +
  +        Column[] columns = new Column[columnNames.length];
  +        for ( int i = 0; i < columnNames.length; i++ ) {
  +            columns[i] = table.getColumn(columnNames[i], false);
  +        }
  +        return columns;
  +    }
  +
   }
  
  
  
  1.8       +9 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/data/BasicTable.java
  
  Index: BasicTable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/data/BasicTable.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BasicTable.java	2001/11/13 17:58:00	1.7
  +++ BasicTable.java	2001/11/14 17:05:32	1.8
  @@ -26,7 +26,11 @@
           throw new RuntimeException("Column " + columnName + " not found");
       }
   
  +
       public Column getColumn(String columnName) {
  +        return this.getColumn(columnName, true);
  +    }
  +    public Column getColumn(String columnName, boolean throwExcpt) {
           Column col = null;
   
           for (int x = 0; x < mColumns.length; x++) {
  @@ -37,7 +41,11 @@
           if(col != null) {
               return col;
           } else {
  -            throw new RuntimeException("Column " + columnName + " not found");
  +            if (throwExcpt) {
  +                throw new RuntimeException("Column " + columnName + " not found");
  +            } else {
  +                return null;
  +            }
           }
       }
   }
  
  
  
  1.8       +3 -1      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/Column.java
  
  Index: Column.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/Column.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Column.java	2001/11/13 09:25:42	1.7
  +++ Column.java	2001/11/14 17:05:33	1.8
  @@ -14,12 +14,14 @@
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
    * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">g-froehlich@gmx.de</a>
  - * @version * $Revision: 1.7 $
  + * @version * $Revision: 1.8 $
    */
   public interface Column extends Nameable {
   
       void test(Object obj) throws ValidationException;
       Object convertFromString(String str) throws ValidationException;
  +    Object getValue(Row row);
  +    void setIndex(int ix);
   
       String getSQLType();
       String getJavaType();
  
  
  
  1.2       +12 -1     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/AbstractColumn.java
  
  Index: AbstractColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/AbstractColumn.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractColumn.java	2001/11/12 23:09:56	1.1
  +++ AbstractColumn.java	2001/11/14 17:05:33	1.2
  @@ -13,6 +13,7 @@
   import org.apache.avalon.db.data.Table;
   import org.apache.avalon.db.data.Queryable;
   import org.apache.avalon.db.data.Column;
  +import org.apache.avalon.db.data.Row;
   
   
   /**
  @@ -21,13 +22,14 @@
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
    * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">g-froehlich@gmx.de</a>*
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public abstract class AbstractColumn implements Column {
   
       protected String mName;
       protected String mSqlType;
       protected String mJavaType;
  +    protected int mIndex = -1;
   
       /**
        * Constructor AbstractColumn
  @@ -43,6 +45,15 @@
           mName = name;
           mSqlType = sqlType;
           mJavaType = javaType;
  +    }
  +
  +    // TODO can be overriden, or should be overridden
  +    public Object getValue(Row row) {
  +        return row.getValue(mIndex);
  +    }
  +
  +    public void setIndex(int ix) {
  +        mIndex = ix;
       }
   
       /**
  
  
  

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


Mime
View raw message