/*
 * 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$
 *  
 */
/*
 * EXTENSION
 * ISSUE: DVCORE-2521
 * FIXED BY: Roman Pedchenko
 * DATE: 2014-12-05
 * ADOPTED FROM: TEIID-2153, 2171, 2359, 2149, 2358, 2410, 2271, 2467, 2429, 2363, 2160, 2461, 2797, 2326, 1557
 * END EXTENSION
 */
// https://issues.jboss.org/browse/TEIID-2245
// https://issues.jboss.org/browse/TEIID-3295
// https://issues.jboss.org/browse/TEIID-3325
// https://issues.jboss.org/browse/TEIID-2885
// https://issues.jboss.org/browse/TEIID-3530
// https://issues.redhat.com/browse/TEIID-3156
// https://issues.redhat.com/browse/TEIID-4129
// https://issues.redhat.com/browse/TEIID-4330
package org.teiid.query.util;

import java.util.Properties;

import org.teiid.translator.ExecutionFactory.NullOrder;

/**
 * A holder for options
 */
public class Options {

	public static final String UNNEST_DEFAULT = "org.teiid.subqueryUnnestDefault"; //$NON-NLS-1$
	public static final String PUSHDOWN_DEFAULT_NULL_ORDER = "org.teiid.pushdownDefaultNullOrder"; //$NON-NLS-1$
	public static final String JOIN_PREFETCH_BATCHES = "org.teiid.joinPrefetchBatches"; //$NON-NLS-1$
	public static final String REQUIRE_COLLATION = "org.teiid.requireTeiidCollation"; //$NON-NLS-1$
	public static final String DEFAULT_NULL_ORDER = "org.teiid.defaultNullOrder"; //$NON-NLS-1$
	public static final String ASSUME_MATCHING_COLLATION = "org.teiid.assumeMatchingCollation"; //$NON-NLS-1$
	public static final String ENFORCE_SINGLE_MAX_BUFFER_SIZE_ESTIMATE = "org.teiid.enforceSingleMaxBufferSizeEstimate"; //$NON-NLS-1$
	public static final String AGGRESSIVE_JOIN_GROUPING = "org.teiid.aggressiveJoinGrouping"; //$NON-NLS-1$
	public static final String MAX_SESSION_BUFFER_SIZE_ESTIMATE = "org.teiid.maxSessionBufferSizeEstimate"; //$NON-NLS-1$

	private Properties properties;
	private boolean subqueryUnnestDefault = false;
	private boolean pushdownDefaultNullOrder;
	private int joinPrefetchBatches = 10;
	private boolean requireTeiidCollation;
	private NullOrder defaultNullOrder = NullOrder.LOW;
	private boolean assumeMatchingCollation = true;
	private boolean enforceSingleMaxBufferSizeEstimate = false;
	private boolean aggressiveJoinGrouping = true;
	private long maxSessionBufferSizeEstimate = Long.MAX_VALUE;

	public Properties getProperties() {
		return properties;
	}
	
	public void setProperties(Properties properties) {
		this.properties = properties;
	}
	
	public boolean isSubqueryUnnestDefault() {
		return subqueryUnnestDefault;
	}
	
	public void setSubqueryUnnestDefault(boolean subqueryUnnestDefault) {
		this.subqueryUnnestDefault = subqueryUnnestDefault;
	}
	
	public Options subqueryUnnestDefault(boolean s) {
		this.subqueryUnnestDefault = s;
		return this;
	}

	public boolean isPushdownDefaultNullOrder() {
		return pushdownDefaultNullOrder;
	}

	public void setPushdownDefaultNullOrder(boolean virtualizeDefaultNullOrdering) {
		this.pushdownDefaultNullOrder = virtualizeDefaultNullOrdering;
	}

	public Options pushdownDefaultNullOrder(boolean p) {
		this.pushdownDefaultNullOrder = p;
		return this;
	}
	
	public void setJoinPrefetchBatches(int joinPrefetchBatches) {
		this.joinPrefetchBatches = joinPrefetchBatches;
	}
	
	public int getJoinPrefetchBatches() {
		return joinPrefetchBatches;
	}
	
	public Options joinPrefetchBatches(int i) {
		this.joinPrefetchBatches = i;
		return this;
	}

	public boolean isRequireTeiidCollation() {
		return requireTeiidCollation;
	}

	public void setRequireTeiidCollation(boolean requireTeiidCollation) {
		this.requireTeiidCollation = requireTeiidCollation;
	}

	public Options requireTeiidCollation(boolean b) {
		this.requireTeiidCollation = b;
		return this;
	}

	public NullOrder getDefaultNullOrder() {
		return defaultNullOrder;
	}

	public void setDefaultNullOrder(NullOrder defaultNullOrder) {
		this.defaultNullOrder = defaultNullOrder;
	}

	public Options defaultNullOrder(NullOrder b) {
		this.defaultNullOrder = b;
		return this;
	}

	public boolean isAssumeMatchingCollation() {
		return this.assumeMatchingCollation;
	}

	public void setAssumeMatchingCollation(boolean assumeMatchingCollation) {
		this.assumeMatchingCollation = assumeMatchingCollation;
	}

	public Options assumeMatchingCollation(boolean b) {
		this.assumeMatchingCollation = b;
		return this;
	}

	public boolean isEnforceSingleMaxBufferSizeEstimate() {
		return enforceSingleMaxBufferSizeEstimate;
	}

	public void setEnforceSingleMaxBufferSizeEstimate(
			boolean enforceSingleMaxBufferSizeEstimate) {
		this.enforceSingleMaxBufferSizeEstimate = enforceSingleMaxBufferSizeEstimate;
	}

	public Options enforceSingleMaxBufferSizeEstimate(
			boolean b) {
		this.enforceSingleMaxBufferSizeEstimate = b;
		return this;
	}

	public boolean isAggressiveJoinGrouping() {
		return this.aggressiveJoinGrouping;
	}

	public void setAggressiveJoinGrouping(boolean aggressiveJoinGrouping) {
		this.aggressiveJoinGrouping = aggressiveJoinGrouping;
	}

	public Options aggressiveJoinGrouping(boolean b) {
		this.aggressiveJoinGrouping = b;
		return this;
	}

	public Options maxSessionBufferSizeEstimate(
			long l) {
		this.maxSessionBufferSizeEstimate = l;
		return this;
	}

	public void setMaxSessionBufferSizeEstimate(
			long maxSessionBufferSizeEstimate) {
		this.maxSessionBufferSizeEstimate = maxSessionBufferSizeEstimate;
	}

	public long getMaxSessionBufferSizeEstimate() {
		return maxSessionBufferSizeEstimate;
	}
}
