private void setField(final PersistentObject entity, final String fieldName, final Object parameterValue) throws SPersistenceException { Long id = null; try { id = entity.getId(); ClassReflector.setField(entity, fieldName, parameterValue); } catch (final Exception e) { throw new SPersistenceException("Problem while updating entity: " + entity + " with id: " + id, e); } }
private void handleCreationException(final PersistentObject persitentObject, final SPersistenceLogBuilder logBuilder, final Exception e, final String methodName) throws SObjectCreationException { log(persitentObject.getId(), SQueriableLog.STATUS_FAIL, logBuilder, methodName); throw new SObjectCreationException(e); }
private void handleCreationException(final PersistentObject persitentObject, final SPersistenceLogBuilder logBuilder, final Exception e, final String methodName) throws SObjectCreationException { log(persitentObject.getId(), SQueriableLog.STATUS_FAIL, logBuilder, methodName); throw new SObjectCreationException(e); }
private void setField(final PersistentObject entity, final String fieldName, final Object parameterValue) throws SPersistenceException { Long id = null; try { id = entity.getId(); ClassReflector.setField(entity, fieldName, parameterValue); } catch (final Exception e) { throw new SPersistenceException("Problem while updating entity: " + entity + " with id: " + id, e); } }
@Override public void delete(final PersistentObject entity) throws SPersistenceException { try { if (logger.isLoggable(getClass(), TechnicalLogSeverity.DEBUG)) { logger.log(this.getClass(), TechnicalLogSeverity.DEBUG, "[Tenant] Deleting instance of class " + entity.getClass().getSimpleName() + " with id=" + entity.getId()); } final Class<? extends PersistentObject> mappedClass = getMappedClass(entity.getClass()); final Session session = getSession(true); final Object pe = session.get(mappedClass, new PersistentObjectId(entity.getId(), getTenantId())); session.delete(pe); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final STenantIdNotSetException | HibernateException e) { throw new SPersistenceException(e); } }
@Override public void delete(final PersistentObject entity) throws SPersistenceException { try { if (logger.isLoggable(getClass(), TechnicalLogSeverity.DEBUG)) { logger.log(this.getClass(), TechnicalLogSeverity.DEBUG, "[Tenant] Deleting instance of class " + entity.getClass().getSimpleName() + " with id=" + entity.getId()); } final Class<? extends PersistentObject> mappedClass = getMappedClass(entity.getClass()); final Session session = getSession(true); final Object pe = session.get(mappedClass, new PersistentObjectId(entity.getId(), getTenantId())); session.delete(pe); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final STenantIdNotSetException | HibernateException e) { throw new SPersistenceException(e); } }
@Override public void delete(final PersistentObject entity) throws SPersistenceException { if (logger.isLoggable(getClass(), TechnicalLogSeverity.DEBUG)) { logger.log(this.getClass(), TechnicalLogSeverity.DEBUG, "Deleting instance of class " + entity.getClass().getSimpleName() + " with id=" + entity.getId()); } final Class<? extends PersistentObject> mappedClass = getMappedClass(entity.getClass()); final Session session = getSession(true); try { if (session.contains(entity)) { session.delete(entity); } else { // Deletion must be performed on the session entity and not on a potential transitional entity. final Object pe = session.get(mappedClass, new PersistentObjectId(entity.getId(), 0)); session.delete(pe); } } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException he) { throw new SPersistenceException(he); } }
@Override public void delete(final PersistentObject entity) throws SPersistenceException { if (logger.isLoggable(getClass(), TechnicalLogSeverity.DEBUG)) { logger.log(this.getClass(), TechnicalLogSeverity.DEBUG, "Deleting instance of class " + entity.getClass().getSimpleName() + " with id=" + entity.getId()); } final Class<? extends PersistentObject> mappedClass = getMappedClass(entity.getClass()); final Session session = getSession(true); try { if (session.contains(entity)) { session.delete(entity); } else { // Deletion must be performed on the session entity and not on a potential transitional entity. final Object pe = session.get(mappedClass, new PersistentObjectId(entity.getId(), 0)); session.delete(pe); } } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException he) { throw new SPersistenceException(he); } }
protected void setId(final PersistentObject entity) throws SPersistenceException { if (entity == null) { return; } // if this entity has no id, set it Long id = null; try { id = entity.getId(); } catch (final Exception e) { // this is a new object to save } if (id == null || id == -1 || id == 0) { try { id = getSequenceManager().getNextId(entity.getClass().getName(), getTenantId()); ClassReflector.invokeSetter(entity, "setId", long.class, id); } catch (final Exception e) { throw new SPersistenceException("Problem while saving entity: " + entity + " with id: " + id, e); } } }
protected void setId(final PersistentObject entity) throws SPersistenceException { if (entity == null) { return; } // if this entity has no id, set it Long id = null; try { id = entity.getId(); } catch (final Exception e) { // this is a new object to save } if (id == null || id == -1 || id == 0) { try { id = getSequenceManager().getNextId(entity.getClass().getName(), getTenantId()); ClassReflector.invokeSetter(entity, "setId", long.class, id); } catch (final Exception e) { throw new SPersistenceException("Problem while saving entity: " + entity + " with id: " + id, e); } } }
SConnectorInstance createConnectorInstanceObject(PersistentObject container, String containerType, SConnectorDefinition sConnectorDefinition, int executionOrder) { return BuilderFactory .get(SConnectorInstanceBuilderFactory.class) .createNewInstance(sConnectorDefinition.getName(), container.getId(), containerType, sConnectorDefinition.getConnectorId(), sConnectorDefinition.getVersion(), sConnectorDefinition.getActivationEvent(), executionOrder) .done(); }
SConnectorInstance createConnectorInstanceObject(PersistentObject container, String containerType, SConnectorDefinition sConnectorDefinition, int executionOrder) { return BuilderFactory .get(SConnectorInstanceBuilderFactory.class) .createNewInstance(sConnectorDefinition.getName(), container.getId(), containerType, sConnectorDefinition.getConnectorId(), sConnectorDefinition.getVersion(), sConnectorDefinition.getActivationEvent(), executionOrder) .done(); }
private SCategory addCategory(final String name, final String description) throws SCategoryCreationException { final SCategoryLogBuilder logBuilder = getQueriableLog(ActionType.CREATED, "Creating a new category with name " + name); final long creator; creator = getCreator(); final SCategory sCategory = BuilderFactory.get(SCategoryBuilderFactory.class).createNewInstance(name, creator).setDescription(description).done(); final InsertRecord insertRecord = new InsertRecord(sCategory); try { recorder.recordInsert(insertRecord, CATEGORY); initiateLogBuilder(insertRecord.getEntity().getId(), SQueriableLog.STATUS_OK, logBuilder, "addCategory"); return sCategory; } catch (final SRecorderException e) { initiateLogBuilder(insertRecord.getEntity().getId(), SQueriableLog.STATUS_FAIL, logBuilder, "addCategory"); throw new SCategoryCreationException(e); } }
private SCategory addCategory(final String name, final String description) throws SCategoryCreationException { final SCategoryLogBuilder logBuilder = getQueriableLog(ActionType.CREATED, "Creating a new category with name " + name); final long creator; creator = getCreator(); final SCategory sCategory = BuilderFactory.get(SCategoryBuilderFactory.class).createNewInstance(name, creator).setDescription(description).done(); final InsertRecord insertRecord = new InsertRecord(sCategory); try { recorder.recordInsert(insertRecord, CATEGORY); initiateLogBuilder(insertRecord.getEntity().getId(), SQueriableLog.STATUS_OK, logBuilder, "addCategory"); return sCategory; } catch (final SRecorderException e) { initiateLogBuilder(insertRecord.getEntity().getId(), SQueriableLog.STATUS_FAIL, logBuilder, "addCategory"); throw new SCategoryCreationException(e); } }
@Override public void createGroup(final SGroup group, String iconFileName, byte[] iconContent) throws SGroupCreationException { final String methodName = "createGroup"; final long objectId = group.getId(); final SGroupLogBuilder logBuilder = getGroupLog(ActionType.CREATED, "Adding a new group with name " + group.getName()); try { if (iconFileName != null && iconContent != null) { SIcon icon = createIcon(iconFileName, iconContent); ((SGroupImpl) group).setIconId(icon.getId()); } final InsertRecord insertRecord = new InsertRecord(group); recorder.recordInsert(insertRecord, GROUP); final int status = SQueriableLog.STATUS_OK; log(insertRecord.getEntity().getId(), status, logBuilder, methodName); } catch (final SRecorderException re) { final int status = SQueriableLog.STATUS_FAIL; log(objectId, status, logBuilder, methodName); throw new SGroupCreationException(re); } }
@Override public void createGroup(final SGroup group, String iconFileName, byte[] iconContent) throws SGroupCreationException { final String methodName = "createGroup"; final long objectId = group.getId(); final SGroupLogBuilder logBuilder = getGroupLog(ActionType.CREATED, "Adding a new group with name " + group.getName()); try { if (iconFileName != null && iconContent != null) { SIcon icon = createIcon(iconFileName, iconContent); ((SGroupImpl) group).setIconId(icon.getId()); } final InsertRecord insertRecord = new InsertRecord(group); recorder.recordInsert(insertRecord, GROUP); final int status = SQueriableLog.STATUS_OK; log(insertRecord.getEntity().getId(), status, logBuilder, methodName); } catch (final SRecorderException re) { final int status = SQueriableLog.STATUS_FAIL; log(objectId, status, logBuilder, methodName); throw new SGroupCreationException(re); } }