You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Vinicius Bomfim <vi...@globo.com> on 2003/07/11 02:44:39 UTC

RES: Query Customizers

Hi All,

	Is there any one with a Query Customizer example ?

Thanks,
Vinicius Bomfim

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: RES: RES: Query Customizers

Posted by Thomas Cornet <th...@cornet.name>.

You mean, when you load an object ? If so, take a look at proxies...



At 21:15 11/07/2003, you wrote:
>Thanks a lot.
>It?s working fine.
>
>Do you know how can i choose to load or not a collection ?
>
>Thanks again,
>Vinicius Bomfim
>
>-----Mensagem original-----
>De: Thomas Cornet [mailto:thomas@cornet.name]
>Enviada em: sexta-feira, 11 de julho de 2003 02:41
>Para: OJB Users List
>Assunto: Re: RES: Query Customizers
>
>
>
>     Here is one I've made, quite a basic one, which just adds 'equal'
>criterias.
>
>           Thomas
>
>*** ========= repository.xml ============== ***
>
>                  <collection-descriptor
>                          name="sortsAttaque"
>                          element-class-ref="net.aejase.avatar.MobSort"
>                          proxy="true"
>                  >
>                          <inverse-foreignkey field-ref="mobId"/>
>
>                          <query-customizer
>class="net.aejase.ojb.AejaseQueryCustomizer">
>                                  <attribute attribute-name="cible"
>attribute-value="1" />
>                          </query-customizer>
>                  </collection-descriptor>
>
>
>*** =================================== ***
>
>/*
>   * Created on 29 juin 2003
>   *
>   */
>package net.aejase.ojb;
>
>import java.util.HashMap;
>import java.util.Iterator;
>
>import org.apache.ojb.broker.PersistenceBroker;
>import org.apache.ojb.broker.accesslayer.QueryCustomizer;
>import org.apache.ojb.broker.metadata.CollectionDescriptor;
>import org.apache.ojb.broker.query.Criteria;
>import org.apache.ojb.broker.query.Query;
>import org.apache.ojb.broker.query.QueryByCriteria;
>
>/**
>   *
>   *
>   *  @author
>   */
>public class AejaseQueryCustomizer implements QueryCustomizer
>{
>          private HashMap map = null;
>
>          /**
>           *
>           */
>          public AejaseQueryCustomizer()
>          {
>                  map = new HashMap();
>          }
>
>          /* (non-Javadoc)
>           * @see
>org.apache.ojb.broker.accesslayer.QueryCustomizer#customizeQuery(java.lang.O
>bject,
>org.apache.ojb.broker.PersistenceBroker,
>org.apache.ojb.broker.metadata.CollectionDescriptor,
>org.apache.ojb.broker.query.QueryByCriteria)
>           */
>          public Query customizeQuery(
>                  Object arg0,
>                  PersistenceBroker arg1,
>                  CollectionDescriptor arg2,
>                  QueryByCriteria query)
>          {
>                  String tmp;
>
>                  Criteria c = query.getCriteria();
>                  Iterator i = map.keySet().iterator();
>
>                  while (i.hasNext())
>                  {
>                          tmp = (String)i.next();
>                          c.addEqualTo(tmp, this.getAttribute(tmp));
>                  }
>
>                  return query;
>          }
>
>          /* (non-Javadoc)
>           * @see
>org.apache.ojb.broker.metadata.AttributeContainer#addAttribute(java.lang.Str
>ing,
>java.lang.String)
>           */
>          public void addAttribute(String arg0, String arg1)
>          {
>                  map.put(arg0, arg1);
>
>          }
>
>          /* (non-Javadoc)
>           * @see
>org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.Str
>ing,
>java.lang.String)
>           */
>          public String getAttribute(String arg0, String arg1)
>          {
>                  if (map.containsKey(arg0))
>                          return (String)map.get(arg0);
>
>                  return arg1;
>          }
>
>          /* (non-Javadoc)
>           * @see
>org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.Str
>ing)
>           */
>          public String getAttribute(String arg0)
>          {
>                  return (String)map.get(arg0);
>          }
>
>}
>
>*** ================================================== ***
>
>
>At 02:44 11/07/2003, you wrote:
> >Hi All,
> >
> >         Is there any one with a Query Customizer example ?
> >
> >Thanks,
> >Vinicius Bomfim
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> >For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


RES: RES: Query Customizers

Posted by Vinicius Bomfim <vi...@globo.com>.
Thanks a lot.
It?s working fine.

Do you know how can i choose to load or not a collection ?

Thanks again,
Vinicius Bomfim

-----Mensagem original-----
De: Thomas Cornet [mailto:thomas@cornet.name]
Enviada em: sexta-feira, 11 de julho de 2003 02:41
Para: OJB Users List
Assunto: Re: RES: Query Customizers



    Here is one I've made, quite a basic one, which just adds 'equal'
criterias.

          Thomas

*** ========= repository.xml ============== ***

                 <collection-descriptor
                         name="sortsAttaque"
                         element-class-ref="net.aejase.avatar.MobSort"
                         proxy="true"
                 >
                         <inverse-foreignkey field-ref="mobId"/>

                         <query-customizer
class="net.aejase.ojb.AejaseQueryCustomizer">
                                 <attribute attribute-name="cible"
attribute-value="1" />
                         </query-customizer>
                 </collection-descriptor>


