|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjason.bb.ChainBBAdapter
jason.bb.JDBCPersistentBB
public class JDBCPersistentBB
Implementation of BB that stores some beliefs in a relational data base.
The parameters for this customisation are:
predicate(arity [, table_name [, columns]])
columns( col_name(col_type), col_name(col_type), ....)
Example in .mas2j project, the agent c uses a JDBC belief base:
agents: c beliefBaseClass jason.bb.JDBCPersistentBB( "org.hsqldb.jdbcDriver", // driver for HSQLDB "jdbc:hsqldb:bookstore", // URL connection "sa", // user "", // password "[a(1,tablea,columns(runs(integer))), book(5), book_author(2), author(2,author,columns(id(integer),name(varchar(30)))), publisher(2)]");
The predicate a/1
is mapped to a table called "tablea" with an integer column called runs;
predicate book
(with arity 5) is mapped to a table called "book"; and so on.
The name and type of the columns are used only if the table does not exits and have to be created.
If no column name/type is provided, an arbitrary name is used with type varchar(256).
If no table name is provided, the predicate name is used for the table name.
Field Summary | |
---|---|
protected java.lang.String |
agentName
|
protected java.util.Map<PredicateIndicator,java.sql.ResultSetMetaData> |
belsDB
|
protected java.sql.Connection |
conn
|
protected int |
extraCols
the number of columns that this customisation creates (default is 2: the j_negated and j_annots columns) |
static java.lang.String |
timestampFunctor
|
protected java.lang.String |
url
|
Fields inherited from class jason.bb.ChainBBAdapter |
---|
nextBB |
Fields inherited from interface jason.bb.BeliefBase |
---|
APercept, ASelf, TPercept, TSelf |
Constructor Summary | |
---|---|
JDBCPersistentBB()
|
|
JDBCPersistentBB(BeliefBase next)
|
Method Summary | |
---|---|
boolean |
abolish(PredicateIndicator pi)
Removes all believes with some functor/arity |
boolean |
add(Literal l)
Adds a belief in the end of the BB, returns true if succeed. |
Literal |
contains(Literal l)
Returns the literal l as it is in BB, this method does not consider annotations in the search. |
java.util.Iterator<Literal> |
getCandidateBeliefs(Literal l,
Unifier u)
Returns an iterator for all literals relevant for l's predicate indicator, if l is a var, returns all beliefs. The unifier u may contain values for variables in l. |
protected java.lang.String |
getCountQuery(PredicateIndicator pi)
returns a SQL command to count the number of instances of a predicate |
protected java.lang.String |
getCreateTable(java.lang.String table,
int arity,
Structure columns)
returns the SQL command to create a new table |
protected java.lang.String |
getDeleteAll(PredicateIndicator pi)
returns a SQL command to delete all entries for a predicate |
protected java.lang.String |
getInsert(Literal l)
returns the SQL command to insert l into the DB |
protected java.lang.String |
getSelect(Literal l)
returns the SQL command for a select that retrieves the literal l from the DB |
protected java.lang.String |
getSelectAll(PredicateIndicator pi)
returns the SQL command the selects all literals of type pi |
protected java.lang.String |
getTableName(Literal l)
|
protected java.lang.String |
getTableName(PredicateIndicator pi)
|
protected java.lang.String |
getWhere(Literal l)
returns the where clausule for a select for literal l |
void |
init(Agent ag,
java.lang.String[] args)
Called before the MAS execution with the agent that uses this BB and the args informed in .mas2j project. Example in .mas2j: agent BeliefBaseClass(1,bla); the init args will be ["1", "bla"]. |
protected boolean |
isCreatedByJason(PredicateIndicator pi)
returns true if the table for pi was created by Jason |
protected boolean |
isDB(Literal l)
returns true if the literal is stored in a DB |
java.util.Iterator<Literal> |
iterator()
Returns an iterator for all beliefs. |
boolean |
remove(Literal l)
Removes a literal from BB, returns true if succeed |
protected Literal |
resultSetToLiteral(java.sql.ResultSet rs,
PredicateIndicator pi)
translates the current line of a result set into a Literal |
int |
size()
Returns the number of beliefs in BB |
void |
stop()
Called just before the end of MAS execution |
static java.sql.Timestamp |
structure2timestamp(Term timestamp)
translates structure like "timestamp(Y,M,D,H,M,S)" into a SQL timestamp |
void |
test()
just create some data to test |
static Structure |
timestamp2structure(java.sql.Timestamp timestamp)
translates a SQL timestamp into a structure like "timestamp(Y,M,D,H,M,S)" |
Methods inherited from class jason.bb.ChainBBAdapter |
---|
add, clone, getAll, getAsDOM, getCandidateBeliefs, getLastBB, getNextAdapter, getPercepts, getRelevant, setNext, toString |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected int extraCols
protected java.sql.Connection conn
protected java.lang.String url
protected java.lang.String agentName
protected java.util.Map<PredicateIndicator,java.sql.ResultSetMetaData> belsDB
public static final java.lang.String timestampFunctor
Constructor Detail |
---|
public JDBCPersistentBB()
public JDBCPersistentBB(BeliefBase next)
Method Detail |
---|
public void init(Agent ag, java.lang.String[] args)
BeliefBase
agent BeliefBaseClass(1,bla);
init
in interface BeliefBase
init
in class ChainBBAdapter
public void stop()
BeliefBase
stop
in interface BeliefBase
stop
in class ChainBBAdapter
protected boolean isDB(Literal l)
protected boolean isCreatedByJason(PredicateIndicator pi) throws java.sql.SQLException
java.sql.SQLException
public Literal contains(Literal l)
BeliefBase
contains(a(10)[d])
returns
a(10)[a,b].
contains
in interface BeliefBase
contains
in class ChainBBAdapter
public boolean add(Literal l)
BeliefBase
add
in interface BeliefBase
add
in class ChainBBAdapter
public boolean remove(Literal l)
BeliefBase
remove
in interface BeliefBase
remove
in class ChainBBAdapter
public boolean abolish(PredicateIndicator pi)
BeliefBase
abolish
in interface BeliefBase
abolish
in class ChainBBAdapter
public java.util.Iterator<Literal> getCandidateBeliefs(Literal l, Unifier u)
BeliefBase
getCandidateBeliefs(a(5), {})
= {{a(10),a(20)}.getCandidateBeliefs(X)
=
{{a(10),a(20)}. The getCandidateBeliefs(a(X), {X -> 5})
should also return {{a(10),a(20)}.
getCandidateBeliefs
in interface BeliefBase
getCandidateBeliefs
in class ChainBBAdapter
public int size()
BeliefBase
size
in interface BeliefBase
size
in class ChainBBAdapter
public java.util.Iterator<Literal> iterator()
BeliefBase
iterator
in interface BeliefBase
iterator
in interface java.lang.Iterable<Literal>
iterator
in class ChainBBAdapter
protected Literal resultSetToLiteral(java.sql.ResultSet rs, PredicateIndicator pi) throws java.sql.SQLException
java.sql.SQLException
protected java.lang.String getTableName(Literal l) throws java.sql.SQLException
java.sql.SQLException
protected java.lang.String getTableName(PredicateIndicator pi) throws java.sql.SQLException
java.sql.SQLException
protected java.lang.String getCreateTable(java.lang.String table, int arity, Structure columns) throws java.sql.SQLException
java.sql.SQLException
protected java.lang.String getSelect(Literal l) throws java.sql.SQLException
java.sql.SQLException
protected java.lang.String getSelectAll(PredicateIndicator pi) throws java.sql.SQLException
java.sql.SQLException
protected java.lang.String getWhere(Literal l) throws java.sql.SQLException
java.sql.SQLException
protected java.lang.String getInsert(Literal l) throws java.sql.SQLException
java.sql.SQLException
protected java.lang.String getDeleteAll(PredicateIndicator pi) throws java.sql.SQLException
java.sql.SQLException
protected java.lang.String getCountQuery(PredicateIndicator pi) throws java.sql.SQLException
java.sql.SQLException
public void test()
public static Structure timestamp2structure(java.sql.Timestamp timestamp) throws java.sql.SQLException
java.sql.SQLException
public static java.sql.Timestamp structure2timestamp(Term timestamp) throws java.sql.SQLException
java.sql.SQLException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |