You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by "Denis (JIRA)" <ji...@apache.org> on 2007/07/13 10:39:05 UTC

[jira] Updated: (AXIS2-2957) ADB. Time of addition of elements into array proportionally to a factorial!

     [ https://issues.apache.org/jira/browse/AXIS2-2957?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Denis updated AXIS2-2957:
-------------------------

    Attachment: adb-codegen-sample-bug-factorial.zip

Sample of code generated from Eclipse 3.2 by wizard "Axis2 Code Generator".

> ADB. Time of addition of elements into array proportionally to a factorial!
> ---------------------------------------------------------------------------
>
>                 Key: AXIS2-2957
>                 URL: https://issues.apache.org/jira/browse/AXIS2-2957
>             Project: Axis 2.0 (Axis2)
>          Issue Type: Bug
>          Components: adb, codegen
>    Affects Versions: 1.2
>         Environment: Win XP Pro, Tomcat 5.5.20, Eclipse 3.2, Sun JDK 1.5
>            Reporter: Denis
>            Priority: Critical
>         Attachments: adb-codegen-sample-bug-factorial.zip
>
>
> The code, generated by ADB for addition of an element to an array, is carried out in time proportional to a factorial from number of added elements.
> Also the ADB generates a dirty (bad formatted and without using import statements) code.
> The code was generated from Eclipse by wizard "Axis2 code generator".
> Small part of WSDL:
>             <xs:complexType name="Advertisement">
>                 <xs:sequence>
>                     <xs:element name="id" type="xs:long"/>
>                     <xs:element name="placeId" type="xs:int"/>
>                     <xs:element name="header" type="xs:string"/>
>                     <xs:element name="file" type="xs:string"/>
>                     <xs:element minOccurs="0" name="url" type="xs:string"/>
>                 </xs:sequence>
>             </xs:complexType>
>             <xs:complexType name="AdvertisementArray">
>                 <xs:sequence>
>                     <xs:element maxOccurs="unbounded" minOccurs="0" name="advertisement"
>                         type="data:Advertisement"/>
>                 </xs:sequence>
>             </xs:complexType>
>             <xs:complexType name="Packet">
>                 <xs:sequence>
>                     <xs:element name="id" type="xs:string"/>
>                     <xs:element minOccurs="0" name="sessionId" type="xs:string"/>
>                     <xs:element minOccurs="0" name="advertisements" type="data:AdvertisementArray"/>
>                     <xs:element minOccurs="0" name="info" type="xs:string"/>
>                 </xs:sequence>
>             </xs:complexType>
>             <xs:element name="packet" type="data:Packet"/>
> See an example of a code:
> The auto generated by ADB AdvertisementArray.java contains following code:
> 	 public void addAdvertisement (
> 			 ru.scanrealty.supplier.deo. SRDAdvertisement param) {
> 		 if (localAdvertisement == null) {
> 			 localAdvertisement = new ru.scanrealty.supplier.deo. SRDAdvertisement [] {};
> 		}
> 		 // update the setting tracker
> 		 localAdvertisementTracker = true;
> 		 java.util. List list = org.apache.axis2.databinding.utils.ConverterUtil
> 				 .toList (localAdvertisement);
> 		 list.add (param);
> 		 this.localAdvertisement = (ru.scanrealty.supplier.deo. SRDAdvertisement []) list
> 				 .toArray (new ru.scanrealty.supplier.deo. SRDAdvertisement [list
> 						 .size ()]);
> 	}
> Also org.apache.axis2.databinding.utils.ConverterUtil.java contains following code:
>     public static List toList (Object [] array) {
>         if (array == null) {
>             return new ArrayList ();
>        } else {
>             ArrayList list = new ArrayList ();
>             for (int i = 0; i < array.length; i ++) {
>                 list.add (array [i]);
>            }
>             return list;
>        }
>    }
> It's very bad code!
> The following code will be carried out in time proportional to a factorial from amount of added elements:
> ResultSet rs = < gets result set from DB >
> AdvertisementArray advertisements = new AdvertisementArray ();
> while (rs.next ()) {
>     advertisements.addAdvertisement (createAdvertisement (rs));
> }
> It occurs because of transformation of an array to the list and copying of elements of an array in a loop in a code ConverterUtil.toList().
> In Java the given code should be as:
> public class AdvertisementArray
>     implements org.apache.axis2.databinding. ADBBean {
>           ......
>     protected ArrayList <Advertisement> localAdvertisement; // Sequence and repeated elements.
>     public Advertisement [] getAdvertisement () {
>         ... some checks (also up on null) ...
>         return (Advertisement []) localAdvertisement.toArray (new Advertisement [0]);
>    }
>     public void addAdvertisement (Advertisement el) {
>         ... some checks ...
>         localAdvertisement.add (el);
>    }
>     ......
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org