/*
 * JBoss, Home of Professional Open Source.
 * See the COPYRIGHT.txt file distributed with this work for information
 * regarding copyright ownership.  Some portions may be licensed
 * to Red Hat, Inc. under one or more contributor license agreements.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 * Modified by
 * @author  Data Virtuality GmbH
 * @date    $Date$
 *  
 */

package org.teiid.events;

import org.teiid.Replicated;
import org.teiid.metadata.ColumnStats;
import org.teiid.metadata.Table;
import org.teiid.metadata.TableStats;

import java.util.List;

/**
 * Distributes events across the Teiid cluster
 */
public interface EventDistributor {
	
	/**
	 * Update the given materialized view row.
	 * The tuple is expected to be in table order, which has the primary key first.
	 * Deletes need to only send the key, not the entire row contents.
	 * 
	 * @param vdbName
	 * @param vdbVersion
	 * @param schema
	 * @param viewName
	 * @param tuple
	 * @param delete
	 */
	@Replicated(remoteOnly=true)
	void updateMatViewRow(String vdbName, int vdbVersion, String schema, String viewName, List<?> tuple, boolean delete);
	
	/**
	 * Notify that the table data has changed.
	 * @param vdbName
	 * @param vdbVersion
 	 * @param schema
	 * @param tableNames
	 */
	@Replicated(remoteOnly=true)
	void dataModification(String vdbName, int vdbVersion, String schema, String... tableNames);

	/**
	 * Set the column stats
	 * @param vdbName
	 * @param vdbVersion
	 * @param schemaName
	 * @param tableName
	 * @param columnName
	 * @param stats
	 */
	@Replicated(remoteOnly=true)
	void setColumnStats(String vdbName, int vdbVersion, String schemaName,
			String tableName, String columnName, ColumnStats stats);

	/**
	 * Set the table stats
	 * @param vdbName
	 * @param vdbVersion
	 * @param schemaName
	 * @param tableName
	 * @param stats
	 */
	@Replicated(remoteOnly=true)
	void setTableStats(String vdbName, int vdbVersion, String schemaName,
			String tableName, TableStats stats);
	
	/**
	 * Set the given property value
	 * @param vdbName
	 * @param vdbVersion
	 * @param uuid
	 * @param name
	 * @param value
	 */
	@Replicated(remoteOnly=true)
	void setProperty(String vdbName, int vdbVersion, String uuid, String name, String value);
	
	/**
	 * Set the instead of trigger definition.  Only one of either the triggerDefinition or enabled should be specified.
	 * @param vdbName
	 * @param vdbVersion
	 * @param schema
	 * @param viewName
	 * @param triggerEvent
	 * @param triggerDefinition
	 * @param enabled
	 */
	@Replicated(remoteOnly=true)
	void setInsteadOfTriggerDefinition(String vdbName, int vdbVersion, String schema, String viewName, Table.TriggerEvent triggerEvent, String triggerDefinition, Boolean enabled);

	/**
	 * Set the procedure definition
	 * @param vdbName
	 * @param vdbVersion
	 * @param schema
	 * @param procName
	 * @param definition
	 */
	@Replicated(remoteOnly=true)
	void setProcedureDefinition(String vdbName, int vdbVersion, String schema, String procName, String definition);

	/**
	 * Set the view definition
	 * @param vdbName
	 * @param vdbVersion
	 * @param schema
	 * @param viewName
	 * @param definition
	 */
	@Replicated(remoteOnly=true, asynch = false)
	void setViewDefinition(String vdbName, int vdbVersion, String schema, String viewName, String definition);

	@Replicated(remoteOnly=true, asynch = false)
	void alterViewProc(String vdbName, int vdbVersion, String command, boolean view);

	@Replicated(remoteOnly=true, asynch = false)
	void dropViewProc(String vdbName, int vdbVersion, String command, Integer id, String schema, String resourceName, boolean view);

	@Replicated(remoteOnly=true, asynch = false)
	void dropViewProc(String vdbName, int vdbVersion, String command, boolean view);

	@Replicated(remoteOnly=true, asynch = false)
	void createViewProc(String vdbName, int vdbVersion, String command, boolean view);
	
	@Replicated(remoteOnly = true, asynch = false)
	void importViewProc(String vdbName, int vdbVersion, String sql, boolean view);
	
	@Replicated(remoteOnly=true)
	void setFunctionDefinition(String vdbName, int vdbVersion, String schema, String functionName, String definition);

