将(自动生成的)EJB代码从Websphere转换为Glassfish

时间:2019-02-18 17:07:14

标签: java glassfish ejb websphere

我有一个现有的旧版Java应用程序,该应用程序旨在在Websphere 7.0环境中运行。我们正在从Websphere转向Glassfish。此代码的原始开发人员不在身边,并且按预期没有文档。

大多数转换很简单。但是,EJB 2.1代码有问题。 bean定义本身很好,但是有许多辅助代码与IBM Websphere库非常非常紧密地结合在一起,而且似乎不需要完全重写就可以转换。

一个例子:

/**
 * MyBeanAdaptorBinding_ebb6f53f
 */
public class MyBeanAdaptorBinding_ebb6f53f implements com.ibm.ws.ejbpersistence.beanextensions.EJBAdapterBinding {
    /**
     * getExtractor
     */
    public com.ibm.ws.ejbpersistence.dataaccess.EJBExtractor getExtractor() {
        // extractor for mypackage.entity.websphere_deploy.ORACLE_V11_1.MyBeanExtractor_ebb6f53f
        com.ibm.ws.ejbpersistence.dataaccess.AbstractEJBExtractor extractor =  new mypackage.entity.websphere_deploy.ORACLE_V11_1.MyBeanExtractor_ebb6f53f();
        extractor.setPrimaryKeyColumns(new int[] {1});
        extractor.setDataColumns(new int[] {1,2});
        return extractor;
    }
    /**
     * getInjector
     */
    public com.ibm.ws.ejbpersistence.beanextensions.EJBInjector getInjector() {
        return new mypackage.entity.websphere_deploy.ORACLE_V11_1.MyBeanInjectorImpl_ebb6f53f();
    }
    /**
     * getAdapter
     */
    public com.ibm.websphere.ejbpersistence.EJBToRAAdapter getAdapter() {
        return com.ibm.ws.rsadapter.cci.WSRelationalRAAdapter.createAdapter();
    }
    /**
     * getMetadata
     */
    public Object[] getMetadata() {

        java.lang.String[] primarykey, subhomes, composedObjs, composedObjImpls;
        com.ibm.ObjectQuery.metadata.OSQLExternalCatalogEntry[] cat;
        com.ibm.ObjectQuery.metadata.OSQLExternalColumnDef[] fields;
        cat = new com.ibm.ObjectQuery.metadata.OSQLExternalCatalogEntry[5];

        //-------------------------------------Alias-------------------------------------
        cat[0] = new com.ibm.ObjectQuery.metadata.OSQLExternalCatalogRDBAlias("My", "My1_Alias", "ORACLE", "MYSCHEMA.My", "My_My1_Table", 11, 0, 0);


        //-----------------------------------Table Type-----------------------------------
        fields = new com.ibm.ObjectQuery.metadata.OSQLExternalColumnDef[2];

        fields[0] = new com.ibm.ObjectQuery.metadata.OSQLExternalColumnDef("MyID", new String(), com.ibm.ObjectQuery.engine.OSQLConstants.NOT_APPLICABLE, new String(), com.ibm.ObjectQuery.engine.OSQLConstants.NOT_APPLICABLE, true, com.ibm.ObjectQuery.engine.OSQLSymbols._CHARACTER, 250, com.ibm.ObjectQuery.engine.OSQLConstants.NO_TYPE, true, 0, -1, 0, false);
        fields[1] = new com.ibm.ObjectQuery.metadata.OSQLExternalColumnDef("MyNM", new String(), com.ibm.ObjectQuery.engine.OSQLConstants.NOT_APPLICABLE, new String(), com.ibm.ObjectQuery.engine.OSQLConstants.NOT_APPLICABLE, true, com.ibm.ObjectQuery.engine.OSQLSymbols._CHARACTER, 250, com.ibm.ObjectQuery.engine.OSQLConstants.NO_TYPE, false, 0, -1, 0, false);
        primarykey = new String[1];
        primarykey[0] = "MyID";
        cat[1] = new com.ibm.ObjectQuery.metadata.OSQLExternalCatalogType("My", "My1_Table", null, fields, primarykey);


        //-----------------------------------Bean Type-----------------------------------
        fields = new com.ibm.ObjectQuery.metadata.OSQLExternalColumnDef[2];

        fields[0] = new com.ibm.ObjectQuery.metadata.OSQLExternalColumnDef("MyId", new String(), com.ibm.ObjectQuery.engine.OSQLConstants.NOT_APPLICABLE, new String(), com.ibm.ObjectQuery.engine.OSQLConstants.NOT_APPLICABLE, true, com.ibm.ObjectQuery.engine.OSQLSymbols._CHARACTER, 0, com.ibm.ObjectQuery.engine.OSQLConstants.NO_TYPE, false, 0, -1, 0, false);
        fields[1] = new com.ibm.ObjectQuery.metadata.OSQLExternalColumnDef("MyNm", new String(), com.ibm.ObjectQuery.engine.OSQLConstants.NOT_APPLICABLE, new String(), com.ibm.ObjectQuery.engine.OSQLConstants.NOT_APPLICABLE, true, com.ibm.ObjectQuery.engine.OSQLSymbols._CHARACTER, 0, com.ibm.ObjectQuery.engine.OSQLConstants.NO_TYPE, false, 0, -1, 0, false);
        primarykey = new String[1];
        primarykey[0] = "MyId";
        cat[2] = new com.ibm.ObjectQuery.metadata.OSQLExternalCatalogType("My", "My_BO", "mypackage.entity.MyBean", fields, primarykey);


        //--------------------------------------View--------------------------------------
        composedObjs = null;
        composedObjImpls = null;
        subhomes = null;
        cat[3] = new com.ibm.ObjectQuery.metadata.OSQLExternalCatalogView("My", "My_My_BO", "My_My1_Alias", composedObjs, composedObjImpls, 
        "select t1.MyID,t1.MyNM from _this t1", 
        null, subhomes, 
        0, null);



        cat[4] = new com.ibm.ObjectQuery.metadata.OSQLExternalSysApplOptions(14, false);

        return cat;
    }
    /**
     * createDataAccessSpecs
     */
    public java.util.Collection createDataAccessSpecs() throws javax.resource.ResourceException {
        <snipped long implementation of find/create/delete logic using com.ibm.ws.* classes>
    }
    /**
     * getProperties
     */
    public java.util.HashMap getProperties() {
        properties.put("USING_DB_AUTO_OCC_COLLISION_DETECTION", Boolean.FALSE);
        properties.put("NEED_REFRESH_AFTER_PERSISTENCE", Boolean.FALSE);
        return properties;
    }
    /**
     * MyBeanAdaptorBinding_ebb6f53f
     */
    public MyBeanAdaptorBinding_ebb6f53f() {
        properties = new java.util.HashMap();
        properties.put("VERSION", "7.0.0.0");
    }
    private java.util.HashMap properties;
}