*** =================================== ***

/*
  * Created on 29 juin 2003
  *
  */
package net.aejase.ojb;

import java.util.HashMap;
import java.util.Iterator;

import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.accesslayer.QueryCustomizer;
import org.apache.ojb.broker.metadata.CollectionDescriptor;
import org.apache.ojb.broker.query.Criteria;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.query.QueryByCriteria;

/**
  *
  *
  *  @author
  */
public class AejaseQueryCustomizer implements QueryCustomizer
{
         private HashMap map = null;

         /**
          *
          */
         public AejaseQueryCustomizer()
         {
                 map = new HashMap();
         }

         /* (non-Javadoc)
          * @see
org.apache.ojb.broker.accesslayer.QueryCustomizer#customizeQuery(java.lang.O
bject,
org.apache.ojb.broker.PersistenceBroker,
org.apache.ojb.broker.metadata.CollectionDescriptor,
org.apache.ojb.broker.query.QueryByCriteria)
          */
         public Query customizeQuery(
                 Object arg0,
                 PersistenceBroker arg1,
                 CollectionDescriptor arg2,
                 QueryByCriteria query)
         {
                 String tmp;

                 Criteria c = query.getCriteria();
                 Iterator i = map.keySet().iterator();

                 while (i.hasNext())
                 {
                         tmp = (String)i.next();
                         c.addEqualTo(tmp, this.getAttribute(tmp));
                 }

                 return query;
         }

         /* (non-Javadoc)
          * @see
org.apache.ojb.broker.metadata.AttributeContainer#addAttribute(java.lang.Str
ing,
java.lang.String)
          */
         public void addAttribute(String arg0, String arg1)
         {
                 map.put(arg0, arg1);

         }

         /* (non-Javadoc)
          * @see
org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.Str
ing,
java.lang.String)
          */
         public String getAttribute(String arg0, String arg1)
         {
                 if (map.containsKey(arg0))
                         return (String)map.get(arg0);

                 return arg1;
         }

         /* (non-Javadoc)
          * @see
org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.Str
ing)
          */
         public String getAttribute(String arg0)
         {
                 return (String)map.get(arg0);
         }

}

*** ================================================== ***


At 02:44 11/07/2003, you wrote:
>Hi All,
>
>         Is there any one with a Query Customizer example ?
>
>Thanks,
>Vinicius Bomfim
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: RES: Query Customizers

Posted by Thomas Cornet <th...@cornet.name>.
    Here is one I've made, quite a basic one, which just adds 'equal' 
criterias.

          Thomas

*** ========= repository.xml ============== ***

                 <collection-descriptor
                         name="sortsAttaque"
                         element-class-ref="net.aejase.avatar.MobSort"
                         proxy="true"
                 >
                         <inverse-foreignkey field-ref="mobId"/>

                         <query-customizer 
class="net.aejase.ojb.AejaseQueryCustomizer">
                                 <attribute attribute-name="cible" 
attribute-value="1" />
                         </query-customizer>
                 </collection-descriptor>


*** =================================== ***

/*
  * Created on 29 juin 2003
  *
  */
package net.aejase.ojb;

import java.util.HashMap;
import java.util.Iterator;

import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.accesslayer.QueryCustomizer;
import org.apache.ojb.broker.metadata.CollectionDescriptor;
import org.apache.ojb.broker.query.Criteria;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.query.QueryByCriteria;

/**
  *
  *
  *  @author
  */
public class AejaseQueryCustomizer implements QueryCustomizer
{
         private HashMap map = null;

         /**
          *
          */
         public AejaseQueryCustomizer()
         {
                 map = new HashMap();
         }

         /* (non-Javadoc)
          * @see 
org.apache.ojb.broker.accesslayer.QueryCustomizer#customizeQuery(java.lang.Object, 
org.apache.ojb.broker.PersistenceBroker, 
org.apache.ojb.broker.metadata.CollectionDescriptor, 
org.apache.ojb.broker.query.QueryByCriteria)
          */
         public Query customizeQuery(
                 Object arg0,
                 PersistenceBroker arg1,
                 CollectionDescriptor arg2,
                 QueryByCriteria query)
         {
                 String tmp;

                 Criteria c = query.getCriteria();
                 Iterator i = map.keySet().iterator();

                 while (i.hasNext())
                 {
                         tmp = (String)i.next();
                         c.addEqualTo(tmp, this.getAttribute(tmp));
                 }

                 return query;
         }

         /* (non-Javadoc)
          * @see 
org.apache.ojb.broker.metadata.AttributeContainer#addAttribute(java.lang.String, 
java.lang.String)
          */
         public void addAttribute(String arg0, String arg1)
         {
                 map.put(arg0, arg1);

         }

         /* (non-Javadoc)
          * @see 
org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.String, 
java.lang.String)
          */
         public String getAttribute(String arg0, String arg1)
         {
                 if (map.containsKey(arg0))
                         return (String)map.get(arg0);

                 return arg1;
         }

         /* (non-Javadoc)
          * @see 
org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.String)
          */
         public String getAttribute(String arg0)
         {
                 return (String)map.get(arg0);
         }

}

*** ================================================== ***


At 02:44 11/07/2003, you wrote:
>Hi All,
>
>         Is there any one with a Query Customizer example ?
>
>Thanks,
>Vinicius Bomfim
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org