	@Replicated(remoteOnly=true, asynch = false)
	void alterFunction(String vdbName, int vdbVersion, String command);

	@Replicated(remoteOnly=true, asynch = false)
	void dropFunction(String vdbName, int vdbVersion, String command, Integer id, String schema, String resourceName);

	@Replicated(remoteOnly=true, asynch = false)
	void dropFunction(String vdbName, int vdbVersion, String command);

	@Replicated(remoteOnly=true, asynch = false)
	void createFunction(String vdbName, int vdbVersion, String command);

	@Replicated(remoteOnly = true, asynch = false)
	void importFunction(String vdbName, int vdbVersion, String sql);

	@Replicated(remoteOnly = true, asynch = false)
	void createConnection(String vdbName, int vdbVersion, String name, String template, String properties, String encryptedProperties);

	@Replicated(remoteOnly = true, asynch = false)
	void createDatasource(String vdbName, int vdbVersion, String name, String connectionName, String translator, String modelPropsString, String translatorPropsString,
	                      String encryptedModelPropsString, String encryptedTranslatorPropsString);

	@Replicated(remoteOnly = true, asynch = false)
	void removeConnection(String vdbName, int vdbVersion, String name, String jndiName, String dropScript, String template);

	@Replicated(remoteOnly = true, asynch = false)
	void removeDatasource(String vdbName, int vdbVersion, String name);

	@Replicated(remoteOnly = true, asynch = false)
	void createVirtualSchema(String vdbName, int vdbVersion, String name, boolean isDeletable, int id);

	@Replicated(remoteOnly = true, asynch = false)
	void dropVirtualSchema(String vdbName, int vdbVersion, int id, String name);

	@Replicated(remoteOnly = true, asynch = false)
	void renameVirtualSchema(String vdbName, int vdbVersion, int id, String name, String oldName);

	@Replicated(remoteOnly = true, asynch = false)
	void createTable(String vdbName, int vdbVersion, String command);

	@Replicated(remoteOnly = true, asynch = false)
	void dropTable(String vdbName, int vdbVersion, String command);

	@Replicated(remoteOnly = true, asynch = false)
	void selectInto(String vdbName, int vdbVersion, String command, String connectionId, long executionId, String combinedId, boolean rollbackMetadata);

	@Replicated(remoteOnly = true, asynch = false)
	void removeTable(String vdbName, int vdbVersion, String schemaName, String tableName);
	
	@Replicated(remoteOnly = true, asynch = false)
	void changeDWH(String vdbName, int vdbVersion, String nameInDv, String nameInSource, boolean restoreTableCounter);

	@Replicated(remoteOnly = true, asynch = false)
	void distributeMatTable(String vdbName, int vdbVersion, int recOptId, String matTableName, String matNameInInternalDB);

	@Replicated(remoteOnly = true)
	void distributeGitEvent(String observedType, Integer entityId, String operationType);

	@Replicated(remoteOnly = true, asynch = false)
	void createVdb(String name, Integer version);

	@Replicated(remoteOnly = true, asynch = false)
	void renameVdb(String name, Integer version, String oldName, Integer oldVersion);

	@Replicated(remoteOnly = true, asynch = false)
	void dropVdb(String name, Integer version);

	@Replicated(remoteOnly = true, asynch = false)
	void createQueueHandler(String name, Integer threadCount);

	@Replicated(remoteOnly = true, asynch = false)
	void editQueueHandler(String name, Integer threadCount);

	@Replicated(remoteOnly = true, asynch = false)
	void dropQueueHandler(String name);

	@Replicated(remoteOnly = true, asynch = false)
	void updateWorkContextMetadata();

	@Replicated(remoteOnly = true, asynch = false)
	void refreshModel(String vdbName, int vdbVersion, String name);

	@Replicated(remoteOnly = true, asynch = false)
	void setDefaultOptionValue(String option, String initialValue, String encryptedValue);

	@Replicated(remoteOnly = true, asynch = false)
	void deleteSchedulerJob(Integer jobId, String jobUuid);

	@Replicated(remoteOnly = true, asynch = false)
	void cancelQuery(String sessionId, Long reqIndex);

	@Replicated(remoteOnly = true, asynch = false)
	void callOnCompleteJobRun(Integer scheduleId, Integer id, String status, String failureReason);

    @Replicated(remoteOnly = true, asynch = false)
    void installLicense(String base64LicenseFile);
}
