This discussion is archived
5 Replies Latest reply: Nov 9, 2012 10:20 AM by Timo Hahn RSS

Getting a View Object Total Attributes

918256 Newbie
Currently Being Moderated
Hi, Is there any way to retrieve the Attribute count (DataBase Columns) of a View Object in its own java implementation?

I'm using this:
JDev 11.1.1.6

System.out.println("this.getEntityDef(0).getAttributeCount() " + this.getEntityDef(0).getAttributeCount());
System.out.println("Column count1 " + this.getAttributeCount());
System.out.println("Column count2 " + this.getAttributeDefs().length);
System.out.println("Column count3 " + this.getProperties().size());

but none of them works the best way:

the first one gives me 6 more than the actual columns that excist in the entity object

the second and third are gives me more than the attributes of that object
the forth gives me 200 and more

which way gives me the count of the database table columns, and how can I access it in by index?

thanks
  • 1. Re: Getting a View Object Total Attributes
    Cvele_new_account Expert
    Currently Being Moderated
    Put this method in the ViewObjectImpl:
        public int getCountOfPersistentAttrs() {
            int result = 0;
            for (AttributeDef attr : getAttributeDefs()) {
                if (attr.getAttributeKind() == AttributeDef.ATTR_PERSISTENT) 
                     result++;
            }
            return result;
        } 
  • 2. Re: Getting a View Object Total Attributes
    Timo Hahn Oracle ACE
    Currently Being Moderated
    Instead of using the entity object the VO is based on you should use the ViewDefImpl of the VO. You can generate the class at the same location where you generate the other classes for a VO.
    The ViewDefImpl class has a getAttributeCount() method too, however this method should give you the count of attributes the VO contains.

    Timo
  • 3. Re: Getting a View Object Total Attributes
    918256 Newbie
    Currently Being Moderated
    Thanks, and how can I access each one name?
    by using att variable?

    thanks again
  • 4. Re: Getting a View Object Total Attributes
    Timo Hahn Oracle ACE
    Currently Being Moderated
    Have you checked the javadoc of the AttributeDef class (http://docs.oracle.com/cd/E16764_01/apirefs.1111/e10653/oracle/jbo/AttributeDef.html)?
    getColumnName() hives you the name of the column, getName(); the name of the attribute visible from the outside...

    Timo
  • 5. Re: Getting a View Object Total Attributes
    Cvele_new_account Expert
    Currently Being Moderated
    - Here is modified code, which prints attribute name along with database column name the attribute represents:
     public int getCountOfPersistentAttrs() {
            int result = 0;
            for (AttributeDef attr : getAttributeDefs()) {
                if (attr.getAttributeKind() == AttributeDef.ATTR_PERSISTENT) {
                     System.out.println("Name of persistent attribute : " + attr.getName());
                     System.out.println("Name of the database column the attribute represents : " + attr.getColumnName());
                     result++;
                }
            }
            return result;
        } 

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points