use of edu.uci.ics.textdb.api.field.IDField in project textdb by TextDB.
the class RelationManagerTest method test9.
/*
* Test inserting a tuple to a table, then update it, then delete it
*/
@Test
public void test9() throws Exception {
String tableName = "relation_manager_test_table";
String tableDirectory = "./index/test_table";
Schema tableSchema = new Schema(new Attribute("content", AttributeType.STRING));
RelationManager relationManager = RelationManager.getRelationManager();
relationManager.deleteTable(tableName);
relationManager.createTable(tableName, tableDirectory, tableSchema, LuceneAnalyzerConstants.standardAnalyzerString());
DataWriter dataWriter = relationManager.getTableDataWriter(tableName);
dataWriter.open();
Tuple insertedTuple = new Tuple(tableSchema, new StringField("test"));
IDField idField = dataWriter.insertTuple(insertedTuple);
dataWriter.close();
Tuple returnedTuple = relationManager.getTupleByID(tableName, idField);
Assert.assertEquals(insertedTuple.getField("content").getValue().toString(), returnedTuple.getField("content").getValue().toString());
dataWriter.open();
Tuple updatedTuple = new Tuple(tableSchema, new StringField("testUpdate"));
dataWriter.updateTuple(updatedTuple, idField);
dataWriter.close();
Tuple returnedUpdatedTuple = relationManager.getTupleByID(tableName, idField);
Assert.assertEquals(updatedTuple.getField("content").getValue().toString(), returnedUpdatedTuple.getField("content").getValue().toString());
dataWriter.open();
dataWriter.deleteTupleByID(idField);
dataWriter.close();
Tuple deletedTuple = relationManager.getTupleByID(tableName, idField);
Assert.assertNull(deletedTuple);
relationManager.deleteTable(tableName);
}
Aggregations