此代码(以及其余大部分代码)似乎是自动生成的:_ebb6f53f后缀,完全指定的类名等。与此同时,还有MyBeanCacheEntry_ebb6f53f,MyBeanExtractor_ebb6f53f,MyBeanFunctionSet_ebb6f53f,MyBeanInjector_ebb6f53f,MyBeanInjector_ebb6f53f,是接口)。每个bean的辅助类集都有一个不同的十六进制字符串后缀。

ejb-jar.xml文件的相关部分:

    <entity id="My">
        <ejb-name>My</ejb-name>
        <local-home>mypackage.entity.MyLocalHome</local-home>
        <local>mypackage.entity.MyLocal</local>
        <ejb-class>mypackage.entity.MyBean</ejb-class>
        <persistence-type>Container</persistence-type>
        <prim-key-class>java.lang.String</prim-key-class>
        <reentrant>false</reentrant>
        <cmp-version>2.x</cmp-version>
        <abstract-schema-name>My</abstract-schema-name>
        <cmp-field id="CMPAttribute_1133536288497">
            <field-name>MyId</field-name>
        </cmp-field>
        <cmp-field id="CMPAttribute_1133536292665">
            <field-name>MyNm</field-name>
        </cmp-field>
        <primkey-field>MyId</primkey-field>
    </entity>

cmp字段ID取自Oracle Map.mapxmi文件。 ejb-jar.xml和Map.mapxmi似乎都没有绑定到Websphere,所以我不认为它们需要修改,但是如果它们 did 我也认为它们也是自动生成的。

这不是行家或蚂蚁项目;构建过程是直接通过Eclipse完成的,并且不会在构建过程中修改/自动生成代码;它只是编译JAR,然后打包WAR和EAR。

我对EJB或Websphere不太了解。在过去的几天里,我已经进行了很多搜索和阅读,但是无法令人满意地回答以下问题:

  1. 该代码是如何生成的(Eclipse或Rational Application Developer工具,特定的Websphere工具等)?
  2. 如何生成ejb-jar.xml和Map.mapxmi文件?
  3. 是否可以在没有com.ibm。*依赖项的情况下为Glassfish重新生成(最好仅在javax。*依赖项下)?
  4. 非Websphere部署是否还需要这种类型的代码?

0 个答案:

没有答案