org.beigesoft.replicator.service.SrvEntitySyncHasVersion Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of beige-replicator Show documentation
Show all versions of beige-replicator Show documentation
It replicate/persist any entity according XML settings and user's requirements with a file or network (HTTP).
Right now it has implemented XML format of stored/transferred data.
The newest version!
package org.beigesoft.replicator.service;
/*
* Beigesoft ™
*
* Licensed under the Apache License, Version 2.0
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
import java.util.Map;
import org.beigesoft.model.IHasVersion;
import org.beigesoft.orm.service.ISrvOrm;
/**
* Service to synchronize IHasVersion.
* It's untransactional service. Transaction must be started.
*
* @param platform dependent record set type
* @author Yury Demidenko
*/
public class SrvEntitySyncHasVersion implements ISrvEntitySync {
/**
* ORM service.
**/
private ISrvOrm srvOrm;
/**
*
* Synchronize IHasVersion.
*
* @param pEntity object
* @param pAddParam additional params
* @return isNew if entity exist in database (need update)
* @throws Exception - an exception
**/
@Override
public final boolean sync(final Object pEntity,
final Map pAddParam) throws Exception {
IHasVersion entityPb = (IHasVersion) pEntity;
IHasVersion entityPbDb = getSrvOrm().retrieveEntity(entityPb);
boolean isNew = true;
if (entityPbDb != null) {
entityPb.setItsVersion(entityPbDb.getItsVersion());
isNew = false;
}
return isNew;
}
//Simple getters and setters:
/**
* Getter for srvOrm.
* @return ISrvOrm
**/
public final ISrvOrm getSrvOrm() {
return this.srvOrm;
}
/**
* Setter for srvOrm.
* @param pSrvOrm reference
**/
public final void setSrvOrm(final ISrvOrm pSrvOrm) {
this.srvOrm = pSrvOrm;
}
}