/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.dynamo.unistore;

import java.util.*;
import com.silverwrist.dynamo.db.OpsBase;
import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*;

abstract class ManagerOps extends OpsBase
{
  /*--------------------------------------------------------------------------------
   * Static data members
   *--------------------------------------------------------------------------------
   */

  static final String PARAM_MSGID   = "msgid";
  static final String PARAM_PARENT  = "parent";
  static final String PARAM_SEQ     = "seq";
  static final String PARAM_CREATOR = "creator";
  static final String PARAM_POSTED  = "posted";
  static final String PARAM_ACLID   = "aclid";

  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private MessageOps m_msgops = null;

  /*--------------------------------------------------------------------------------
   * Constructor
   *--------------------------------------------------------------------------------
   */

  protected ManagerOps(DBConnectionPool pool)
  {
    super(pool);

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Overrides from class OpsBase
   *--------------------------------------------------------------------------------
   */

  public void dispose()
  {
    if (m_msgops!=null)
      m_msgops.dispose();
    m_msgops = null;
    super.dispose();

  } // end dispose

  /*--------------------------------------------------------------------------------
   * Abstract operations
   *--------------------------------------------------------------------------------
   */

  protected abstract MessageOps createMessageOps(DBConnectionPool pool);

  abstract Map getMessageData(long msgid) throws DatabaseException;

  abstract long createMessage(int creator, java.util.Date postdate) throws DatabaseException;

  /*--------------------------------------------------------------------------------
   * External operations
   *--------------------------------------------------------------------------------
   */

  synchronized MessageOps getMessageOps()
  {
    if (m_msgops==null)
      m_msgops = createMessageOps(getPool());
    return m_msgops;

  } // return getMessageOps

  /*--------------------------------------------------------------------------------
   * External static operations
   *--------------------------------------------------------------------------------
   */

  static ManagerOps get(DBConnectionPool pool) throws ConfigException
  {
    return (ManagerOps)get(pool,ManagerOps.class.getClassLoader(),ManagerOps.class.getName() + "_","ManagerOps");

  } // end get

} // end class ManagerOps
