All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ebeaninternal.server.core.InternalConfigXmlMap Maven / Gradle / Ivy

There is a newer version: 15.8.0
Show newest version
package io.ebeaninternal.server.core;

import io.ebeaninternal.api.CoreLog;
import io.ebeaninternal.server.dto.DtoNamedQueries;
import io.ebeaninternal.xmapping.api.XmapDto;
import io.ebeaninternal.xmapping.api.XmapEbean;
import io.ebeaninternal.xmapping.api.XmapRawSql;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.lang.System.Logger.Level.ERROR;

/**
 * Reads the Xml deployment information.
 */
final class InternalConfigXmlMap {

  private final List xmlEbeanList;
  private final ClassLoader classLoader;
  private final Map, DtoNamedQueries> dtoNamedQueries = new HashMap<>();

  InternalConfigXmlMap(List xmlEbeanList, ClassLoader classLoader) {
    this.xmlEbeanList = xmlEbeanList;
    this.classLoader = classLoader;
    initDtoMapping();
  }

  void initDtoMapping() {
    if (xmlEbeanList != null) {
      for (XmapEbean mapping : xmlEbeanList) {
        List dtoList = mapping.getDto();
        for (XmapDto dto : dtoList) {
          readDtoMapping(dto);
        }
      }
    }
  }

  /**
   * Return the XML deployment information for entity beans.
   */
  List xmlDeployment() {
    return xmlEbeanList;
  }

  /**
   * Return the named queries for Dto beans.
   */
  Map, DtoNamedQueries> readDtoMapping() {
    return dtoNamedQueries;
  }

  private void readDtoMapping(XmapDto dto) {
    Class dtoClass;
    try {
      dtoClass = Class.forName(dto.getClazz(), false, classLoader);
    } catch (Exception e) {
      CoreLog.internal.log(ERROR, "Could not load dto bean class " + dto.getClazz() + " for ebean xml entry");
      return;
    }
    DtoNamedQueries namedQueries = dtoNamedQueries.computeIfAbsent(dtoClass, aClass -> new DtoNamedQueries());
    for (XmapRawSql sql : dto.getRawSql()) {
      namedQueries.addRawSql(sql.getName(), sql.getQuery());
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy