Code Search for Developers
 
 
  

TermDeleterFacadeBean.java from Texai at Krugle


Show TermDeleterFacadeBean.java syntax highlighted

/*
 * TermDeleterFacadeBean.java
 *
 * Created on October 17, 2006, 3:41 PM
 *
 * Description: Provides methods for deleting terms from the knowledge base and properly
 * cascades deletions to achieve truth maintenance.
 *
 * Copyright (C) 2006 Stephen L. Reed.
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package org.texai.kb.ejb.session.shared;

import com.sleepycat.je.DatabaseException;
import com.sleepycat.persist.EntityStore;
import com.sleepycat.persist.PrimaryIndex;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import org.apache.log4j.Logger;
import org.texai.kb.Constants;
import org.texai.kb.entity.AtomicTerm;
import org.texai.kb.entity.BinaryGAF;
import org.texai.kb.entity.Formula;
import org.texai.kb.entity.NonAtomicTerm;
import org.texai.kb.entity.PByteArray;
import org.texai.kb.entity.PDate;
import org.texai.kb.entity.PDouble;
import org.texai.kb.entity.PLong;
import org.texai.kb.entity.PString;
import org.texai.kb.entity.PVariable;
import org.texai.kb.entity.QuaternaryGAF;
import org.texai.kb.entity.QuintaryGAF;
import org.texai.kb.entity.AbstractReifiedTerm;
import org.texai.kb.entity.Rule;
import org.texai.kb.entity.Symbol;
import org.texai.kb.entity.AbstractTerm;
import org.texai.kb.entity.LocalTermIdReference;
import org.texai.kb.entity.TernaryGAF;
import org.texai.kb.entity.UnaryGAF;
import org.texai.util.TexaiException;

/**
 *
 * @author reed
 */
@Stateless
public class TermDeleterFacadeBean implements TermDeleterFacadeLocal {
  
  /** the entity store */
  private EntityStore entityStore;
  
  /** the primary index for atomic terms */
  private transient PrimaryIndex<Integer, AtomicTerm> atomicTermByTermId;
  
  /** the primary index for unary GAFS */
  private transient PrimaryIndex<Integer, UnaryGAF> unaryGAFByTermId;
  
  /** the primary index for binary GAFS */
  private transient PrimaryIndex<Integer, BinaryGAF> binaryGAFByTermId;
  
  /** the primary index for ternary GAFS */
  private transient PrimaryIndex<Integer, TernaryGAF> ternaryGAFByTermId;
  
  /** the primary index for quaternary GAFS */
  private transient PrimaryIndex<Integer, QuaternaryGAF> quaternaryGAFByTermId;
  
  /** the primary index for quintary GAFS */
  private transient PrimaryIndex<Integer, QuintaryGAF> quintaryGAFByTermId;
  
  /** the primary index for local term id references */
  private transient PrimaryIndex<Integer, LocalTermIdReference> localTermIdReferenceByTermId;
  
  /** the logger */
  private transient Logger logger;               // NOPMD
  
  /** Creates a new instance of TermDeleterFacadeBean */
  public TermDeleterFacadeBean() {
    super();
  }
  
  /** Deletes the given AtomicTerm.
   *
   * @param atomicTerm the given atomic term
   * @return whether the atomic term was found and deleted
   */
  public boolean deleteAtomicTerm(final AtomicTerm atomicTerm) {
    //Preconditions
    assert atomicTerm != null : "atomicTerm must not be null";
    
    getLogger().debug("deleting atomic term: " + atomicTerm);
    boolean isDeleted = false;
    try {
      isDeleted = atomicTermByTermId.delete(atomicTerm.getTermId());
      localTermIdReferenceByTermId.delete(atomicTerm.getTermId());
    } catch (final DatabaseException ex) {
      throw new TexaiException(ex);
    }
    return isDeleted;
  }
  
  /** Deletes the given unary ground atomic formula.
   *
   * @param unaryGAF the given unary ground atomic formula
   */
  public boolean deleteUnaryGAF(final UnaryGAF unaryGAF) {
    //Preconditions
    assert unaryGAF != null : "unaryGAF must not be null";
    
    getLogger().debug("deleting unary GAF: " + unaryGAF);
    boolean isDeleted = false;
    try {
      isDeleted = unaryGAFByTermId.delete(unaryGAF.getTermId());
      localTermIdReferenceByTermId.delete(unaryGAF.getTermId());
    } catch (final DatabaseException ex) {
      throw new TexaiException(ex);
    }
    return isDeleted;
  }
  
  /** Deletes the given binary ground atomic formula.
   *
   * @param binaryGAF the given binary ground atomic formula
   */
  public boolean deleteBinaryGAF(final BinaryGAF binaryGAF) {
    //Preconditions
    assert binaryGAF != null : "binaryGAF must not be null";
    
    getLogger().debug("deleting binary GAF: " + binaryGAF);
    boolean isDeleted = false;
    try {
      isDeleted = binaryGAFByTermId.delete(binaryGAF.getTermId());
      localTermIdReferenceByTermId.delete(binaryGAF.getTermId());
    } catch (final DatabaseException ex) {
      throw new TexaiException(ex);
    }
    return isDeleted;
  }
  
