io.github.mmm.orm.spi.session.AbstractDbSession Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mmm-orm-spi Show documentation
Show all versions of mmm-orm-spi Show documentation
Service Provider API (SPI) for mmm-orm.
/* 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;
}
}