Thanks for responding... 

Well it works now... I did not change anything actually. Maybe a reboot
of Postgres was what I needed? I don't think so.. But here is the
solution for anyone else that needs this... hope that this helps someone

RESPOSITORY --------------------------
   <class-descriptor
      class="com.cadence.apps.cadencepdk.model.UserView"
      table="userview" >

      <field-descriptor id="1"
         name           ="id"
         column         ="user_id"
         jdbc-type      ="INTEGER"
           primarykey   ="true"/>

      <field-descriptor id="1"
         name           ="email"
         column         ="email"
         jdbc-type      ="VARCHAR"/>

      <field-descriptor id="2"
         name           ="fname"
         column         ="fname"
         jdbc-type      ="VARCHAR"/>
        (* More Stuff *)
   </class-descriptor>

THE VIEW DEFINITION ----------------
CREATE VIEW public.userview AS SELECT users.user_id, users.email,
users.fname, users.lname, companies.comp_name, users.apprved FROM users
WHERE (((users.location_id)::text = (locations.location_id)::text) AND
(companies.cmp_id = locations.cmp_id));
A lot of this stuff was added by Postgres (::text for instance)..

THE JAVA CODE ----------
public class RequestListUsers extends MultipleRequest {
    /**
     * 
     */
    public RequestListUsers(PersistenceBroker broker) {
        super(broker, UserView.class, "userview");
    }

    //  the start, end and sort properties are held in the super class
    public Response execute() {
        ResponseImpl response = new ResponseImpl();
        try {
            // Query query = new QueryByCriteria(User.class,
super.criteria);
            Query query = super.buildSQLObj();
            
            System.out.println("RequestListUsers::execute()=>" + query);
       
            broker.beginTransaction();
            response.setResults((Collection)
                                broker.getCollectionByQuery(query));
            //response.setTotalCount((response.getResults()).size());
DOES NOT WORK
            broker.commitTransaction();
            System.out.println("RequestListUsers "
                + response.getTotalCount()
                + " Users found");
        } catch (Exception exc) {
            exc.printStackTrace();
        }

        return response;
    }
}

The Super Class MultipleRequest --------------

    public MultipleRequest(PersistenceBroker broker, 
                            Class concreteClassType,
                            String tableViewName) {
        super(broker);
        this.concreteClassType = concreteClassType;
        descrpRepos = super.broker.getDescriptorRepository();
        classDesc = descrpRepos.getDescriptorFor(concreteClassType);
        this.tableViewName = tableViewName;
    }

    public void setStartPosition(int startPos) {
        if (startPos != 0) {
            FieldDescriptor fd =
                classDesc.getFieldDescriptorByIndex(Model.OBJECT_ID);
            String objectIDName = fd.getColumnName();
            System.out.println(
                "setStartPosition(" + startPos + ") on => " +
objectIDName);
            this.startPos = startPos;
        } else {
            System.out.println("MultipleRequest: startPos Disabled");
        }
    }

    public void setPageSize(int pageSize) {
        if (pageSize != 0) {
            FieldDescriptor fd =
                classDesc.getFieldDescriptorByIndex(Model.OBJECT_ID);
            String objectIDName = fd.getColumnName();
            System.out.println(
                "setEndPosition(" + pageSize + ") on => " +
objectIDName);
            this.pageSize = pageSize;
        } else {
            System.out.println("MultipleRequest: endPos Disabled");
        }
    }

    public void sortBy(int attributeID) {
        if (attributeID != 0) {
            FieldDescriptor fd =
                classDesc.getFieldDescriptorByIndex(attributeID);
            sortByColumnName = fd.getColumnName();
            System.out.println(
                "sortBy(" + attributeID + ") ColumnName=>" +
sortByColumnName);
        } else {
            System.out.println("MultipleRequest: sortBy Disabled");
        }
    }

    public void filterBy(int attributeID, Object attributeValue) {
        if (attributeValue != null) {
            FieldDescriptor fd =
                classDesc.getFieldDescriptorByIndex(attributeID);
            String filterByColumnName = fd.getColumnName();
            System.out.println(
                "filterBy("
                    + attributeID
                    + ", attributeValue"
                    + attributeValue
                    + ")");
            System.out.println("ColumnName=>" + filterByColumnName);
            columnValuePairs.add(new AttriValuePair(filterByColumnName,
attributeValue));
        } else {
            System.out.println("Invaild request");
        }
    }

    /*
          QueryBySQL qBySql = new QueryBySQL(User.class,
              "select * from users ORDER BY userid LIMIT 3 OFFSET 2
              Where columName = AttriValue");
    */
    protected QueryBySQL buildSQLObj() throws Exception {
        if (tableViewName != null) {
            queryStr = queryStr + tableViewName;
            if (sortByColumnName != null){
                queryStr = queryStr + " ORDER BY " + sortByColumnName;
            }
            if (pageSize != 0) {
                queryStr = queryStr + " LIMIT " + pageSize;
            }
            if (startPos != 0) {
                queryStr = queryStr + " OFFSET " + startPos;
            }
            if (!columnValuePairs.isEmpty()) {
                AttriValuePair attriValuePair = null;
                Iterator colValInter = columnValuePairs.iterator();
                while (colValInter.hasNext()){
                    attriValuePair = (AttriValuePair)colValInter.next();
                    queryStr = queryStr + " Where " +
attriValuePair.filterByColumnName +
                                          " Equals " +
attriValuePair.attributeValue;
                }
            }
        }
        else {
            throw new Exception("MultipleRequest::buildSQLString Invalid
Empty tableName");
        }
        return new QueryBySQL(concreteClassType, queryStr);
    }
    
    
    //  this method used the import
com.cadence.shared.query.ResponseImpl; class
    //  to fill in everything and then returns a Response tot he caller.
    public abstract Response execute();
    
    private class AttriValuePair {
        public String filterByColumnName = null;
        public String attributeValue = null;
        public AttriValuePair(String filterByColumnName, Object
attributeValue){
            this.filterByColumnName = filterByColumnName;
            this.attributeValue = convertStr(attributeValue);
        }
        
        private String convertStr(Object obj) /*throws Exception*/ {
            String returnStr = null;
            if (obj instanceof Boolean){
                returnStr = ((Boolean)obj).toString();
            }
            else if (obj instanceof Integer){
                returnStr = ((Integer)obj).toString();
            }
            else if (obj instanceof String){
                returnStr = ((String)obj);
            } 
            /*
            else if (obj instanceof Date){
                returnStr = ((String)obj);
            }  
            */
            else {
                System.out.println("AttriValuePair::convertStr(" +
obj.toString() + " bv Invalid type");
                //throw new Exception ("AttriValuePair::convertStr(" +
obj.toString() + " bv Invalid type");
            }
            return   returnStr;                   
        }
    }
}


THE ACTUAL QUERY STRING I EXECUTE--------------
select * from userview





-----Original Message-----
From: Jakob Braeuchi [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 03, 2003 4:03 AM
To: OJB Users List
Subject: Re: Mapping objects from a view, not a table

hi,

this should work as long as you only read.

hth
jakob

----- Original Message ----- 
From: "Raymond Lukas" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, January 02, 2003 11:01 PM
Subject: Mapping objects from a view, not a table


I need to map objects which come from a view, not a real table. Can I do
that?

What happens to the "required" object id in the repository file. I will
not have one since this is a view and not a real table. 

 

Note:

I am using views because I was not able to efficiently use multiple
inter-linked tables. 



--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to