📄 fullreplicator.java
字号:
/*
*
* Copyright (c) 2004 SourceTap - www.sourcetap.com
*
* The contents of this file are subject to the SourceTap Public License
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*/
package com.sourcetap.sfa.replication;
import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericDelegator;
import com.sourcetap.sfa.util.UserInfo;
/**
* This abstract class is used for full data replication. <P>
*
* Full replication is required to populate a newly registered replication node, or
* to re-populate an inactive replication node.<P>
*
* This class should be extended, and the populateRelatedEntityMapVector() method should be
* called in the descendant class tospecify what entities are to be
* replicated.
*
* To perform full replication, instantiate the descendant class, and call the replicateFull()
* method.
*
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*/
public abstract class FullReplicator extends EntityReplicator {
/**
* Debug switch
*/
public static final String module = FullReplicator.class.getName();
/**
* Constructor with no args.
*/
public FullReplicator() {
super();
}
/**
* Constructor with args.
*
* @param mainInstance Main entity instance for which related entities will be replicated
* @param localDelegator Delegator to attach to local data base
* @param masterDelegator Delegator to attach to master data base
* @param entityName Name of the entity to be replicated
* @param userInfo UserInfo object containing user information
*/
public FullReplicator(GenericDelegator localDelegator,
GenericDelegator masterDelegator, String entityName, UserInfo userInfo) {
super(localDelegator, masterDelegator, entityName, userInfo);
}
/**
* This method removes all instances of all entities named
* in the relatedEntityMapVector.
*
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @return Status. Possible values: STATUS_CONTINUE, STATUS_ERROR, STATUS_CANCELED
*/
protected int removeAll() {
return removeAllRelated(null);
}
/**
* This method replicates all instances of all entities in the related entity
* map vector. It should be used to start full replication after the removeAll method is called.
*
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @return Status. Possible values: STATUS_CONTINUE, STATUS_ERROR, STATUS_CANCELED
*/
protected int replicateAll() {
return replicateAllRelated(null);
}
/**
* This method removes and replicates all entities in the related entity map vector.
* It should be called from the appplication to do a full replication.
*
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @return Status. Possible values: STATUS_CONTINUE, STATUS_ERROR, STATUS_CANCELED
*/
public int replicateFull() {
if (getUserInfo() == null) {
Debug.logError("[replicateFull] User info is required.", module);
return STATUS_ERROR;
}
;
int status = removeAll();
if (status == STATUS_CONTINUE) {
// Data removal was successful.
Debug.logVerbose("[replicateFull] Data removal complete.", module);
// Replicate.
status = replicateAll();
if (status == STATUS_CONTINUE) {
// Replication was successful.
Debug.logVerbose("[replicateFull] Replication complete.", module);
// Set the node's status to Active.
status = markNodeReplicated(getReplNodeId(),
getUserInfo().getPartyId());
if (status == STATUS_CONTINUE) {
// Node status update was successful.
Debug.logVerbose("[replicateFull] Node status updated.", module);
} else {
// Node status update was unsuccessful. Log a warning.
Debug.logError("[replicateAll] Node status update failed.", module);
}
} else {
// Replication failed.
Debug.logError("[replicateAll] Replication failed.", module);
}
} else {
// Removal failed.
Debug.logError("[replicateAll] Data removal failed.", module);
}
return status;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -