use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class JpaSnapshotDao method doRemove.
@Transactional
protected void doRemove(String snapshotId) throws NotFoundException {
final EntityManager manager = managerProvider.get();
final SnapshotImpl snapshot = manager.find(SnapshotImpl.class, snapshotId);
if (snapshot == null) {
throw new NotFoundException(format("Snapshot with id '%s' doesn't exist", snapshotId));
}
manager.remove(snapshot);
}
use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class JpaSnapshotDao method doReplaceSnapshots.
@Transactional
protected List<SnapshotImpl> doReplaceSnapshots(String workspaceId, String envName, Collection<? extends SnapshotImpl> newSnapshots) {
final EntityManager manager = managerProvider.get();
final List<SnapshotImpl> existing = manager.createNamedQuery("Snapshot.findByWorkspaceAndEnvironment", SnapshotImpl.class).setParameter("workspaceId", workspaceId).setParameter("envName", envName).getResultList();
existing.forEach(manager::remove);
manager.flush();
newSnapshots.forEach(manager::persist);
return existing;
}
use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class SnapshotDaoTest method shouldFindSnapshotsByWorkspaceAndNamespace.
@Test
public void shouldFindSnapshotsByWorkspaceAndNamespace() throws Exception {
final SnapshotImpl snapshot = snapshots[0];
final List<SnapshotImpl> found = snapshotDao.findSnapshots(snapshot.getWorkspaceId());
assertEquals(new HashSet<>(found), new HashSet<>(asList(snapshots[0], snapshots[1], snapshots[2])));
}
use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class SnapshotDaoTest method replacesSnapshots.
@Test(dependsOnMethods = "shouldFindSnapshotsByWorkspaceAndNamespace")
public void replacesSnapshots() throws Exception {
final SnapshotImpl newSnapshot = createSnapshot("new-snapshot", snapshots[0].getWorkspaceId(), snapshots[0].getEnvName(), snapshots[0].getMachineName());
final List<SnapshotImpl> replaced = snapshotDao.replaceSnapshots(newSnapshot.getWorkspaceId(), newSnapshot.getEnvName(), singletonList(newSnapshot));
assertEquals(new HashSet<>(replaced), Sets.newHashSet(snapshots[0], snapshots[1]));
final HashSet<SnapshotImpl> actual = new HashSet<>(snapshotDao.findSnapshots(this.snapshots[0].getWorkspaceId()));
final HashSet<SnapshotImpl> expected = Sets.newHashSet(newSnapshot, this.snapshots[2]);
assertEquals(actual, expected);
}
use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class SnapshotDaoTest method shouldGetSnapshotByWorkspaceEnvironmentAndMachineName.
@Test
public void shouldGetSnapshotByWorkspaceEnvironmentAndMachineName() throws Exception {
final SnapshotImpl snapshot = snapshots[0];
assertEquals(snapshotDao.getSnapshot(snapshot.getWorkspaceId(), snapshot.getEnvName(), snapshot.getMachineName()), snapshot);
}
Aggregations