Archived
0

Hello, MyBatis!

This commit is contained in:
2019-02-26 11:44:45 +03:00
parent 07e8e0c366
commit 6d990d1fb4
16 changed files with 323 additions and 455 deletions

View File

@@ -1,9 +1,9 @@
package ru.prisonlife.api.template;
import org.apache.ibatis.session.SqlSession;
import org.bukkit.Bukkit;
import ru.prisonlife.api.PrisonAPI;
import ru.prisonlife.api.PrisonAPI.Factions;
import ru.prisonlife.api.store.AbstractCachedDao;
import ru.prisonlife.api.store.DailyRespectTaskEntity;
import java.lang.ref.WeakReference;
@@ -28,21 +28,25 @@ public class Faction extends AbstractApiData {
if (refDailyRespectTaskEntity != null && (entity = refDailyRespectTaskEntity.get()) != null) {
return entity;
} else {
final AbstractCachedDao<DailyRespectTaskEntity> cachedDao = PrisonAPI.getDailyRespectTaskDao();
entity = cachedDao.findByUuid(me.getPlayer().getUniqueId())
.orElseThrow(() -> new RuntimeException(
"no data in db by '" + me.getPlayer().getUniqueId().toString() + "'"));
final SqlSession session = PrisonAPI.getSqlStore().openSession();
entity = session.selectOne("DailyRespectTask.selectOne", me.getPlayer().getUniqueId().toString());
session.close();
if (entity == null) {
throw new RuntimeException("no data in db by '" + me.getPlayer().getUniqueId().toString() + "'");
}
refDailyRespectTaskEntity = new WeakReference<>(entity);
return entity;
}
}
public String getType() {
return getPlayerStatsEntity().getFaction().name();
return Factions.valueOf(getPlayerStatsEntity().getFaction()).name();
}
public int getId() {
return getPlayerStatsEntity().getFaction().getId();
return getPlayerStatsEntity().getFaction();
}
public int getRangId() {
@@ -62,7 +66,7 @@ public class Faction extends AbstractApiData {
}
public void setFaction(int id) {
getPlayerStatsEntity().setFaction(Factions.valueOf(id));
getPlayerStatsEntity().setFaction(id);
}
public int getRespect() {