All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jumpmind.symmetric.model.TriggerRouter Maven / Gradle / Ivy

Go to download

SymmetricDS is an open source database synchronization solution. It is platform-independent, web-enabled, and database-agnostic. SymmetricDS was first built to replicate changes between 'retail store' databases and ad centralized 'corporate' database.

The newest version!
/*
 * Licensed to JumpMind Inc under one or more contributor 
 * license agreements.  See the NOTICE file distributed
 * with this work for additional information regarding 
 * copyright ownership.  JumpMind Inc licenses this file
 * to you under the GNU Lesser General Public License (the
 * "License"); you may not use this file except in compliance
 * with the License. 
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see           
 * .
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License. 
 */


package org.jumpmind.symmetric.model;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jumpmind.symmetric.ddl.model.Column;
import org.jumpmind.symmetric.ddl.model.Table;

/**
 * Defines the trigger via which a table will be synchronized.
 *
 * 
 */
public class TriggerRouter {

    static final Log logger = LogFactory.getLog(TriggerRouter.class);

    private static final long serialVersionUID = 8947288471097851573L;

    /**
     * This is the order in which the definitions will be processed.
     */
    private int initialLoadOrder;
    
    private String initialLoadSelect;

    private Trigger trigger;

    private Router router;

    private Date createTime;

    private Date lastUpdateTime;

    private String lastUpdateBy;
    
    private boolean pingBackEnabled = false;

    public TriggerRouter() {
        trigger = new Trigger();
        router = new Router();
        createTime = new Date();
        lastUpdateTime = new Date();
    }

    public Date getCreateTime() {
        return createTime;
    }

    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    public String getLastUpdateBy() {
        return lastUpdateBy;
    }

    public void setCreateTime(Date createdOn) {
        this.createTime = createdOn;
    }

    public void setLastUpdateTime(Date lastModifiedOn) {
        this.lastUpdateTime = lastModifiedOn;
    }

    public void setLastUpdateBy(String updatedBy) {
        this.lastUpdateBy = updatedBy;
    }

    /**
     * When dealing with columns, always use this method to order the columns so that the primary keys are first.
     */
    public Column[] orderColumnsForTable(Table table) {
        return trigger.orderColumnsForTable(table);
    }

    public int getInitialLoadOrder() {
        return initialLoadOrder;
    }

    public void setInitialLoadOrder(int order) {
        this.initialLoadOrder = order;
    }

    public void setRouter(Router router) {
        this.router = router;
    }

    public Router getRouter() {
        return router;
    }

    public void setTrigger(Trigger trigger) {
        this.trigger = trigger;
    }

    public Trigger getTrigger() {
        return trigger;
    }
    
    public void setInitialLoadSelect(String initialLoadSelect) {
        this.initialLoadSelect = initialLoadSelect;
    }
    
    public String getInitialLoadSelect() {
        return initialLoadSelect;
    }

    public boolean isRouted(DataEventType event) {
        switch (event) {
        case INSERT:
            return router.isSyncOnInsert();
        case DELETE:
            return router.isSyncOnDelete();
        case UPDATE:
            return router.isSyncOnUpdate();
        default:
            return true;
        }
    }

    public String getTargetSchema(String defaultSchema) {
        if (router != null && !StringUtils.isBlank(router.getTargetSchemaName())) {
            return router.getTargetSchemaName();
        } else {
            return defaultSchema;
        }
    }

    public String getTargetCatalog(String defaultCatalog) {
        if (router != null && !StringUtils.isBlank(router.getTargetCatalogName())) {
            return router.getTargetCatalogName();
        } else {
            return defaultCatalog;
        }
    }

    public String getTargetTable() {
        if (router != null && !StringUtils.isBlank(router.getTargetTableName())) {
            return router.getTargetTableName();
        }
        if (trigger != null && !StringUtils.isBlank(trigger.getSourceTableName())) {
            return trigger.getSourceTableName();
        } else {
            return null;
        }
    }
    
    public String qualifiedSourceTableName() {
        return trigger.qualifiedSourceTableName();
    }
    
    public String qualifiedSourceTablePrefix() {
        return trigger.qualifiedSourceTablePrefix();
    }

    public String qualifiedTargetTableName() {
        String catalog = getTargetCatalog(null);
        String schema = getTargetSchema(null);
        String tableName = getTargetTable();
        if (!StringUtils.isBlank(schema)) {
            tableName = schema + "." + tableName;
        }
        if (!StringUtils.isBlank(catalog)) {
            tableName = catalog + "." + tableName;
        }
        return tableName;
    }
    
    public void setPingBackEnabled(boolean pingBackEnabled) {
        this.pingBackEnabled = pingBackEnabled;
    }
    
    public boolean isPingBackEnabled() {
        return pingBackEnabled;
    }
    
    public boolean isSame(TriggerRouter triggerRouter) {
        return (this.trigger == null && triggerRouter.trigger == null)
                || (this.trigger != null && triggerRouter.trigger != null && this.trigger
                        .isSame(triggerRouter.trigger))
                && (this.router == null && triggerRouter.router == null)
                || (this.router != null && triggerRouter.router != null && this.router
                        .equals(triggerRouter.router));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy