// Obtain the service ServiceReference historyServiceRef = context.getServiceReference( HistoryService.class.getName()); HistoryService historyService = (HistoryService)context.getService(historyServiceRef); HistoryID id = HistoryID.createFromRawID( new String[] {"this", "is", "a simple", "id, yeah!!"}); // If there is no such history - create it. // Otherwise just get the existing one History history; if(!historyService.isHistoryExisting(id)) { HistoryRecordStructure recordStructure = new HistoryRecordStructure(new String[]{"name", "age", "gender"}); history = historyService.createHistory(id, recordStructure); } else { history = historyService.getHistory(id); } // Add some records HistoryWriter writer = this.history.getWriter(); writer.addRecord(new String[] {"Monica", "32", "female"}); writer.addRecord(new String[] {"John", "64", "male"}); writer.addRecord(new String[] {"Santa Claus", "1024", "declines to state"}); // Then search through all records and print the results HistoryReader reader = this.history.getReader(); QueryResultSet result = reader.findByKeyword("state"); while(result.hasNext()) { HistoryRecord record = result.nextRecord(); String[] vals = record.getPropertyValues(); System.out.println( "Found! Name: " + vals[0] + " Age:" + vals[1] + " Gender:" + vals[2]); }