private void createPersonTable(Set<String> tables) {
    if (!tables.contains("PERSON")) {
      SQL.insert(SQLs.PERSON_CREATE_TABLE);
      LOG.info("Database table 'PERSON' created");

      if (CONFIG.getPropertyValue(ConfigProperties.DatabaseAutoPopulateProperty.class)) {
        createPersonEntry(
            "Alice",
            null,
            "http://www.uergsel.de/uploads/Alice.png",
            DateUtility.parse("26.11.1865", "dd.MM.yyyy"),
            "F",
            "Daresbury, Cheshire",
            "GB",
            "The curious girl",
            ORGANISATION1);
        createPersonEntry(
            "Rabbit",
            "the White",
            "https://upload.wikimedia.org/wikipedia/commons/4/42/The_White_Rabbit_%28Tenniel%29_-_The_Nursery_Alice_%281890%29_-_BL.jpg",
            DateUtility.parse("26.11.1861", "dd.MM.yyyy"),
            "F",
            "Daresbury, Cheshire",
            "GB",
            "Follow me",
            ORGANISATION1);

        LOG.info("Database table 'PERSON' populated with sample data");
      }
    }
  }
  public void autoCreateDatabase() {
    if (CONFIG.getPropertyValue(ConfigProperties.DatabaseAutoCreateProperty.class)) {

      try {
        BEANS
            .get(SuperUserRunContextProducer.class)
            .produce()
            .run(
                new IRunnable() {

                  @Override
                  public void run() throws Exception {
                    Set<String> tables = getExistingTables();
                    createOrganizationTable(tables);
                    createPersonTable(tables);
                  }
                });
      } catch (RuntimeException e) {
        BEANS.get(ExceptionHandler.class).handle(e);
      }
    }
  }
  private void createOrganizationTable(Set<String> tables) {
    if (!tables.contains("ORGANIZATION")) {
      SQL.insert(SQLs.ORGANIZATION_CREATE_TABLE);
      LOG.info("Database table 'ORGANIZATION' created");

      if (CONFIG.getPropertyValue(ConfigProperties.DatabaseAutoPopulateProperty.class)) {
        createOrganizationEntry(
            ORGANISATION1,
            "London",
            "GB",
            "http://en.wikipedia.org/wiki/Alice%27s_Adventures_in_Wonderland",
            "https://upload.wikimedia.org/wikipedia/en/3/3f/Alice_in_Wonderland%2C_cover_1865.jpg");
        createOrganizationEntry(
            "BSI Business Systems Integration AG",
            "Daettwil, Baden",
            "CH",
            "https://www.bsi-software.com",
            "https://wiki.eclipse.org/images/4/4f/Bsiag.png");

        LOG.info("Database table 'ORGANIZATION' populated with sample data");
      }
    }
  }
/**
 * Wraps a JAX-WS handler, so that the handler can be invoked from within {@link RunContext}. The
 * invocation is done via {@link IBeanManager}, meaning that the handler is to be annotated with
 * {@link ApplicationScoped} annotation. Also, this class adds support to inject <em>init
 * parameters</em> to the handler.
 *
 * <p>To be invoked in a {@link RunContext}, annotate the handler with {@link RunWithRunContext}
 * annotation.
 *
 * @since 5.1
 */
public class HandlerDelegate<CONTEXT extends MessageContext> implements Handler<CONTEXT> {

  private static final Logger LOG = LoggerFactory.getLogger(HandlerDelegate.class);

  private static final Subject HANDLER_SUBJECT =
      CONFIG.getPropertyValue(JaxWsHandlerSubjectProperty.class);

  private final Handler<CONTEXT> m_handler;

  private final RunContextProducer m_handlerRunContextProducer;

  @SuppressWarnings("unchecked")
  public HandlerDelegate(
      final org.eclipse.scout.rt.server.jaxws.provider.annotation.Handler handlerAnnotation) {
    m_handler =
        BEANS.get(ClazzUtil.resolve(handlerAnnotation.value(), Handler.class, "@Handler.value"));

    final RunWithRunContext runHandleWithRunContext =
        m_handler.getClass().getAnnotation(RunWithRunContext.class);
    m_handlerRunContextProducer =
        (runHandleWithRunContext != null ? BEANS.get(runHandleWithRunContext.value()) : null);

    injectInitParams(m_handler, toInitParamMap(handlerAnnotation.initParams()));
  }

  @Override
  public boolean handleMessage(final CONTEXT messageContext) {
    return handle(
        messageContext,
        "handleMessage",
        new Callable<Boolean>() {

          @Override
          public Boolean call() throws Exception {
            return m_handler.handleMessage(messageContext);
          }
        });
  }

  @Override
  public boolean handleFault(final CONTEXT messageContext) {
    return handle(
        messageContext,
        "handleFault",
        new Callable<Boolean>() {

          @Override
          public Boolean call() throws Exception {
            return m_handler.handleFault(messageContext);
          }
        });
  }

  @Override
  public void close(final MessageContext messageContext) {
    handle(
        messageContext,
        "close",
        new Callable<Void>() {

          @Override
          public Void call() throws Exception {
            m_handler.close(messageContext);
            return null;
          }
        });
  }

  /**
   * Method invoked to optionally run the given {@link Callable} on behalf of a {@link RunContext}.
   */
  @Internal
  protected <T> T handle(
      final MessageContext messageContext, final String method, final Callable<T> callable) {
    try {
      if (m_handlerRunContextProducer == null) {
        return callable.call();
      } else {
        final Subject subject = MessageContexts.getSubject(messageContext, HANDLER_SUBJECT);
        return m_handlerRunContextProducer
            .produce(subject)
            .call(
                new Callable<T>() {
                  @Override
                  public T call() throws Exception {
                    return callable.call();
                  }
                },
                DefaultExceptionTranslator.class);
      }
    } catch (final Exception e) {
      LOG.error(
          "Failed to handle message [handler={}, method={}, inbound={}]",
          m_handler.getClass().getName(),
          method,
          MessageContexts.isInboundMessage(messageContext),
          e);
      throw new HTTPException(
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR); // do not send cause to the client
    }
  }

  /** @return original handler this handler delegates to. */
  protected Handler<CONTEXT> getHandlerDelegate() {
    return m_handler;
  }

  /** Injects the given 'init-params' into the given handler. */
  @Internal
  protected void injectInitParams(
      final Handler<CONTEXT> handler, final Map<String, String> initParams) {
    for (final Field field : handler.getClass().getDeclaredFields()) {
      if (field.getAnnotation(Resource.class) != null
          && field.getType().isAssignableFrom(initParams.getClass())) {
        try {
          LOG.info(
              "Inject 'initParams' to JAX-WS handler [path={}#{}]",
              handler.getClass().getName(),
              field.getName());
          field.setAccessible(true);
          field.set(handler, initParams);
          return;
        } catch (final ReflectiveOperationException e) {
          throw new PlatformException(
              "Failed to inject 'InitParams' for handler '{}'", handler.getClass().getName(), e);
        }
      }
    }

    if (!initParams.isEmpty()) {
      LOG.warn(
          "'InitParams' could not be injected into handler because no field found that is of type Map<String, String> and annotated with @Resource [handler={}, initParams={}]",
          handler.getClass().getName(),
          initParams);
    }
  }

  @Internal
  protected Map<String, String> toInitParamMap(final InitParam[] initParams) {
    final Map<String, String> map = new HashMap<>(initParams.length);
    for (final InitParam initParam : initParams) {
      map.put(initParam.key(), initParam.value());
    }
    return map;
  }
}