Skip to content

Commit

Permalink
Use EntityManager for destroying buildings.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgift committed Jul 7, 2024
1 parent d4f82ca commit 7b76fec
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public boolean printHeader() {
@Override
public void cleanup(Context context, Base base, int building) {
super.cleanup(context, base, building);
org.hibernate.Session db = context.getDB();
var db = context.getEM();


Academy academy = base.getAcademy();
Expand All @@ -105,7 +105,7 @@ public void cleanup(Context context, Base base, int building) {
academy.getQueueEntries().clear();

base.setAcademy(null);
db.delete(academy);
db.remove(academy);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public boolean printHeader()
@Override
public void cleanup(Context context, Base base, int buildingid)
{
org.hibernate.Session db = context.getDB();
var db = context.getEM();

Factory wf = loadFactoryEntity(base, buildingid);
if (wf == null)
Expand All @@ -324,7 +324,7 @@ public void cleanup(Context context, Base base, int buildingid)
int id = aPlist.getId();
int count = aPlist.getCount();

FactoryEntry entry = (FactoryEntry) db.get(FactoryEntry.class, id);
FactoryEntry entry = db.find(FactoryEntry.class, id);

usedcapacity = usedcapacity.add(entry.getDauer().multiply(new BigDecimal(count)));
}
Expand All @@ -338,7 +338,7 @@ public void cleanup(Context context, Base base, int buildingid)
int id = plist[i].getId();
int count = plist[i].getCount();

FactoryEntry entry = (FactoryEntry) db.get(FactoryEntry.class, id);
FactoryEntry entry = db.find(FactoryEntry.class, id);

BigDecimal capUsed = new BigDecimal(count).multiply(entry.getDauer());

Expand All @@ -365,7 +365,7 @@ public void cleanup(Context context, Base base, int buildingid)
}
else
{
db.delete(wf);
db.remove(wf);
base.getFactories().remove(wf);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void cleanup(Context context, Base base, int building) {
}
base.setForschungszentrum(null);

org.hibernate.Session db = context.getDB();
db.delete(fz);
var db = context.getEM();
db.remove(fz);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public void build(Base base, int building) {
public void cleanup(Context context, Base base, int building) {
super.cleanup(context, base, building);

org.hibernate.Session db = context.getDB();
Kaserne kaserne = (Kaserne)db.createQuery("from Kaserne where base=:base")
.setEntity("base", base)
.uniqueResult();
var db = context.getEM();
Kaserne kaserne = db.createQuery("from Kaserne where base=:base", Kaserne.class)
.setParameter("base", base)
.getSingleResult();

if( kaserne != null ) {
kaserne.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Kommandozentrale() {
@Override
public void cleanup(Context context, Base base, int building) {
super.cleanup(context, base, building);
org.hibernate.Session db = context.getDB();
var db = context.getEM();

// Loesche alle GTU-Aktionen
base.setAutoGTUActs(new ArrayList<>());
Expand All @@ -104,13 +104,13 @@ public void cleanup(Context context, Base base, int building) {

// Ueberstelle Offiziere
db.createQuery("update Offizier set owner=:owner where stationiertAufBasis=:dest")
.setEntity("owner", nullUser)
.setEntity("dest", base)
.setParameter("owner", nullUser)
.setParameter("dest", base)
.executeUpdate();

// Loesche Verbindungen
db.createQuery("update ShipWerft set linked=null where linked=:base")
.setEntity("base", base)
.setParameter("base", base)
.executeUpdate();

// Loesche Eintraege der Basiswerft
Expand All @@ -130,14 +130,14 @@ public void cleanup(Context context, Base base, int building) {
}

// Auftraege der Kaserne loeschen
Kaserne kaserne = (Kaserne)db.createQuery("from Kaserne where base=:base")
.setEntity("base", base)
.uniqueResult();
Kaserne kaserne = db.createQuery("from Kaserne where base=:base", Kaserne.class)
.setParameter("base", base)
.getResultList().stream().findFirst().orElse(null);

if( kaserne != null ) {
for( KaserneEntry entry : kaserne.getQueueEntries() )
{
db.delete(entry);
db.remove(entry);
}
}

Expand Down

0 comments on commit 7b76fec

Please sign in to comment.