use of javax.persistence.EntityExistsException in project hibernate-orm by hibernate.
the class EntityManagerTest method testPersistExisting.
@Test
public void testPersistExisting() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Wallet w = new Wallet();
w.setBrand("Lacoste");
w.setModel("Minimic");
w.setSerial("0100202002");
em.persist(w);
w = new Wallet();
w.setBrand("Lacoste");
w.setModel("Minimic");
w.setSerial("0100202002");
try {
em.persist(w);
} catch (EntityExistsException eee) {
//success
if (em.getTransaction() != null) {
em.getTransaction().rollback();
}
em.close();
return;
}
try {
em.getTransaction().commit();
fail("Should have raised an exception");
} catch (PersistenceException pe) {
} finally {
em.close();
}
}
use of javax.persistence.EntityExistsException in project cloudstack by apache.
the class CiscoVnmcElement method addCiscoAsa1000vResource.
@Override
public CiscoAsa1000vDevice addCiscoAsa1000vResource(AddCiscoAsa1000vResourceCmd cmd) {
Long physicalNetworkId = cmd.getPhysicalNetworkId();
CiscoAsa1000vDevice ciscoAsa1000vResource = null;
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork == null) {
throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
}
ciscoAsa1000vResource = new CiscoAsa1000vDeviceVO(physicalNetworkId, cmd.getManagementIp().trim(), cmd.getInPortProfile(), cmd.getClusterId());
try {
_ciscoAsa1000vDao.persist((CiscoAsa1000vDeviceVO) ciscoAsa1000vResource);
} catch (EntityExistsException e) {
throw new InvalidParameterValueException("An ASA 1000v appliance already exists with same configuration");
}
return ciscoAsa1000vResource;
}
use of javax.persistence.EntityExistsException in project cloudstack by apache.
the class ServiceOfferingDaoImpl method persistSystemServiceOffering.
@Override
@DB
public ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO offering) {
assert offering.getUniqueName() != null : "how are you going to find this later if you don't set it?";
ServiceOfferingVO vo = findByName(offering.getUniqueName());
if (vo != null) {
// check invalid CPU speed in system service offering, set it to default value of 500 Mhz if 0 CPU speed is found
if (vo.getSpeed() <= 0) {
vo.setSpeed(500);
update(vo.getId(), vo);
}
if (!vo.getUniqueName().endsWith("-Local")) {
if (vo.getUseLocalStorage()) {
vo.setUniqueName(vo.getUniqueName() + "-Local");
vo.setName(vo.getName() + " - Local Storage");
update(vo.getId(), vo);
}
}
return vo;
}
try {
return persist(offering);
} catch (EntityExistsException e) {
// Assume it's conflict on unique name
return findByName(offering.getUniqueName());
}
}
use of javax.persistence.EntityExistsException in project API by ca-cwds.
the class CrossReportService method create.
/**
* {@inheritDoc}
*
* @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
*/
@Override
public gov.ca.cwds.rest.api.domain.cms.CrossReport create(Request request) {
assert request instanceof gov.ca.cwds.rest.api.domain.cms.CrossReport;
gov.ca.cwds.rest.api.domain.cms.CrossReport crossReport = (gov.ca.cwds.rest.api.domain.cms.CrossReport) request;
try {
String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
CrossReport managed = new CrossReport(CmsKeyIdGenerator.cmsIdGenertor(lastUpdatedId), crossReport, lastUpdatedId);
managed = crossReportDao.create(managed);
return new gov.ca.cwds.rest.api.domain.cms.CrossReport(managed);
} catch (EntityExistsException e) {
LOGGER.info("CrossReport already exists : {}", crossReport);
throw new ServiceException("CrossReport already exists : {}" + crossReport, e);
}
}
use of javax.persistence.EntityExistsException in project API by ca-cwds.
the class LongTextService method create.
/**
* {@inheritDoc}
*
* @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
*/
@Override
public PostedLongText create(Request request) {
assert request instanceof gov.ca.cwds.rest.api.domain.cms.LongText;
gov.ca.cwds.rest.api.domain.cms.LongText longText = (gov.ca.cwds.rest.api.domain.cms.LongText) request;
try {
String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
LongText managed = new LongText(CmsKeyIdGenerator.cmsIdGenertor(lastUpdatedId), longText, lastUpdatedId);
managed = longTextDao.create(managed);
return new PostedLongText(managed);
} catch (EntityExistsException e) {
LOGGER.info("LongText already exists : {}", longText);
throw new ServiceException(e);
}
}
Aggregations