package com.alibaba.cobar.client.executor.support;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.cobar.client.datasources.CobarDataSourceDescriptor;
import com.alibaba.cobar.client.executor.IExecutorContext;

public class ExecutorContextSupporter implements IExecutorContext{

	private int operationType= 0;
	
	private CobarDataSourceDescriptor dataSourceDescriptor;
	
	private Map<String,Object> attributes;
	
	@Override
	public CobarDataSourceDescriptor getDataSourceDescriptor() {
		return dataSourceDescriptor;
	}

	@Override
	public int getOperationType() {
		return operationType;
	}
	
	public void setOperationType(int op){
		operationType= op;
	}
	
	public void setDataSourceDescriptor(CobarDataSourceDescriptor dataSourceDescriptor){
		this.dataSourceDescriptor= dataSourceDescriptor;
	}

	@Override
	public boolean isReadable() {
		return (operationType & OP_READ) == OP_READ;
	}

	@Override
	public boolean isWritable() {
		return (operationType & OP_WRITE) != 0;
	}
	
	public boolean isOnlyWritable(){
		return (operationType & OP_WRITE) == OP_WRITE;
	}

	@Override
	public boolean isTransactional() {
		return (operationType & OP_TRANSACTION) != 0;
	}

	@Override
	public Object getAttribute(String key) {
		if(attributes== null){
			return null;
		}
		return attributes.get(key);
	}
	
	@Override
	public void setAttribute(String key,Object value){
		if(attributes== null){
			attributes= new HashMap<>();
		}
		attributes.put(key, value);
	}

}

@@ -857,33 +857,32 @@
 le() %7B%0A%09%09return 
-(
 operationType & 
@@ -882,19 +882,8 @@
 Type
- & OP_READ)
  == 
@@ -929,32 +929,32 @@
  isWritable() %7B%0A
+
 %09%09return (operat
@@ -985,96 +985,8 @@
 ;%0A%09%7D
-%0A%09%0A%09public boolean isOnlyWritable()%7B%0A%09%09return (operationType & OP_WRITE) == OP_WRITE;%0A%09%7D
 %0A%0A%09@

modify readable status