/** Inserts the feature to the index but does not stages it to be committed */ public ObjectId insert(GeogitTransaction transaction, Feature f) throws Exception { final WorkingTree workTree = (transaction != null ? transaction.getWorkingTree() : repo.getWorkingTree()); Name name = f.getType().getName(); String parentPath = name.getLocalPart(); Node ref = workTree.insert(parentPath, f); ObjectId objectId = ref.getObjectId(); return objectId; }
protected void writeNode(Writer w, Node node) throws IOException { print(w, TreeNode.REF.name()); print(w, "\t"); print(w, node.getType().name()); print(w, "\t"); print(w, node.getName()); print(w, "\t"); print(w, node.getObjectId().toString()); print(w, "\t"); print(w, node.getMetadataId().or(ObjectId.NULL).toString()); print(w, "\t"); Envelope envHelper = new Envelope(); writeBBox(w, node, envHelper); println(w); }
@Override protected RevTree read(ObjectId id, BufferedReader reader, TYPE type) throws IOException { Preconditions.checkArgument(TYPE.TREE.equals(type), "Wrong type: %s", type.name()); Builder<Node> features = ImmutableList.builder(); Builder<Node> trees = ImmutableList.builder(); TreeMap<Integer, Bucket> subtrees = Maps.newTreeMap(); long size = Long.parseLong(parseLine(requireLine(reader), "size")); int numTrees = Integer.parseInt(parseLine(requireLine(reader), "numtrees")); String line; while ((line = reader.readLine()) != null) { Preconditions.checkArgument(!line.isEmpty(), "Empty tree element definition"); ArrayList<String> tokens = Lists.newArrayList(Splitter.on('\t').split(line)); String nodeType = tokens.get(0); if (nodeType.equals(TextWriter.TreeNode.REF.name())) { Node entryRef = parseNodeLine(line); if (entryRef.getType().equals(TYPE.TREE)) { trees.add(entryRef); } else { features.add(entryRef); } } else if (nodeType.equals(TextWriter.TreeNode.BUCKET.name())) { Preconditions.checkArgument(tokens.size() == 4, "Wrong bucket definition: %s", line); Integer idx = Integer.parseInt(tokens.get(1)); ObjectId bucketId = ObjectId.valueOf(tokens.get(2)); Envelope bounds = parseBBox(tokens.get(3)); Bucket bucket = Bucket.create(bucketId, bounds); subtrees.put(idx, bucket); } else { throw new IllegalArgumentException("Wrong tree element definition: " + line); } } RevTree tree; if (subtrees.isEmpty()) { tree = RevTreeImpl.createLeafTree(id, size, features.build(), trees.build()); } else { tree = RevTreeImpl.createNodeTree(id, size, numTrees, subtrees); } return tree; }
protected Node parseNodeLine(String line) { List<String> tokens = Lists.newArrayList(Splitter.on('\t').split(line)); Preconditions.checkArgument(tokens.size() == 6, "Wrong tree element definition: %s", line); TYPE type = TYPE.valueOf(tokens.get(1)); String name = tokens.get(2); ObjectId id = ObjectId.valueOf(tokens.get(3)); ObjectId metadataId = ObjectId.valueOf(tokens.get(4)); Envelope bbox = parseBBox(tokens.get(5)); org.geogit.api.Node ref = org.geogit.api.Node.create(name, id, metadataId, type, bbox); return ref; }
protected void writeBBox(Writer w, Node node, Envelope envHelper) throws IOException { envHelper.setToNull(); node.expand(envHelper); writeEnvelope(w, envHelper); }