| /* |
| * 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. |
| */ |
| package org.apache.cassandra.io.sstable; |
| |
| import java.io.File; |
| |
| import com.google.common.base.Throwables; |
| |
| import org.apache.cassandra.config.CFMetaData; |
| import org.apache.cassandra.db.*; |
| import org.apache.cassandra.db.marshal.AbstractType; |
| import org.apache.cassandra.dht.IPartitioner; |
| import org.apache.cassandra.io.FSError; |
| import org.apache.cassandra.io.sstable.format.SSTableReader; |
| import org.apache.cassandra.io.sstable.format.SSTableWriter; |
| |
| /** |
| * A SSTable writer that assumes rows are in (partitioner) sorted order. |
| * Contrarily to SSTableSimpleUnsortedWriter, this writer does not buffer |
| * anything into memory, however it assumes that row are added in sorted order |
| * (an exception will be thrown otherwise), which for the RandomPartitioner |
| * means that rows should be added by increasing md5 of the row key. This is |
| * rarely possible and SSTableSimpleUnsortedWriter should most of the time be |
| * prefered. |
| * |
| * @see AbstractSSTableSimpleWriter |
| * |
| * @deprecated this class is depracted in favor of {@link CQLSSTableWriter}. |
| */ |
| @Deprecated |
| public class SSTableSimpleWriter extends AbstractSSTableSimpleWriter |
| { |
| private final SSTableWriter writer; |
| |
| /** |
| * Create a new writer. |
| * @param directory the directory where to write the sstable |
| * @param partitioner the partitioner |
| * @param keyspace the keyspace name |
| * @param columnFamily the column family name |
| * @param comparator the column family comparator |
| * @param subComparator the column family subComparator or null if not a Super column family. |
| */ |
| public SSTableSimpleWriter(File directory, |
| IPartitioner partitioner, |
| String keyspace, |
| String columnFamily, |
| AbstractType<?> comparator, |
| AbstractType<?> subComparator) |
| { |
| this(directory, CFMetaData.denseCFMetaData(keyspace, columnFamily, comparator, subComparator), partitioner); |
| } |
| |
| public SSTableSimpleWriter(File directory, CFMetaData metadata, IPartitioner partitioner) |
| { |
| super(directory, metadata, partitioner); |
| writer = getWriter(); |
| } |
| |
| SSTableReader closeAndOpenReader() |
| { |
| if (currentKey != null) |
| writeRow(currentKey, columnFamily); |
| return writer.finish(true); |
| } |
| |
| public void close() |
| { |
| try |
| { |
| if (currentKey != null) |
| writeRow(currentKey, columnFamily); |
| writer.finish(false); |
| } |
| catch (Throwable t) |
| { |
| throw Throwables.propagate(writer.abort(t)); |
| } |
| } |
| |
| protected void writeRow(DecoratedKey key, ColumnFamily columnFamily) |
| { |
| writer.append(key, columnFamily); |
| } |
| |
| protected ColumnFamily getColumnFamily() |
| { |
| return ArrayBackedSortedColumns.factory.create(metadata); |
| } |
| |
| public Descriptor getCurrentDescriptor() |
| { |
| return writer.descriptor; |
| } |
| } |