List<ConnectorConfigurationJPAEntity> oldEntities = searchForMetadata(config
.getMetaData());
if (oldEntities.size() > 1) {
throw new PersistenceException(
"Unexpected error: Found more than 1 object fitting the metadata!");
}
ConnectorConfigurationJPAEntity entity = ConnectorConfigurationJPAEntity
.generateFromConfigItem(config);
if (oldEntities.size() == 1) {
ConnectorConfigurationJPAEntity old = oldEntities.get(0);
old.setConnectorType(entity.getConnectorType());
old.setDomainType(entity.getDomainType());
old.setAttributes(entity.getAttributes());
old.setProperties(entity.getProperties());
try {
synchronized (entityManager) {
entityManager.merge(old);
}
} catch (Exception ex) {
throw new PersistenceException(ex);
}
LOGGER.info("updated ConnectorConfiguration");
} else {
try {
synchronized (entityManager) {
entityManager.persist(entity);
}
} catch (Exception ex) {
throw new PersistenceException(ex);
}
LOGGER.info("inserted ConnectorConfiguration");
}
}