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

io.github.mmm.orm.spi.session.AbstractDbSession Maven / Gradle / Ivy

There is a newer version: 0.9.8
Show newest version
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0 */
package io.github.mmm.orm.spi.session;

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

import io.github.mmm.entity.bean.EntityBean;
import io.github.mmm.orm.connection.DbConnectionData;
import io.github.mmm.orm.spi.session.impl.DbEntitySessionDefault;

/**
 * Database session data for a single transaction.
 *
 * @since 1.0.0
 */
public abstract class AbstractDbSession implements DbSession {

  private Map> entitySessions;

  /** @see #getConnectionData() */
  protected final DbConnectionData connectionData;

  /**
   * The constructor.
   *
   * @param connectionData the {@link DbConnectionData}.
   */
  protected AbstractDbSession(DbConnectionData connectionData) {

    super();
    this.connectionData = connectionData;
    this.entitySessions = new HashMap<>();
    // String mode = this.connectionData.getConfig().get(DbSource.KEY_ENTITY_MODE);
  }

  @SuppressWarnings({ "rawtypes", "unchecked" })
  @Override
  public  DbEntitySession get(E entity) {

    String key = entity.getType().getQualifiedName();
    DbEntitySession session = this.entitySessions.computeIfAbsent(key, k -> newEntitySession(entity));
    return session;
  }

  private  DbEntitySession newEntitySession(E entity) {

    return new DbEntitySessionDefault<>(entity);
  }

  @Override
  public DbConnectionData getConnectionData() {

    return this.connectionData;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy