001/* 
002 * JKNIV, whinstone one contract to access your database.
003 * 
004 * Copyright (C) 2017, the original author or authors.
005 *
006 * This library is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 2.1 of the License.
010 * 
011 * This library is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 * 
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with this library; if not, write to the Free Software Foundation, Inc., 
018 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
019 */
020package net.sf.jkniv.whinstone.types;
021
022/***
023 * Data types supported by cassandra.
024 * 
025 * @author Alisson Gomes
026 * @since 0.6.0
027 */
028public enum CassandraType implements ColumnType
029{
030    CUSTOM, // (0), // id number from cassandra DataType is not public, must be resolved by ordinal or name
031    ASCII, // (1), 
032    BIGINT, // (2), 
033    BLOB, // (3), 
034    BOOLEAN, // (4), 
035    COUNTER, // (5), 
036    DECIMAL, // (6), 
037    DOUBLE, // (7), 
038    FLOAT, // (8), 
039    INT, // (9), 
040    TEXT, // (10), 
041    TIMESTAMP, // (11), 
042    UUID, // (12), 
043    VARCHAR, // (13), 
044    VARINT, // (14), 
045    TIMEUUID, // (15), 
046    INET, // (16), 
047    DATE, // (17), 
048    TIME, // (18), 
049    SMALLINT, // (19), 
050    TINYINT, // (20), 
051    DURATION, // (21), 
052    LIST, // (32), 
053    MAP, // (33), 
054    SET, // (34), 
055    UDT, // (48), 
056    TUPLE, // (49)
057    ;
058    
059    public int value()
060    {
061        return this.ordinal();
062    }
063    
064    @Override
065    public boolean isBinary()
066    {
067        return isBlob();        
068    }
069    
070    @Override
071    public boolean isBlob()
072    {
073        return (this == BLOB);
074    }
075    
076    @Override
077    public boolean isClob()
078    {
079        return false;
080    }
081    
082    @Override
083    public boolean isDate()
084    {
085        return (this == DATE);
086    }
087    
088    @Override
089    public boolean isTimestamp()
090    {
091        return (this == TIMESTAMP);
092    }
093    
094    @Override
095    public boolean isTime()
096    {
097        return (this == TIME);
098    }
099
100    public static ColumnType valueOf(int typeValue)
101    {
102        ColumnType answer = null;
103        for (ColumnType jdbcType : CassandraType.values())
104        {
105            if (jdbcType.value() == typeValue)
106            {
107                answer = jdbcType;
108                break;
109            }
110        }
111        return answer;
112    }
113    
114}