Example usage for org.apache.cassandra.db.marshal TimestampType instance

List of usage examples for org.apache.cassandra.db.marshal TimestampType instance

Introduction

In this page you can find the example usage for org.apache.cassandra.db.marshal TimestampType instance.

Prototype

TimestampType instance

To view the source code for org.apache.cassandra.db.marshal TimestampType instance.

Click Source Link

Usage

From source file:com.stratio.cassandra.index.schema.ColumnMapperDate.java

License:Apache License

/**
 * Builds a new {@link ColumnMapperDate} using the specified pattern.
 *
 * @param pattern The {@link SimpleDateFormat} pattern to be used.
 *///ww w  . j a  v  a2  s . c  o  m
@JsonCreator
public ColumnMapperDate(@JsonProperty("pattern") String pattern) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, DecimalType.instance,
            TimestampType.instance }, new AbstractType[] { LongType.instance, TimestampType.instance });
    this.pattern = pattern == null ? DEFAULT_PATTERN : pattern;
    concurrentDateFormat = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat(ColumnMapperDate.this.pattern);
        }
    };
}

From source file:com.stratio.cassandra.index.schema.ColumnMapperString.java

License:Apache License

/**
 * Builds a new {@link ColumnMapperString}.
 *//*  ww  w. j a  v  a 2  s.  c o  m*/
@JsonCreator
public ColumnMapperString() {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, BooleanType.instance,
            UUIDType.instance, TimeUUIDType.instance, TimestampType.instance, BytesType.instance,
            InetAddressType.instance }, new AbstractType[] { UTF8Type.instance });
}

From source file:com.stratio.cassandra.index.schema.ColumnMapperText.java

License:Apache License

/**
 * Builds a new {@link ColumnMapperText} using the specified Lucene {@link Analyzer}.
 * @param analyzerClassName The Lucene {@link Analyzer} to be used.
 *//*from   w w w. j  ava2s .  co  m*/
@JsonCreator
public ColumnMapperText(@JsonProperty("analyzer") String analyzerClassName) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, BooleanType.instance,
            UUIDType.instance, TimeUUIDType.instance, TimestampType.instance, BytesType.instance,
            InetAddressType.instance }, new AbstractType[] {});
    if (analyzerClassName != null) {
        this.analyzer = AnalyzerFactory.getAnalyzer(analyzerClassName);
    } else {
        this.analyzer = Schema.DEFAULT_ANALYZER;
    }
}

From source file:com.stratio.cassandra.lucene.schema.mapping.BitemporalMapper.java

License:Apache License

/**
 * Builds a new {@link BitemporalMapper}.
 *
 * @param name    the name of the mapper.
 * @param vtFrom  The column name containing the Start Valid Time.
 * @param vtTo    The column name containing the End Valid Time.
 * @param ttFrom  The column name containing the Start Transaction Time.
 * @param ttTo    The column name containing the End Transaction Time.
 * @param pattern The {@link SimpleDateFormat} pattern to be used.
 *//*from   w  ww .j  a v a2s  . co  m*/
public BitemporalMapper(String name, String vtFrom, String vtTo, String ttFrom, String ttTo, String pattern,
        Object nowValue) {

    super(name, true, false, AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, DecimalType.instance,
            TimestampType.instance);

    if (StringUtils.isBlank(vtFrom)) {
        throw new IllegalArgumentException("vtFrom column name is required");
    }

    if (StringUtils.isBlank(vtTo)) {
        throw new IllegalArgumentException("vtTo column name is required");
    }

    if (StringUtils.isBlank(ttFrom)) {
        throw new IllegalArgumentException("ttFrom column name is required");
    }

    if (StringUtils.isBlank(ttTo)) {
        throw new IllegalArgumentException("ttTo column name is required");
    }

    this.pattern = (pattern == null) ? DEFAULT_PATTERN : pattern;
    this.vtFrom = vtFrom;
    this.vtTo = vtTo;
    this.ttFrom = ttFrom;
    this.ttTo = ttTo;

    // Validate pattern
    new SimpleDateFormat(this.pattern);

    // ttTo=now vtTo=now 2 DateRangePrefixTree

    this.tree_t1_V = DateRangePrefixTree.INSTANCE;
    this.strategy_t1_V = new NumberRangePrefixTreeStrategy(tree_t1_V, name + ".t1_v");
    this.tree_t1_T = DateRangePrefixTree.INSTANCE;
    this.strategy_t1_T = new NumberRangePrefixTreeStrategy(tree_t1_T, name + ".t1_t");

    this.tree_t2_V = DateRangePrefixTree.INSTANCE;
    this.strategy_t2_V = new NumberRangePrefixTreeStrategy(tree_t2_V, name + ".t2_v");
    this.tree_t2_T = DateRangePrefixTree.INSTANCE;
    this.strategy_t2_T = new NumberRangePrefixTreeStrategy(tree_t2_T, name + ".t2_t");

    this.tree_t3_V = DateRangePrefixTree.INSTANCE;
    this.strategy_t3_V = new NumberRangePrefixTreeStrategy(tree_t3_V, name + ".t3_v");
    this.tree_t3_T = DateRangePrefixTree.INSTANCE;
    this.strategy_t3_T = new NumberRangePrefixTreeStrategy(tree_t3_T, name + ".t3_t");

    this.tree_t4_V = DateRangePrefixTree.INSTANCE;
    this.strategy_t4_V = new NumberRangePrefixTreeStrategy(tree_t4_V, name + ".t4_v");
    this.tree_t4_T = DateRangePrefixTree.INSTANCE;
    this.strategy_t4_T = new NumberRangePrefixTreeStrategy(tree_t4_T, name + ".t4_t");

    concurrentDateFormat = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat(BitemporalMapper.this.pattern);
        }
    };

    this.nowBitemporalDateTime = nowValue == null ? new BitemporalDateTime(Long.MAX_VALUE)
            : this.parseBiTemporalDate(nowValue);

}

