/*
 * 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$
 *  
 */
// https://issues.jboss.org/browse/TEIID-2159
// https://issues.redhat.com/browse/TEIID-5499
package org.teiid.core.types;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.OptionalDataException;
import java.sql.Clob;
import org.teiid.core.util.ExternalizeUtil;

/**
 * This is wrapper on top of a "clob" object, which implements the "java.sql.Clob"
 * interface. This class also implements the Streamable interface
 */
public final class ClobType extends BaseClobType {

	public enum Type {
 	    TEXT, JSON
 	}

	private static final long serialVersionUID = 2753412502127824104L;
    
	private Type type = Type.TEXT;
    
    public ClobType() {
    }
    
    public ClobType(Clob clob) {
    	super(clob);
    }

	public Type getType() {
		return type;
}

	public void setType(Type type) {
		this.type = type;
	}
    
	@Override
 	public void readExternal(ObjectInput in) throws IOException,
 	                ClassNotFoundException {
		super.readExternal(in);
		try {
			this.type = ExternalizeUtil.readEnum(in, Type.class, Type.TEXT);
		} catch (OptionalDataException e) {
			this.type = Type.TEXT;
		} catch(IOException e) {
			this.type = Type.TEXT;
		}
	}

	@Override
 	public void writeExternal(ObjectOutput out) throws IOException {
		super.writeExternal(out);
		ExternalizeUtil.writeEnum(out, this.type);
	}

}
