Package org.gdbms.engine.strategies

Source Code of org.gdbms.engine.strategies.AggregateDataSource

package org.gdbms.engine.strategies;

import org.gdbms.engine.data.DataSource;
import org.gdbms.engine.data.driver.DriverException;
import org.gdbms.engine.data.metadata.Metadata;
import org.gdbms.engine.data.persistence.Memento;
import org.gdbms.engine.data.persistence.MementoException;
import org.gdbms.engine.values.Value;


/**
* @author Fernando Gonz�lez Cort�s
*/
public class AggregateDataSource extends OperationDataSource implements DataSource {
   
    private Value[] values;
    private String[] names;

    /**
     * @param aggregateds
     */
    public AggregateDataSource(Value[] aggregateds) {
        this.values = aggregateds;
        names = new String[aggregateds.length];
        for (int i = 0; i < names.length; i++) {
            names[i] = "expr" + i;
        }
    }

    /**
     * @see org.gdbms.engine.data.DataSource#start()
     */
    public void start() throws DriverException {
    }

    /**
     * @see org.gdbms.engine.data.DataSource#stop()
     */
    public void stop() throws DriverException {
    }

    /**
     * @see org.gdbms.engine.data.DataSource#getMemento()
     */
    public Memento getMemento() throws MementoException {
        throw new UnsupportedOperationException();
    }

    /**
     * @see org.gdbms.engine.data.driver.ReadAccess#getFieldValue(long, int)
     */
    public Value getFieldValue(long rowIndex, int fieldId)
            throws DriverException {
        return values[fieldId];
    }

    /**
     * @see org.gdbms.engine.data.driver.ReadAccess#getFieldCount()
     */
    public int getFieldCount() throws DriverException {
        return values.length;
    }

    /**
     * @see org.gdbms.engine.data.driver.ReadAccess#getRowCount()
     */
    public long getRowCount() throws DriverException {
        return 1;
    }

    public Metadata getDataSourceMetadata() throws DriverException {
        return new Metadata() {
       
            public Boolean isReadOnly(int fieldId) throws DriverException {
                return true;
            }
       
            public String[] getPrimaryKey() throws DriverException {
                return new String[0];
            }
       
            public String getFieldName(int fieldId) throws DriverException {
                return names[fieldId];
            }
       
            public int getFieldType(int fieldId) throws DriverException {
                return values[fieldId].getType();
            }
       
            public int getFieldCount() throws DriverException {
                return names.length;
            }
       
        };
    }

  public boolean isOpen() {
    return true;
  }
}
TOP

Related Classes of org.gdbms.engine.strategies.AggregateDataSource

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.