@Override public TypeManager getTypeManager() { return repository.getTypeManager(); }
/** * Construct based on an existing record to prevent additional repository reads when the record is already * available. The existing IdRecord should be the last (when it was read) and should have been read with all * fields! */ public VTaggedRecord(IdRecord idRecord, RecordEventHelper eventHelper, LTable table, LRepository repository) throws RepositoryException, InterruptedException { this.table = table; this.typeManager = repository.getTypeManager(); this.record = idRecord; this.recordEventHelper = eventHelper; if (eventHelper != null) { this.recordEvent = eventHelper.getEvent(); } }
private Set<QName> getAllRepositoryFields() throws RepositoryException, InterruptedException { final Set<QName> result = new HashSet<QName>(); for (FieldType fieldType : repository.getTypeManager().getFieldTypes()) { result.add(fieldType.getName()); } return result; }
/** * This is for link extraction from nested records. */ private static void extractRecord(Record record, LinkCollector collector, FieldType ctxField, RecordId ctxRecord, LRepository repository) throws RepositoryException, InterruptedException { for (Map.Entry<QName, Object> field : record.getFields().entrySet()) { FieldType fieldType; try { fieldType = repository.getTypeManager().getFieldTypeByName(field.getKey()); } catch (FieldTypeNotFoundException e) { // Can not do anything with a field if we cannot load its type continue; } // The ctxField and ctxRecord need to stay the top-level ones! It does not matter how // deeply nested a link occurs, as far as the link index is concerned, it still occurs // with the field of the top level record. extract(field.getValue(), fieldType, collector, ctxField, ctxRecord, repository); } }
/** * Extracts the links from a record. The provided Record object should * be "fully loaded" (= contain all fields). */ public static void extract(IdRecord record, LinkCollector collector, LRepository repository) throws RepositoryException, InterruptedException { for (Map.Entry<SchemaId, Object> field : record.getFieldsById().entrySet()) { FieldType fieldType; try { fieldType = repository.getTypeManager().getFieldTypeById(field.getKey()); } catch (FieldTypeNotFoundException e) { // Can not do anything with a field if we cannot load its type continue; } extract(field.getValue(), fieldType, collector, fieldType, record.getId(), repository); } }
@Override public String format(Object record, ValueType valueType, FormatContext formatCtx) throws InterruptedException { StringBuilder builder = new StringBuilder(); TypeManager typeManager = formatCtx.repository.getTypeManager(); for (Map.Entry<QName, Object> field : ((Record)record).getFields().entrySet()) { ValueType fieldValueType; try { fieldValueType = typeManager.getFieldTypeByName(field.getKey()).getValueType(); } catch (RepositoryException e) { // error loading field type: skip this field continue; } String result = formatCtx.format(field.getValue(), fieldValueType, formatCtx); if (result != null) { if (builder.length() > 0) { builder.append(" "); } builder.append(result); } } return returnBuilderResult(builder); } }
private TemplatePart buildFieldTemplatePart(Element el, String template, String expr) throws IndexerConfException, InterruptedException, RepositoryException { QName field = ConfUtil.parseQName(expr, el); FieldType fieldType = ConfUtil.getFieldType(field, systemFields, repository.getTypeManager()); return new FieldTemplatePart(fieldType, field); }
public SolrDocumentBuilder(LRepository repository, IndexRecordFilter indexRecordFilter, SystemFields systemFields, ValueEvaluator valueEvaluator, String table, IdRecord record, String key, SchemaId vtag, long version) { this.repository = repository; this.indexRecordFilter = indexRecordFilter; this.systemFields = systemFields; this.typeManager = repository.getTypeManager(); this.valueEvaluator = valueEvaluator; this.table = table; this.recordId = record.getId(); this.key = key; this.vtag = vtag; this.version = version; this.nameTemplateResolver = new FieldNameTemplateResolver(); this.contexts = new Stack<RecordContext>(); this.push(record, new Dep(this.recordId, Collections.<String>emptySet())); this.dependencies = CacheBuilder.newBuilder().build(new CacheLoader<DependencyEntry, Set<SchemaId>>() { @Override public Set<SchemaId> load(DependencyEntry arg0) throws Exception { return Sets.newHashSet(); } }); }
@PostConstruct public void start() throws IOException, RepositoryException, InterruptedException { AvroLilyImpl avroLily = new AvroLilyImpl(repositoryManager, repositoryManager.getDefaultRepository().getTypeManager()); Responder responder = new LilySpecificResponder(AvroLily.class, avroLily); ThreadFactory threadFactory = new CustomThreadFactory("avro-exechandler", new ThreadGroup("AvroExecHandler")); if (maxServerThreads == -1) { executorService = Executors.newCachedThreadPool(threadFactory); executionHandler = new ExecutionHandler(executorService); } else { executorService = new ThreadPoolExecutor(maxServerThreads / 3, maxServerThreads, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), threadFactory, new WaitPolicy()); executionHandler = new ExecutionHandler(executorService); } //server = new HttpServer(responder, port); server = new NettyServer(responder, new InetSocketAddress(port), new NioServerSocketChannelFactory (Executors.newCachedThreadPool(), Executors.newCachedThreadPool()), executionHandler); server.start(); }
/** * Lookup name of field type, for use in debug logs. Beware, this might be slow. */ private String safeLoadTagName(SchemaId fieldTypeId) { if (fieldTypeId == null) { return "null"; } try { return repositoryManager.getDefaultRepository().getTypeManager().getFieldTypeById(fieldTypeId).getName().getName(); } catch (Throwable t) { return "failed to load name"; } }
@Override public String format(Object record, ValueType valueType, FormatContext formatCtx) throws InterruptedException { TypeManager typeManager = formatCtx.repository.getTypeManager(); StringWriter writer = new StringWriter(); try { JsonGenerator gen = JsonFormat.JSON_FACTORY.createJsonGenerator(writer); gen.writeStartObject(); for (Map.Entry<QName, Object> field : ((Record) record).getFields().entrySet()) { ValueType fieldValueType; try { fieldValueType = typeManager.getFieldTypeByName(field.getKey()).getValueType(); } catch (RepositoryException e) { continue; } String result = formatCtx.format(field.getValue(), fieldValueType, formatCtx); if (result != null) { gen.writeStringField(field.getKey().getName(), result); } } gen.writeEndObject(); gen.flush(); } catch (IOException e) { throw new InterruptedException(e.getMessage()); } return returnBuilderResult(new StringBuilder(writer.toString())); } }
/** * Returns null if the vtag does not exist or is not defined for the record. */ public static Record getRecord(RecordId recordId, String vtag, List<QName> fields, LTable table, LRepository repository) throws RepositoryException, InterruptedException { QName vtagName = new QName(NAMESPACE, vtag); Record record = table.read(recordId); long version; if (vtag.equals("last")) { // we loaded the last version if (fields != null) { filterFields(record, new HashSet<QName>(fields)); } return record; } else if (!record.hasField(vtagName)) { return null; } else { version = (Long) record.getField(vtagName); if (version == 0) { reduceToNonVersioned(record, fields != null ? new HashSet<QName>(fields) : null, repository.getTypeManager()); } else { record = table.read(recordId, version, fields); } return record; } }
public List<MutationCondition> convertFromAvro(List<AvroMutationCondition> avroConditions, LRepository repository) throws RepositoryException, InterruptedException { if (avroConditions == null) { return null; } List<MutationCondition> conditions = new ArrayList<MutationCondition>(avroConditions.size()); for (AvroMutationCondition avroCond : avroConditions) { QName name = convert(avroCond.getName()); // value is optional Object value = null; if (avroCond.getValue() != null) { ValueType valueType = repository.getTypeManager().getValueType(avroCond.getValueType()); value = valueType.read(avroCond.getValue().array()); } CompareOp op = convert(avroCond.getOperator()); boolean allowMissing = avroCond.getAllowMissing(); conditions.add(new MutationCondition(name, op, value, allowMissing)); } return conditions; }
private LilyIndexerConf build(Document doc, LRepository repository) throws IndexerConfException { validate(doc); this.doc = doc; this.repository = repository; this.typeManager = repository.getTypeManager(); this.systemFields = SystemFields.getInstance(repository.getTypeManager(), repository.getIdGenerator()); this.conf = new LilyIndexerConf(); this.conf.setSystemFields(systemFields); try { buildRecordFilter(); buildFormatters(); buildIndexFields(); buildDynamicFields(); } catch (Exception e) { throw new IndexerConfException("Error in the configuration.", e); } return conf; }
FieldType fieldType = repository.getTypeManager().getFieldTypeByName(qname); ValueHandle subHandle = new ValueHandle(fields.get(entry.getKey()), "fields." + entry.getKey(), fieldType.getValueType());
FieldType fieldType = repository.getTypeManager().getFieldTypeByName(filter.getField()); DataOutput dataOutput = new DataOutputImpl(); fieldType.getValueType().write(filter.getFieldValue(), dataOutput, new IdentityRecordStack());
private Object getValue(IndexUpdateBuilder indexUpdateBuilder, FieldType fieldType) throws RepositoryException, InterruptedException { Object value = null; Record record = indexUpdateBuilder.getRecordContext().record; if (systemFields.isSystemField(fieldType.getName())) { if (record != null) { value = systemFields.eval(record, fieldType, indexUpdateBuilder.getRepository().getTypeManager()); } } else { indexUpdateBuilder.addDependency(fieldType.getId()); if (record != null && record.hasField(fieldType.getName())) { value = record.getField(fieldType.getName()); } } return value; }
@Override public FieldValueFilter fromJson(JsonNode node, Namespaces namespaces, LRepository repository, RecordFilterJsonConverter<RecordFilter> converter) throws JsonFormatException, RepositoryException, InterruptedException { FieldValueFilter filter = new FieldValueFilter(); String field = JsonUtil.getString(node, "field", null); JsonNode fieldValue = node.get("fieldValue"); // field and fieldValue should be specified both, or not at all, for deserialization to work if ((field != null || fieldValue != null) && (field == null || fieldValue == null)) { throw new RuntimeException("FieldValueFilter deserialization: both field and fieldValue must be specified."); } if (field != null && fieldValue != null) { QName fieldQName = QNameConverter.fromJson(field, namespaces); filter.setField(fieldQName); ValueType valueType = repository.getTypeManager().getFieldTypeByName(fieldQName).getValueType(); Object value = RecordReader.INSTANCE.readValue( new RecordReader.ValueHandle(fieldValue, "fieldValue", valueType), new RecordReader.ReadContext(repository, new NamespacesImpl(), defaultLinkTransformer)); filter.setFieldValue(value); } String compareOp = JsonUtil.getString(node, "compareOp", null); if (compareOp != null) { filter.setCompareOp(CompareOp.valueOf(compareOp)); } filter.setFilterIfMissing(JsonUtil.getBoolean(node, "filterIfMissing", filter.getFilterIfMissing())); return filter; }
node.put("field", QNameConverter.toJson(filter.getField(), namespaces)); ValueType valueType = repository.getTypeManager().getFieldTypeByName(filter.getField()).getValueType(); JsonNode valueAsJson = RecordWriter.INSTANCE.valueToJson(filter.getFieldValue(), valueType, new WriteOptions(), namespaces, repository);
public FieldType importFieldType(FieldType fieldType) throws RepositoryException, ImportConflictException, ImportException, JsonFormatException, InterruptedException { ImportResult<FieldType> result = FieldTypeImport.importFieldType(fieldType, ImportMode.CREATE_OR_UPDATE, IdentificationMode.NAME, fieldType.getName(), repository.getTypeManager()); FieldType newFieldType = result.getEntity(); switch (result.getResultType()) { case CREATED: importListener.created(EntityType.FIELD_TYPE, newFieldType.getName().toString(), newFieldType.getId().toString()); break; case UP_TO_DATE: importListener.existsAndEqual(EntityType.FIELD_TYPE, newFieldType.getName().toString(), null); break; case CONFLICT: importListener.conflict(EntityType.FIELD_TYPE, fieldType.getName().toString(), result.getConflictingProperty(), result.getConflictingOldValue(), result.getConflictingNewValue()); break; default: throw new ImportException("Unexpected import result type for field type: " + result.getResultType()); } return newFieldType; }