AssociationEditorBean.java from Texai at Krugle
Show AssociationEditorBean.java syntax highlighted
/*
* AssociationEditorBean.java
*
* Created on December 11, 2006, 1:11 PM
*
* Description: Edits propositions.
*
* 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.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
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.AbstractReifiedTerm;
import org.texai.kb.entity.AbstractTerm;
import org.texai.util.ByteUtils;
import org.texai.util.TexaiException;
/**
*
* @author reed
*/
@Stateless
public class AssociationEditorBean implements AssociationEditorLocal {
/** the logger */
private transient Logger logger; // NOPMD
/** the entity store */
private EntityStore entityStore;
/** the primary index for binary GAFS */
private transient PrimaryIndex<Integer, BinaryGAF> binaryGAFByTermId;
/** Creates a new instance of AssociationEditorBean. */
public AssociationEditorBean() {
super();
logger = Logger.getLogger(AssociationEditorBean.class.getName());
}
/**
* Persists the given binary ground atomic formula.
*
* @param binaryGAF the given binary ground atomic formula
*/
public void editBinaryGAF(final BinaryGAF binaryGAF) {
//Preconditions
assert binaryGAF != null : "binaryGAF must not be null";
assert binaryGAF.getTermId() != 0 : "binaryGAF term id must not be zero";
try {
binaryGAFByTermId.putNoReturn(binaryGAF);
} catch (final DatabaseException ex) {
throw new TexaiException(ex);
}
getLogger().info("edited: " + binaryGAF);
}
/** 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 {
binaryGAFByTermId = entityStore.getPrimaryIndex(Integer.class, BinaryGAF.class);
} catch (final DatabaseException ex) {
throw new TexaiException(ex);
}
//Postconditions
assert binaryGAFByTermId != null : "binaryGAFByTermId must not be null";
}
/** Gets the logger.
*
* @return the logger
*/
private Logger getLogger() {
if (logger == null) {
logger = Logger.getLogger(TermFinderFacadeBean.class.getName());
}
return logger;
}
}
See more files for this project here