Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    need help with DMI Java code...

    using: SNAPSHOT_v9.0d_2013-04-30/PowerEdition Deployment (built 2013-04-30)

    I have this partially working function - please see my question in the "result.add" line:

    Code:
       private List<Integer> getAssetIdListForContainer(Integer containerId) {
    
          // this interacts with a table having 2 fields:
          //    containerId
          //    assetId
          
          // assetId values will be added to this list in the for each loop below
          List<Integer> result = new ArrayList<Integer>();
    
          // fetch all records for the given containerId
          DSRequest container = new DSRequest("ContainersToAssets", "fetch");
          container.setCriteria("containerId", containerId);
          
          try {
             
             List<Object> resp = container.execute().getDataList();
             
             for (Object o : resp) {
                
                // the fetch operation above finds 3 records, so this prints 3 times to my log
                logIt("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
                
                // here's where I'm stuck:
                result.add( what goes in here to get the assetId value from the current record ??? )
                
             }
             
             return result;
             
          } catch (Exception somethingBad) {
             return null;
          }
          
       }
    .... or suggest any other approach to populate my result List.

    #2
    I got it working - not sure if my approach is best though...

    After more digging around in the JavaDoc content, I ended up with this doing what I wanted.

    Is there a better way I should have done this?

    Code:
       private List<Integer> getAssetIdListForContainer(Integer containerId) {
    
          // assetId values will be added to this list in the for each loop below
          List<Integer> result = new ArrayList<Integer>();
    
          // fetch all records for the given containerId
          DSRequest container = new DSRequest("ContainersToAssets", "fetch");
          container.setCriteria("containerId", containerId);
          
          try {
             
             List<Integer> values = DataTools.getProperty(
                     container.execute().getRecords(), 
                     "assetId");
             
             for (Integer value : values) {
                result.add(value);
             }
             
             return result;
             
          } catch (Exception somethingBad) {
             return result;
          }
          
       }

    Comment


      #3
      and one more question/suggestion....

      I'm working on this particular section of code leading up to a recursive function which will return a DSResponse containing all descendants (child records) no matter how deeply nested they are starting at a given point in a tree.

      In my particular use-case, the nesting will probably never go deep enough to cause performance problems (I hope). I know it's constructing a SQL IN clause further down in the stack which could get ridiculously large under many circumstances.

      My question is: Did I entirely miss some piece of already existing functionality in SmartClient to help me with this?

      My suggestion would be: Is there any possibility of adding a handful of useful functions to help us deal with deeply nested parent/child data?

      As always, thanks for your help and support!

      Comment


        #4
        Yes, special server-side operations like "load N levels of a tree" make sense as a possible server-side feature. If you'd like to see that as a supported feature in the product, you can use the Feature Sponsorship program to have it added.

        Comment

        Working...
        X