/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */
// Generated by http://code.google.com/p/protostuff/ ... DO NOT EDIT!
// Generated from protobuf

package org.apache.drill.exec.proto.beans;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import com.dyuproject.protostuff.GraphIOUtil;
import com.dyuproject.protostuff.Input;
import com.dyuproject.protostuff.Message;
import com.dyuproject.protostuff.Output;
import com.dyuproject.protostuff.Schema;
import com.dyuproject.protostuff.UninitializedMessageException;

public final class GetQueryPlanFragments implements Externalizable, Message<GetQueryPlanFragments>, Schema<GetQueryPlanFragments>
{

    public static Schema<GetQueryPlanFragments> getSchema()
    {
        return DEFAULT_INSTANCE;
    }

    public static GetQueryPlanFragments getDefaultInstance()
    {
        return DEFAULT_INSTANCE;
    }

    static final GetQueryPlanFragments DEFAULT_INSTANCE = new GetQueryPlanFragments();

    static final Boolean DEFAULT_SPLIT_PLAN = new Boolean(false);
    
    private String query;
    private QueryType type;
    private Boolean splitPlan = DEFAULT_SPLIT_PLAN;

    public GetQueryPlanFragments()
    {
        
    }

    public GetQueryPlanFragments(
        String query
    )
    {
        this.query = query;
    }

    // getters and setters

    // query

    public String getQuery()
    {
        return query;
    }

    public GetQueryPlanFragments setQuery(String query)
    {
        this.query = query;
        return this;
    }

    // type

    public QueryType getType()
    {
        return type == null ? QueryType.SQL : type;
    }

    public GetQueryPlanFragments setType(QueryType type)
    {
        this.type = type;
        return this;
    }

    // splitPlan

    public Boolean getSplitPlan()
    {
        return splitPlan;
    }

    public GetQueryPlanFragments setSplitPlan(Boolean splitPlan)
    {
        this.splitPlan = splitPlan;
        return this;
    }

    // java serialization

    public void readExternal(ObjectInput in) throws IOException
    {
        GraphIOUtil.mergeDelimitedFrom(in, this, this);
    }

    public void writeExternal(ObjectOutput out) throws IOException
    {
        GraphIOUtil.writeDelimitedTo(out, this, this);
    }

    // message method

    public Schema<GetQueryPlanFragments> cachedSchema()
    {
        return DEFAULT_INSTANCE;
    }

    // schema methods

    public GetQueryPlanFragments newMessage()
    {
        return new GetQueryPlanFragments();
    }

    public Class<GetQueryPlanFragments> typeClass()
    {
        return GetQueryPlanFragments.class;
    }

    public String messageName()
    {
        return GetQueryPlanFragments.class.getSimpleName();
    }

    public String messageFullName()
    {
        return GetQueryPlanFragments.class.getName();
    }

    public boolean isInitialized(GetQueryPlanFragments message)
    {
        return 
            message.query != null;
    }

    public void mergeFrom(Input input, GetQueryPlanFragments message) throws IOException
    {
        for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
        {
            switch(number)
            {
                case 0:
                    return;
                case 1:
                    message.query = input.readString();
                    break;
                case 2:
                    message.type = QueryType.valueOf(input.readEnum());
                    break;
                case 3:
                    message.splitPlan = input.readBool();
                    break;
                default:
                    input.handleUnknownField(number, this);
            }   
        }
    }


    public void writeTo(Output output, GetQueryPlanFragments message) throws IOException
    {
        if(message.query == null)
            throw new UninitializedMessageException(message);
        output.writeString(1, message.query, false);

        if(message.type != null)
             output.writeEnum(2, message.type.number, false);

        if(message.splitPlan != null && message.splitPlan != DEFAULT_SPLIT_PLAN)
            output.writeBool(3, message.splitPlan, false);
    }

    public String getFieldName(int number)
    {
        switch(number)
        {
            case 1: return "query";
            case 2: return "type";
            case 3: return "splitPlan";
            default: return null;
        }
    }

    public int getFieldNumber(String name)
    {
        final Integer number = __fieldMap.get(name);
        return number == null ? 0 : number.intValue();
    }

    private static final java.util.HashMap<String,Integer> __fieldMap = new java.util.HashMap<String,Integer>();
    static
    {
        __fieldMap.put("query", 1);
        __fieldMap.put("type", 2);
        __fieldMap.put("splitPlan", 3);
    }
    
}
