Skip to content

Commit

Permalink
Merge pull request #377 from Burnouttt/hibernate-bugfix
Browse files Browse the repository at this point in the history
0.23.4-ALPHA
  • Loading branch information
TikhomirovSergey authored Oct 13, 2022
2 parents d9b1ee4 + 7567330 commit a7aca95
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 68 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

ext {
globalVersion = '0.23.3-ALPHA'
globalVersion = '0.23.4-ALPHA'
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import ru.tinkoff.qa.neptune.database.abstractions.InsertQuery;
import ru.tinkoff.qa.neptune.database.abstractions.SelectQuery;
import ru.tinkoff.qa.neptune.database.abstractions.UpdateAction;
import ru.tinkoff.qa.neptune.hibernate.delete.DeleteAllFromStepSupplier;
import ru.tinkoff.qa.neptune.hibernate.delete.DeleteByQueryStepSupplier;
import ru.tinkoff.qa.neptune.hibernate.exception.HibernateConfigurationException;
import ru.tinkoff.qa.neptune.hibernate.save.SaveStepSupplier;
Expand Down Expand Up @@ -278,11 +277,6 @@ public <R> HibernateContext delete(String description, Iterable<R> toDelete) {
return this;
}

public HibernateContext deleteAllFrom(Class<?> entityCls) {
delete(DeleteAllFromStepSupplier.deleteAllRecords(entityCls));
return this;
}

@Override
protected <R, S, Q extends SequentialGetStepSupplier<HibernateContext, S, ?, ?, ?> & SelectQuery<S>> S update(Q query, UpdateAction<R>... actions) {
return get(((SaveStepSupplier<?, S, R>) query).setUpdates(actions));
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ru.tinkoff.qa.neptune.hibernate.HibernateContext;

import java.util.ArrayList;
import java.util.HashSet;

import static com.google.common.base.Preconditions.checkNotNull;

Expand All @@ -23,14 +24,17 @@ public void setToSave(Iterable<R> listToSave) {

public void saveObjects(HibernateContext context) {
var savedList = new ArrayList<R>();
var sessions = new ArrayList<Session>();
var sessions = new HashSet<Session>();

for (var toSave : listToSave) {
var sessionFactory = context.getSessionFactoryByEntity(toSave.getClass());
var session = sessionFactory.getCurrentSession();
sessions.add(session);
var persistenceUnitUtil = sessionFactory.getPersistenceUnitUtil();
session.beginTransaction();

if (!session.getTransaction().isActive()) {
session.beginTransaction();
}

if (persistenceUnitUtil.getIdentifier(toSave) != null) {
var obj = session.merge(toSave);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void prepareClass() {
when(session.merge(TEST_ENTITIES.get(1))).thenReturn(TEST_ENTITIES.get(1));

when(criteriaBuilder.createCriteriaDelete(TestEntity.class)).thenReturn(criteriaDelete);
when(session.createQuery(criteriaDelete)).thenReturn(query);
}

@Test
Expand Down Expand Up @@ -89,16 +88,6 @@ public void deleteIterableTest() {
}
}

@Test
public void deleteAllTest() {
try (var mockedStatic = Mockito.mockStatic(Persistence.class)) {
mockPersistence(mockedStatic);

hibernate().deleteAllFrom(TestEntity.class);
verify(session, times(1)).createQuery(criteriaDelete);
}
}

@AfterMethod(alwaysRun = true)
public void clearInvocations() {
Mockito.clearInvocations(session);
Expand Down

0 comments on commit a7aca95

Please sign in to comment.