0

最近、hibernate3 から hibernate5 にアップグレードしましたaddDocument(org.w3c.dom.Document doc)。非推奨のメソッドが使用されているコードがあります。addUrlそれを、addResource、またはに置き換えたいのですが、そのaddFile方法がわかりません。

    public MyHibernateMapping getHibernateConfiguration(final String tableName, final ColumnMetaInfo[] columnMetaInfos, final DatabaseType dbType, SynchronizationResult messages) throws ParserConfigurationException {

    if(tableName == null) {
      throw new IllegalArgumentException("parameter 'tableName' must not be null"); //$NON-NLS-1$
    }

    final MyHibernateMapping result = new MyHibernateMapping();
    result.mColumnMapping = new HashMap<>();

    final Configuration configuration = new Configuration();
    configuration.setProperty(Environment.DIALECT, ScaHibernateHelper.getDialect(dbType));

    configuration.setProperty(Environment.SHOW_SQL, "false"); //$NON-NLS-1$

    final Document hibernateMappingDocument = XmlWriter.createDocument();

    final Element hibernateMapping = XmlWriter.appendElement(hibernateMappingDocument, "hibernate-mapping"); //$NON-NLS-1$
    hibernateMapping.setAttribute("default-access", MapAccessor.class.getName()); //$NON-NLS-1$

    final Element classMapping = XmlWriter.appendElement(hibernateMapping, "class"); //$NON-NLS-1$
    classMapping.setAttribute("name", java.util.HashMap.class.getName()); //$NON-NLS-1$
    classMapping.setAttribute("table", tableName); //$NON-NLS-1$

    boolean hasPrimaryKey = false;
    boolean hasCompositeKey = hasCompositeKey(columnMetaInfos);

    //first add the key
    if(hasCompositeKey)
    {
      hasPrimaryKey = true;

      final Element compositeId = XmlWriter.appendElement(classMapping, "composite-id"); //$NON-NLS-1$
      for (final ColumnMetaInfo columnMetaInfo : columnMetaInfos) {
        if(columnMetaInfo.isPrimaryKey())
        {
          final Element key = XmlWriter.appendElement(compositeId, "key-property"); //$NON-NLS-1$
          final String quotedName = getMappedProperty(key, columnMetaInfo, messages);
          result.mColumnMapping.put(columnMetaInfo.getName(), quotedName);
        }
      }
    }
    else
    {
      for (final ColumnMetaInfo columnMetaInfo : columnMetaInfos) {
        if(columnMetaInfo.isPrimaryKey())
        {
          final Element id = XmlWriter.appendElement(classMapping, "id"); //$NON-NLS-1$
          final String quotedName = getMappedProperty(id, columnMetaInfo, messages);
          result.mColumnMapping.put(columnMetaInfo.getName(), quotedName);

          hasPrimaryKey = true;
          break;
        }
      }
    }

    for (ColumnMetaInfo columnMetaInfo2 : columnMetaInfos) {
      ColumnMetaInfo columnMetaInfo = columnMetaInfo2;
      final Element property;
      if(!columnMetaInfo.isPrimaryKey())
      {
        property = XmlWriter.appendElement(classMapping, "property"); //$NON-NLS-1$
        final String quotedName = getMappedProperty(property, columnMetaInfo, messages);

        result.mColumnMapping.put(columnMetaInfo.getName(), quotedName);
      }
    }

    if(!hasPrimaryKey)
    {
      final Element property = XmlWriter.appendElement(classMapping, "id"); //$NON-NLS-1$
      property.setAttribute("name", PRIMARY_KEY_NAME); //$NON-NLS-1$
      property.setAttribute("column", "id_pk"); //$NON-NLS-1$ //$NON-NLS-2$
      property.setAttribute("type", "long"); //$NON-NLS-1$ //$NON-NLS-2$
      result.mUseGeneratedKey = true;
    }

    // create a additional timestamp column that will be used during the synchronization mechanism
    final Element property = XmlWriter.appendElement(classMapping, "property"); //$NON-NLS-1$
    property.setAttribute("name", SYNCHRONIZED_ON); //$NON-NLS-1$
    property.setAttribute("column", SYNCHRONIZED_ON); //$NON-NLS-1$
    property.setAttribute("type", "timestamp"); //$NON-NLS-1$ //$NON-NLS-2$


    configuration.addDocument(hibernateMappingDocument); //this should be replaced with other method

    result.mConfiguration = configuration;
    return result;}

これが私の方法であり、 configuration.addDocument(hibernateMappingDocument)の代わりに、 addUrl、addResource、または addFile などの別のものを使用したいと考えています。

4

0 に答える 0