3 Replies Latest reply on Oct 13, 2008 4:20 PM by starksm64

    java.beans.XMLEncoder Useless?

    starksm64

      So after talking about what the attachments serialized form would look like on the open console call, I created a little test of a datasource:

       /**
       * Just a test to see what the java.beans.XMLEncoder output for the
       * local ds metadata looks like.
       */
       public void testJavaBeanXml()
       {
       ManagedConnectionFactoryDeploymentGroup mcfs = new ManagedConnectionFactoryDeploymentGroup();
       LocalDataSourceDeploymentMetaData lds = new LocalDataSourceDeploymentMetaData();
       lds.setBackgroundValidation(true);
       lds.setBackgroundValidationMillis(5000);
       lds.setBlockingTimeoutMilliSeconds(5000);
       lds.setCheckValidConnectionSQL("select something from somewhere");
       lds.setConnectionDefinition("conn def");
       lds.setConnectionUrl("jdbc:xyz:a=b");
       DataSourceConnectionPropertyMetaData cp1 = new DataSourceConnectionPropertyMetaData();
       cp1.setName("cp1-name");
       cp1.setValue("cp1-value");
       DataSourceConnectionPropertyMetaData cp2 = new DataSourceConnectionPropertyMetaData();
       cp2.setName("cp2-name");
       cp2.setValue("cp2-value");
       DataSourceConnectionPropertyMetaData[] cps = {
       cp1, cp2
       };
       lds.setDataSourceConnectionProperties(Arrays.asList(cps));
       lds.setDriverClass("org.jboss.jdbc.SomeDriver");
       lds.setExceptionSorterClassName("org.jboss.jdbc.SomeExceptionSorter");
       String[] depends = {"jboss:service=Naming"};
       lds.setDependsNames(Arrays.asList(depends));
       lds.setIdleTimeoutMinutes(15);
       lds.setInterleaving(false);
       lds.setMaxSize(100);
       lds.setMinSize(1);
       lds.setNewConnectionSQL("run this on a new conn");
       lds.setPassWord("password");
       lds.setPrefill(true);
       lds.setPreparedStatementCacheSize(50);
       lds.setQueryTimeout(30000);
       lds.setUserName("user");
      
       ManagedConnectionFactoryDeploymentMetaData[] mds = {lds};
       mcfs.setDeployments(Arrays.asList(mds));
      
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       XMLEncoder oos = new XMLEncoder(baos);
       oos.writeObject(mcfs);
       oos.close();
      
       String s = new String(baos.toByteArray());
       System.out.println(s);
       }
      


      only translates to:
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.5.0_16" class="java.beans.XMLDecoder">
       <object class="org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup"/>
      </java>
      


      Maybe I'm missing something obvious, but that's not going to work.


        • 1. Re: java.beans.XMLEncoder Useless?
          starksm64

          Since we should be using jaxb for metadata that is annotated with it, and I see that you can use jaxb even when its not annotated, I'm looking at that instead. For metadata like the datasource which does have jaxb annotations:

           public void testJaxbMCFXml()
           throws Exception
           {
           ManagedConnectionFactoryDeploymentGroup mcfs = initMCFDG();
          
           JAXBContext ctx = JAXBContext.newInstance(ManagedConnectionFactoryDeploymentGroup.class);
           Marshaller marshaller = ctx.createMarshaller();
           marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
           QName mcfsName = new QName("datasources");
           JAXBElement<ManagedConnectionFactoryDeploymentGroup> root = new
           JAXBElement<ManagedConnectionFactoryDeploymentGroup>(mcfsName,
           ManagedConnectionFactoryDeploymentGroup.class, mcfs);
           marshaller.marshal(root, System.out);
           }
          


          with initMCFDG() populating the mcfs similar to that shown above, jaxb output produces:
          <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
          <datasources>
           <local-tx-datasource>
           <rar-name>jboss-local-jdbc.rar</rar-name>
           <use-java-context>true</use-java-context>
           <connection-definition>conn def</connection-definition>
           <jmx-invoker-name>jboss:service=invoker,type=jrmp</jmx-invoker-name>
           <min-pool-size>1</min-pool-size>
           <max-pool-size>100</max-pool-size>
           <blocking-timeout-millis>5000</blocking-timeout-millis>
           <idle-timeout-minutes>15</idle-timeout-minutes>
           <prefill>true</prefill>
           <background-validation>true</background-validation>
           <background-validation-millis>5000</background-validation-millis>
           <validate-on-match>true</validate-on-match>
           <statistics-formatter>org.jboss.resource.statistic.pool.JBossDefaultSubPoolStatisticFormatter</statistics-formatter>
           <isSameRM-override-value>false</isSameRM-override-value>
           <depends>jboss:service=Naming</depends>
           <depends>jboss:service=Hypersonic,database=localDB</depends>
           <metadata>
           <type-mapping>Hypersonic SQL</type-mapping>
           </metadata>
           <local-transaction/>
           <user-name>user</user-name>
           <password>password</password>
           <new-connection-sql>run this on a new conn</new-connection-sql>
           <check-valid-connection-sql>select something from somewhere</check-valid-connection-sql>
           <exception-sorter-class-name>org.jboss.jdbc.SomeExceptionSorter</exception-sorter-class-name>
           <prepared-statement-cache-size>50</prepared-statement-cache-size>
           <share-prepared-statements>false</share-prepared-statements>
           <set-tx-query-timeout>false</set-tx-query-timeout>
           <query-timeout>30000</query-timeout>
           <use-try-lock>0</use-try-lock>
           <driver-class>org.jboss.jdbc.SomeDriver</driver-class>
           <connection-url>jdbc:xyz:a=b</connection-url>
           <connection-property name="cp1-name">cp1-value</connection-property>
           <connection-property name="cp2-name">cp2-value</connection-property>
           </local-tx-datasource>
          </datasources>
          



          • 2. Re: java.beans.XMLEncoder Useless?
            ccrouch

            I don't see an "identifier" attribute? How is it tracked that this is different from the defaultDS datasource say?

            • 3. Re: java.beans.XMLEncoder Useless?
              starksm64

              It wouldn't be. Its different only by virtue of being created by the admin layer. Most attachments don't support an id attribute, so any extra information we want to keep around such as timestamps, change set info, etc. would have to be outside of the attachment serialized form.