CVS update: sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple

From: cvs@openprivacy.org
Date: Tue Mar 13 2001 - 15:43:50 PST

  • Next message: cvs@openprivacy.org: "CVS update: sierra/docs"

    Date: Tuesday March 13, 19101 @ 15:43
    Author: burton
    CVSWEB Options: -------------------

    Main CVSWeb: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi

    View this module: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple

    -----------------------------------

    Update of /usr/local/cvs/public/sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple
    In directory giga:/tmp/cvs-serv371/src/java/org/openprivacy/sierra/query/talon/implementations/simple

    Modified Files:
            SimpleQueryEngine.java
    Log Message:
    ...

    *****************************************************************
    File: sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple/SimpleQueryEngine.java

    CVSWEB Options: -------------------

    CVSWeb: Annotate this file: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple/SimpleQueryEngine.java?annotate=1.3

    CVSWeb: View this file: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple/SimpleQueryEngine.java?rev=1.3&content-type=text/x-cvsweb-markup

    CVSWeb: Diff to previous version: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple/SimpleQueryEngine.java.diff?r1=1.3&r2=1.2

    -----------------------------------

    Index: sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple/SimpleQueryEngine.java
    diff -u sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple/SimpleQueryEngine.java:1.2 sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple/SimpleQueryEngine.java:1.3
    --- sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple/SimpleQueryEngine.java:1.2 Tue Mar 13 02:07:21 2001
    +++ sierra/src/java/org/openprivacy/sierra/query/talon/implementations/simple/SimpleQueryEngine.java Tue Mar 13 15:43:50 2001
    @@ -21,12 +21,15 @@
     import java.io.*;
     import java.net.*;
     import java.util.*;
    +import java.sql.*;
     import org.openprivacy.sierra.query.talon.interfaces.*;
     import org.openprivacy.sierra.rce.talon.interfaces.*;
     import org.openprivacy.sierra.reputation.talon.interfaces.*;
    +import org.openprivacy.sierra.reputation.talon.implementations.*;
     import org.openprivacy.sierra.store.talon.interfaces.*;
     import org.openprivacy.sierra.util.SierraException;
     import org.openprivacy.sierra.util.*;
    +import org.openprivacy.sierra.util.sql.*;
     import talon.*;
     import talon.interfaces.*;
     import talon.util.net.*;
    @@ -34,7 +37,7 @@
     /**
      * @see QueryManager
      * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
    - * @version $Id: SimpleQueryEngine.java,v 1.2 2001/03/13 10:07:21 burton Exp $
    + * @version $Id: SimpleQueryEngine.java,v 1.3 2001/03/13 23:43:50 burton Exp $
      */
     public class SimpleQueryEngine extends BaseComponent implements Component, QueryEngine {
     
    @@ -57,7 +60,7 @@
         /**
          * @see QueryEngine
          * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
    - * @version $Id: SimpleQueryEngine.java,v 1.2 2001/03/13 10:07:21 burton Exp $
    + * @version $Id: SimpleQueryEngine.java,v 1.3 2001/03/13 23:43:50 burton Exp $
          */
         public Result execute( Query query ) throws SierraException {
             return null;
    @@ -68,7 +71,7 @@
          * Add a reputation for indexing...
          *
          * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
    - * @version $Id: SimpleQueryEngine.java,v 1.2 2001/03/13 10:07:21 burton Exp $
    + * @version $Id: SimpleQueryEngine.java,v 1.3 2001/03/13 23:43:50 burton Exp $
          */
         public void addReputation( Reputation reputation ) throws SierraException {
     
    @@ -78,19 +81,189 @@
     
             if ( supports( reputation ) ) {
     
    - //do some stuff
    + //add this reputation to the database...
    +
    + //FIXME: this should be replace by a database abstraction layer.
    +
    + //if they are property payloads then we can index them.
                 
    + try {
    +
    + DatabaseConnectionPool dcp =(DatabaseConnectionPool)ComponentFactory
    + .getInstance( SierraResources.DATABASE_CONNNECTION_POOL );
    +
    + StringBuffer insert = new StringBuffer();
    +
    + //insert records into the reputations table
    +
    + insertIntoReputationsTable( dcp, reputation );
    +
    + Enumeration payloads = reputation.getPayloads();
    +
    + while ( payloads.hasMoreElements() ) {
    +
    + Payload current = (Payload)payloads.nextElement();
    +
    + if ( supports( current ) ) {
    +
    + //insert records into the identifiers table
    + insertIntoIdentifiersTable( dcp, current );
    +
    + //insert records into the properties table
    + insertIntoPropertiesTable( dcp, current );
    +
    + }
    +
    + }
    +
    +
    + } catch ( Throwable t ) {
    + throw new SierraException( t );
    + }
    +
    +
             } else {
                 throw new SierraException( "The given Reputation is not supported." );
             }
             
    + }
    +
    +
    + /**
    + *
    + *
    + * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
    + * @version $Id: SimpleQueryEngine.java,v 1.3 2001/03/13 23:43:50 burton Exp $
    + */
    + private void insertIntoPropertiesTable( DatabaseConnectionPool dcp, Payload payload )
    + throws Exception {
    +
    + //get the identifier id
    + Select select_identifier = new Select();
    + select_identifier.setDatabaseConnectionPool( dcp )
    + .setTable( "identifiers" )
    + .addString( "uri", payload.getIdentifier().toString() );
    +
    + select_identifier.commit();
    +
    + select_identifier.getResultSet().next();
    + int identifier = select_identifier.getResultSet().getInt( "pk" );
             
    + //get the reputation id
    + Select select_reputation = new Select();
    + select_reputation.setDatabaseConnectionPool( dcp )
    + .setTable( "reputations" )
    + .addString( "uri", payload.getIdentifier().toString() );
    +
    + select_reputation.commit();
    +
    + select_reputation.getResultSet().next();
    + int reputation = select_reputation.getResultSet().getInt( "pk" );
    +
    +
    + //go over all properties and add them.
    + PropertyManagerPayload pmp = (PropertyManagerPayload)payload;
    +
    + //add all properties
    +
    + Enumeration keys = pmp.getKeys();
    +
    + while ( keys.hasMoreElements() ) {
    +
    + //FIXME: I am adding all records as strings here. This is a BAD
    + //idea. It is much better to add the appropriate types.
    + String name = (String)keys.nextElement();
    + String value = pmp.getString( name );
    +
    + Insert insert = new Insert();
    + insert.setDatabaseConnectionPool( dcp )
    + .setTable( "properties" )
    + .addInteger( "reputation", reputation )
    + .addInteger( "identifier", identifier )
    + .addString( "name", name )
    + .addString( "value", value )
    + .addString( "type", "string" );
    +
    + insert.commit();
    +
    + }
    +
    + }
    +
    + /**
    + *
    + *
    + * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
    + * @version $Id: SimpleQueryEngine.java,v 1.3 2001/03/13 23:43:50 burton Exp $
    + */
    + private void insertIntoIdentifiersTable( DatabaseConnectionPool dcp, Payload payload )
    + throws Exception {
    +
    + Select select = new Select();
    + select.setDatabaseConnectionPool( dcp )
    + .setTable( "identifiers" )
    + .addString( "uri", payload.getIdentifier().toString() );
    +
    + select.commit();
    +
    + //only insert if there are no records in the DB.
    + //HACK: there is no easy way to find out if no results were found. :(
    + if ( select.getResultSet().next() == false ) {
    +
    + this.getLogger().message( "Adding database record for identifier: " + payload.getIdentifier().toString() );
    +
    + Insert insert = new Insert();
    + insert.setDatabaseConnectionPool( dcp )
    + .setTable( "identifiers" )
    + .addString( "uri", payload.getIdentifier().toString() );
             
    - //if they are property payloads then we can index them.
    + insert.commit();
    +
    + }
             
         }
     
    +
    + /**
    + *
    + *
    + * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
    + * @version $Id: SimpleQueryEngine.java,v 1.3 2001/03/13 23:43:50 burton Exp $
    + */
    + private void insertIntoReputationsTable( DatabaseConnectionPool dcp, Reputation reputation )
    + throws Exception {
    +
    + Select select = new Select();
    + select.setDatabaseConnectionPool( dcp )
    + .setTable( "reputations" )
    + .addString( "uri", reputation.getURI().toString() );
     
    + select.commit();
    +
    + //only insert if there are no records in the DB.
    + //HACK: there is no easy way to find out if no results were found. :(
    + if ( select.getResultSet().next() == false ) {
    +
    + this.getLogger().message( "Adding database record for reputation: " + reputation.getURI().toString() );
    +
    + Insert insert = new Insert();
    + insert.setDatabaseConnectionPool( dcp )
    + .setTable( "reputations" )
    + .addString( "reference", reputation.getReference().toString() )
    + .addString( "uri", reputation.getURI().toString() );
    +
    + insert.commit();
    +
    + }
    +
    + }
    +
    +
    + /**
    + * @see QueryEngine
    + * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
    + * @version $Id: SimpleQueryEngine.java,v 1.3 2001/03/13 23:43:50 burton Exp $
    + */
         public boolean supports( Reputation reputation ) {
     
             Enumeration enum = reputation.getPayloads();
    @@ -110,12 +283,22 @@
             return true;
         }
     
    + /**
    + * @see QueryEngine
    + * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
    + * @version $Id: SimpleQueryEngine.java,v 1.3 2001/03/13 23:43:50 burton Exp $
    + */
         public boolean supports( Payload payload ) {
     
             return this.supportedPayloads.contains( payload.getIdentifier().toString() );
     
         }
     
    + /**
    + * @see QueryEngine
    + * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
    + * @version $Id: SimpleQueryEngine.java,v 1.3 2001/03/13 23:43:50 burton Exp $
    + */
         public boolean supports( Query query ) {
             //FIXME: for now support all queries.
             return true;



    This archive was generated by hypermail 2b30 : Tue Mar 13 2001 - 15:43:52 PST