package com.dbxml.db.core.adapter;

/*
 * dbXML - Native XML Database
 * Copyright (C) 1999-2004  The dbXML Group, L.L.C.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: Adapter.java,v 1.2 2004/02/12 00:17:57 bradford Exp $
 */

import com.dbxml.db.core.Collection;
import com.dbxml.db.core.DBException;
import com.dbxml.db.core.data.Key;
import com.dbxml.db.core.query.ResultSet;
import com.dbxml.db.core.transaction.Transaction;
import com.dbxml.xml.NamespaceMap;

/**
 * Adapter defines an interface that allows adapter facades to be developed
 * in order to allow dbXML to persist objects other than dbXML
 * DocumentTable instances.  These might include DOM Documents, JAXB-generated
 * classes, or XMLSerializable instances.
 */

public interface Adapter {
   /**
    * getCollection returns a reference to the underlying Collection.
    *
    * @return The underlying Collection
    */
   Collection getCollection();
   
   /**
    * getName returns the name for the underlying Collection.
    * <br>
    * ex: ocs
    *
    * @return The name
    */
   public abstract String getName();
   
   /**
    * getCanonicalName returns the canonical name for the underlying
	 * Collection.
    * <br>
    * ex: /local/test/ocs
    *
    * @return The canonical name
    */
   public abstract String getCanonicalName();
	
   /**
    * listKeys returns a list of object keys stored managed by the Adapter.
    *
    * @param tx The controlling Transaction
    * @return the list of object keys
    * @throws DBException If a Database Exception occurs
    */
   Key[] listKeys(Transaction tx) throws DBException;
   
   /**
    * remove removes an object from the Adapter based on its Key.
    *
    * @param tx The controlling Transaction
    * @param key The Object's Key
    * @throws DBException If a Database Exception occurs
    */
   void remove(Transaction tx, Object key) throws DBException;
   
   /**
    * getKeyCount returns the count of objects being maintained
    * by this Adapter.
    *
    * @param tx The controlling Transaction
    * @return The object count
    * @throws DBException If a Database Exception occurs
    */
   long getKeyCount(Transaction tx) throws DBException;
   
   /**
    * queryCollection performs a query against the current collection
    * using the specified style and query String.
    *
    * @param tx The controlling Transaction
    * @param style The query style to use (ex: XPath)
    * @param query The query to execute
    * @param nsMap The namespace Map (if any)
    * @return The resulting ResultSet
    * @throws DBException If a Database Exception occurs
    */
   ResultSet queryCollection(Transaction tx, String style, String query, NamespaceMap nsMap) throws DBException;

   /**
    * queryDocument performs a query against a single Document using
    * the specified style, query string, and Document ID.
    *
    * @param tx The controlling Transaction
    * @param style The query style to use (ex: XPath)
    * @param query The query to execute
    * @param nsMap The namespace Map (if any)
    * @param key The Document to query
    * @return The resulting ResultSet
    * @throws DBException If a Database Exception occurs
    */
   ResultSet queryDocument(Transaction tx, String style, String query, NamespaceMap nsMap, Object key) throws DBException;
   
}

