Hi again,

This time I'm using the Query instead of the NodeQuery thank to the wise
advice of Michiel... But I'm still getting unpredictable results:

---

import org.mmbase.bridge.*;
import org.mmbase.storage.search.*;
import java.util.*;

public class PruebaMMBase {
    public static void main(String[] args) {
        int itemsToShow = 2;

        // Set the cloud connection parameters
        CloudContext cloudContext =
ContextProvider.getCloudContext("rmi://127.0.0.1:1111/remotecontext");
        HashMap credentials = new HashMap();
        credentials.put("username", "admin");
        credentials.put("password", "admin2k");

        // We get connected to the cloud
        Cloud cloud = cloudContext.getCloud("mmbase", "name/password",
credentials);

        // Create the query to retrieve info from the CMS repository
        Query query = cloud.createQuery();

        // Define the object types involved in the query
        NodeManager url = cloud.getNodeManager("url");
        NodeManager tema = cloud.getNodeManager("tema");

        // Create the query steps
        query.addStep(url);
        query.addRelationStep(tema).getNext();

        // Add the desired fields
        StepField campo_number = query.addField("url.number");
        query.addField("url.nombre");
        query.addField("url.url");
        query.addField("tema.descripcion");
        
        // Establish the sort order
        query.addSortOrder(campo_number, SortOrder.ORDER_DESCENDING);

        // We set the max number of items to retrieve
        query.setMaxNumber(itemsToShow);

        // Launch the query against the cloud
        List elementList = cloud.getList(query);

        System.out.println("-----------------------------------------");
        System.out.println(new Date());
        System.out.println("-----------------------------------------");
        System.out.println("List: " + elementList);

        Iterator elementIterator = elementList.iterator();
        while (elementIterator.hasNext()) {
            // For each node...
            Node element = (Node) elementIterator.next();
            System.out.println("\t(Node): " + element + "\n");
            // We get the desired fields
            System.out.println("\t\turl.url: " +
element.getStringValue("url.url"));
            System.out.println("\t\turl.nombre: " +
element.getStringValue("url.nombre"));
            System.out.println("\t\ttema.descripcion: " +
element.getStringValue("tema.descripcion"));
            System.out.println("\t\turl.descripcion (should be empty): " +
element.getStringValue("url.descripcion"));
        }
        System.out.println("-----------------------------------------");
    }
}





The output is as follows (anybody can try it, simply change the NodeManager
and Field names and run):


-----------------------------------------
Fri Aug 06 11:51:55 CEST 2004
-----------------------------------------
List:
[prefix='',insrel.number=9:'2545',url.number=9:'2539',tema.descripcion=1:'Ga
uzak',
url.url=1:'http://www.pru2.com',url.nombre=1:'Pru2',tema.number=9:'413',
prefix='',insrel.number=9:'2541',url.number=9:'2529',tema.descripcion=1:'Zie
ntzia',
url.url=1:'http://www.sony.com',url.nombre=1:'Sony',tema.number=9:'412',
prefix='',insrel.number=9:'2546',url.number=9:'2528',tema.descripcion=1:'Ais
ialdia',
url.url=1:'http://www.coverlink.com',url.nombre=1:'Coverlink',tema.number=9:
'399']

        Node:
prefix='',insrel.number=9:'2545',url.number=9:'2539',tema.descripcion=1:'Gau
zak',
        
url.url=1:'http://www.pru2.com',url.nombre=1:'Pru2',tema.number=9:'413'
                url.url: http://www.pru2.com
                url.nombre: Pru2
                tema.descripcion: Gauzak
                url.descripcion (should be empty): dsgdsfgd
        Node:
prefix='',insrel.number=9:'2541',url.number=9:'2529',tema.descripcion=1:'Zie
ntzia',
        
url.url=1:'http://www.sony.com',url.nombre=1:'Sony',tema.number=9:'412'
                url.url: http://www.sony.com
                url.nombre: Sony
                tema.descripcion: Zientzia
                url.descripcion (should be empty): El mejor fabricante de
dispositivos electr�nicos de consumo
        Node:
prefix='',insrel.number=9:'2546',url.number=9:'2528',tema.descripcion=1:'Ais
ialdia',
        
url.url=1:'http://www.coverlink.com',url.nombre=1:'Coverlink',tema.number=9:
'399'
                url.url: http://www.coverlink.com
                url.nombre: Coverlink
                tema.descripcion: Aisialdia
                url.descripcion (should be empty): La empresa que desarrolla
el nuevo portal HABENET
-----------------------------------------
Process terminated with exit code 0


So the NodeList obtained through cloud.getList(query) seems to contain ONLY
the specified fields, but when I print it the mysterious "url.descripcion"
field appears when it should be blank (because it's not in the query field
list).

The NodeList obtained using NodeQuery instead of Query doesn't contain "not
specifically added fields" either.

Any ideas?


Ignacio Renuncio.-


Reply via email to