  /** Deletes the given ternary ground atomic formula.
   *
   * @param ternaryGAF the given ternary ground atomic formula
   */
  public boolean deleteTernaryGAF(final TernaryGAF ternaryGAF) {
    //Preconditions
    assert ternaryGAF != null : "ternaryGAF must not be null";
    
    getLogger().debug("deleting ternary GAF: " + ternaryGAF);
    boolean isDeleted = false;
    try {
      isDeleted = ternaryGAFByTermId.delete(ternaryGAF.getTermId());
      localTermIdReferenceByTermId.delete(ternaryGAF.getTermId());
    } catch (final DatabaseException ex) {
      throw new TexaiException(ex);
    }
    return isDeleted;
  }
  
  /** Deletes the given quaternary ground atomic formula.
   *
   * @param quaternaryGAF the given quaternary ground atomic formula
   */
  public boolean deleteQuaternaryGAF(final QuaternaryGAF quaternaryGAF) {
    //Preconditions
    assert quaternaryGAF != null : "quaternaryGAF must not be null";
    
    getLogger().debug("deleting quaternary GAF: " + quaternaryGAF);
    boolean isDeleted = false;
    try {
      isDeleted = quaternaryGAFByTermId.delete(quaternaryGAF.getTermId());
      localTermIdReferenceByTermId.delete(quaternaryGAF.getTermId());
    } catch (final DatabaseException ex) {
      throw new TexaiException(ex);
    }
    return isDeleted;
  }
  
  /** Deletes the given quintary ground atomic formula.
   *
   * @param quintaryGAF the given quintary ground atomic formula
   */
  public boolean deleteQuintaryGAF(final QuintaryGAF quintaryGAF) {
    //Preconditions
    assert quintaryGAF != null : "quintaryGAF must not be null";
    
    getLogger().debug("deleting quintary GAF: " + quintaryGAF);
    boolean isDeleted = false;
    try {
      isDeleted = quintaryGAFByTermId.delete(quintaryGAF.getTermId());
      localTermIdReferenceByTermId.delete(quintaryGAF.getTermId());
    } catch (final DatabaseException ex) {
      throw new TexaiException(ex);
    }
    return isDeleted;
  }
  
  /** Sets the entity store.
   *
   * @param entityStore
   */
  public void setEntityStore(final EntityStore entityStore) {
    //Preconditions
    assert entityStore != null : "entityStore must not be null";
    
    this.entityStore = entityStore;
  }
  
  /** Initializes the primary and secondary indicies. */
  public void initializeIndices() {
    //Preconditions
    assert entityStore != null : "entityStore must not be null";
    
    // primary indicies
    try {
      atomicTermByTermId = entityStore.getPrimaryIndex(Integer.class, AtomicTerm.class);
      unaryGAFByTermId = entityStore.getPrimaryIndex(Integer.class, UnaryGAF.class);
      binaryGAFByTermId = entityStore.getPrimaryIndex(Integer.class, BinaryGAF.class);
      ternaryGAFByTermId = entityStore.getPrimaryIndex(Integer.class, TernaryGAF.class);
      quaternaryGAFByTermId = entityStore.getPrimaryIndex(Integer.class, QuaternaryGAF.class);
      quintaryGAFByTermId = entityStore.getPrimaryIndex(Integer.class, QuintaryGAF.class);
      localTermIdReferenceByTermId = entityStore.getPrimaryIndex(Integer.class, LocalTermIdReference.class);
    } catch (final DatabaseException ex) {
      throw new TexaiException(ex);
    }
    //Postconditions
    assert atomicTermByTermId != null : "atomicTermByTermId must not be null";
    assert unaryGAFByTermId != null : "unaryGAFByTermId must not be null";
    assert binaryGAFByTermId != null : "binaryGAFByTermId must not be null";
    assert ternaryGAFByTermId != null : "ternaryGAFByTermId must not be null";
    assert quaternaryGAFByTermId != null : "quaternaryGAFByTermId must not be null";
    assert quintaryGAFByTermId != null : "quintaryGAFByTermId must not be null";
    assert localTermIdReferenceByTermId != null : "localTermIdReferenceByTermId must not be null";
  }
  
  /** Gets the logger.
   *
   * @return the logger
   */
  private Logger getLogger() {
    if (logger == null) {
      logger = Logger.getLogger(TermDeleterFacadeBean.class.getName());
    }
    return logger;
  }
}




See more files for this project here

Texai

Texai is an chatbot that intelligently seeks to acquire knowledge and friendly behaviors.

Project homepage: http://sourceforge.net/projects/texai
Programming language(s): Java,Shell Script,XML
License: other

  AssociationEditorBean.java
  AssociationEditorLocal.java
  AssociationFinderBean.java
  AssociationFinderLocal.java
  KBPartitionFacadeBean.java
  KBPartitionFacadeLocal.java
  KBShardFacadeBean.java
  TermDeleterFacadeBean.java
  TermDeleterFacadeLocal.java
  TermFinderFacadeBean.java
  TermFinderFacadeLocal.java
  TermManagerBean.java
  TermManagerLocal.java