From source file:com.stratio.cassandra.lucene.schema.mapping.BitemporalMapperTest.java

License:Apache License

@Test()
public void testReadVtFromFieldFromTimeStampColumn() {
    BitemporalMapper mapper = new BitemporalMapper("field", "vtFrom", "vtTo", "ttFrom", "ttTo",
            "yyyy/MM/dd HH:mm:ss", "2025/12/23 00:00:00");
    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    try {//from   w w  w  . j  a v  a  2  s . co  m
        date = format.parse("2015/03/24 11:15:14");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Columns columns = new Columns();
    columns.add(Column.fromComposed("vtFrom", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("vtTo", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("ttFrom", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("ttTo", date, TimestampType.instance, false));
    assertEquals(new BitemporalMapper.BitemporalDateTime(date), mapper.readBitemporalDate(columns, "vtFrom"));
}

From source file:com.stratio.cassandra.lucene.schema.mapping.BitemporalMapperTest.java

License:Apache License

@Test()
public void testReadVtToFieldsFromTimeStampColumn() {
    BitemporalMapper mapper = new BitemporalMapper("field", "vtFrom", "vtTo", "ttFrom", "ttTo",
            "yyyy/MM/dd HH:mm:ss", "2025/12/23 00:00:00");
    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    try {/*from  w w w.  j a  v  a2  s . c om*/
        date = format.parse("2015/03/24 11:15:14");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Columns columns = new Columns();
    columns.add(Column.fromComposed("vtFrom", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("vtTo", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("ttFrom", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("ttTo", date, TimestampType.instance, false));
    assertEquals(new BitemporalMapper.BitemporalDateTime(date), mapper.readBitemporalDate(columns, "vtTo"));
}

From source file:com.stratio.cassandra.lucene.schema.mapping.BitemporalMapperTest.java

License:Apache License

@Test()
public void testReadTtFromFieldFromTimeStampColumn() {
    BitemporalMapper mapper = new BitemporalMapper("field", "vtFrom", "vtTo", "ttFrom", "ttTo",
            "yyyy/MM/dd HH:mm:ss", "2025/12/23 00:00:00");
    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    try {/*from  ww w  .  j  ava2  s . c om*/
        date = format.parse("2015/03/24 11:15:14");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Columns columns = new Columns();
    columns.add(Column.fromComposed("vtFrom", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("vtTo", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("ttFrom", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("ttTo", date, TimestampType.instance, false));
    assertEquals(new BitemporalMapper.BitemporalDateTime(date), mapper.readBitemporalDate(columns, "ttFrom"));
}

From source file:com.stratio.cassandra.lucene.schema.mapping.BitemporalMapperTest.java

License:Apache License

@Test()
public void testReadTtToFieldFromTimeStampColumn() {
    BitemporalMapper mapper = new BitemporalMapper("field", "vtFrom", "vtTo", "ttFrom", "ttTo",
            "yyyy/MM/dd HH:mm:ss", "2025/12/23 00:00:00");
    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    try {/*from  w  ww  . java2s.c  o  m*/
        date = format.parse("2015/03/24 11:15:14");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Columns columns = new Columns();
    columns.add(Column.fromComposed("vtFrom", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("vtTo", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("ttFrom", date, TimestampType.instance, false));
    columns.add(Column.fromComposed("ttTo", date, TimestampType.instance, false));
    assertEquals(new BitemporalMapper.BitemporalDateTime(date), mapper.readBitemporalDate(columns, "ttTo"));
}

From source file:com.stratio.cassandra.lucene.schema.mapping.DateMapper.java

License:Apache License

/**
 * Builds a new {@link DateMapper} using the specified pattern.
 *
 * @param name    The name of the mapper.
 * @param indexed If the field supports searching.
 * @param sorted  If the field supports sorting.
 * @param pattern The {@link SimpleDateFormat} pattern to be used.
 *//*w ww . j a  va2 s .  c  om*/
public DateMapper(String name, Boolean indexed, Boolean sorted, String pattern) {
    super(name, indexed, sorted, AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, DecimalType.instance,
            TimestampType.instance);
    this.pattern = pattern == null ? DEFAULT_PATTERN : pattern;

    // Validate pattern
    new SimpleDateFormat(this.pattern);

    concurrentDateFormat = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat(DateMapper.this.pattern);
        }
    };
}

From source file:com.stratio.cassandra.lucene.schema.mapping.DateRangeMapper.java

License:Apache License

/**
 * Builds a new {@link DateRangeMapper}.
 *
 * @param name    The name of the mapper.
 * @param start   The column containing the start {@link Date}.
 * @param stop    The column containing the stop {@link Date}.
 * @param pattern The {@link SimpleDateFormat} pattern to be used.
 *///w ww  .j  a v a  2 s .  c o  m
public DateRangeMapper(String name, String start, String stop, String pattern) {
    super(name, true, false, AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, DecimalType.instance,
            TimestampType.instance);

    if (StringUtils.isBlank(start)) {
        throw new IllegalArgumentException("start column name is required");
    }

    if (StringUtils.isBlank(stop)) {
        throw new IllegalArgumentException("stop column name is required");
    }

    this.start = start;
    this.stop = stop;
    this.tree = DateRangePrefixTree.INSTANCE;
    this.strategy = new NumberRangePrefixTreeStrategy(tree, name);
    this.pattern = pattern == null ? DEFAULT_PATTERN : pattern;

    concurrentDateFormat = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat(DateRangeMapper.this.pattern);
        }
    };
}