@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final SubDocument other = (SubDocument) obj; if (this.documentId != other.documentId) { return false; } if (this.index != other.index) { return false; } if (this.values != other.values && (this.values == null || !this.values.equals(other.values))) { return false; } if (this.type != other.type && (this.type == null || !this.type.equals(other.type))) { return false; } return true; }
@Override public Builder add(String key, ScalarValue value) { Preconditions.checkArgument(expectedType.getAttribute(key) != null); return super.add(key, value); } }
@SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON") public Iterable<Field<? extends ScalarValue<? extends Serializable>>> getSubDocFields() { final Iterator<Field<? extends ScalarValue<? extends Serializable>>> iterator = new AbstractIterator<Field<? extends ScalarValue<? extends Serializable>>>() { Iterator<String> attIt = erasuredType.getAttributeKeys().iterator(); @Override protected Field<? extends ScalarValue<? extends Serializable>> computeNext() { if (!attIt.hasNext()) { endOfData(); return null; } return (Field<? extends ScalarValue<? extends Serializable>>) field(attIt.next()); } }; return new Iterable<Field<? extends ScalarValue<? extends Serializable>>>() { @Override public Iterator<Field<? extends ScalarValue<? extends Serializable>>> iterator() { return iterator; } }; }
public void setSubDoc(SubDocument subdoc) throws IllegalArgumentException { if (!table.getSubDocType().equals(subdoc.getType())) { throw new IllegalArgumentException("Type of table " + table + " is " + table.getSubDocType() + " which is " + "different than the type of the given subdocument (" + subdoc.getType() + ")"); } for (String key : subdoc.getType().getAttributeKeys()) { String fieldName = table.subDocHelper().toColumnName(key); //@gortiz: I think we can not use types here! Field f = field(fieldName); ScalarValue<?> v = subdoc.getValue(key); setValue(f, v); } }
SubDocType type2 = structure2.getType(); if (!type1.equals(type2)) { Collection<SubDocAttribute> attributes1 = type1.getAttributes(); Collection<SubDocAttribute> attributes2 = type2.getAttributes();
@Override public int hashCode() { int hash = 7; hash = 79 * hash + this.documentId; hash = 79 * hash + this.index; hash = 79 * hash + (this.type != null ? this.type.hashCode() : 0); return hash; }
public SubDocType build() { built = true; return new SubDocType(attributes); } }
private SubDocTable( String alias, Schema schema, Table<SubDocTableRecord> aliased, Field<?>[] parameters, @Nonnull SubDocType type, DatabaseInterface databaseInterface ) { super(alias, schema, aliased, parameters, ""); this.erasuredType = type; for (SubDocAttribute attibute : type.getAttributes()) { String fieldName = new SubDocHelper(databaseInterface).toColumnName(attibute.getKey()); DataType<?> dataType = databaseInterface.getValueToJooqDataTypeProvider().getDataType(attibute.getType()); createField( fieldName, dataType, this, ""); } this.databaseInterface = databaseInterface; }
@Override public int hashCode() { int hash = 7; hash = 37 * hash + this.type.hashCode(); hash = 37 * hash + this.index; return hash; }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (getClass() != obj.getClass()) { return false; } final DocStructure other = (DocStructure) obj; if (!this.type.equals(other.type)) { return false; } if (this.index != other.index) { return false; } if (!this.elements.equals(other.elements)) { return false; } return true; }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (getClass() != obj.getClass()) { return false; } final SubDocType other = (SubDocType) obj; if (other.hash != this.hash) { return false; } if (other.attributes.size() != this.attributes.size()) { return false; } for (SubDocAttribute thisAtt : this.attributes.values()) { SubDocAttribute otherAtt = other.getAttribute(thisAtt.getKey()); if (!otherAtt.equalsWithSameKey(thisAtt)) { return false; } } return true; }
int attSize = structure.getElements().size() + structure.getType().getAttributeKeys().size(); List<String> attributes = Lists.newArrayListWithCapacity(attSize); attributes.addAll(structure.getElements().keySet()); attributes.addAll(structure.getType().getAttributeKeys());
docCounter++; assert subDocument.getType().equals(type);
@Override public Builder add(SubDocAttribute att, ScalarValue value) { String key = att.getKey(); Preconditions.checkArgument(att.equals(expectedType.getAttribute(key))); return super.add(att, value); }
private static KVDocument translateDocStructure(SubDocValueToDocValueTranslator.Argument arg) { DocStructure structure = (DocStructure) arg.structure; SplitDocument splitDocument = arg.splitDoc; LinkedHashMap<String, KVValue<?>> map = new LinkedHashMap<>(); SubDocument subDoc = splitDocument.getSubDocuments().get( structure.getType(), structure.getIndex()); for (String keyName : subDoc.getType().getAttributeKeys()) { //childStructure will be null if the child is a scalar StructureElement childStructure = structure.getElements().get(keyName); arg.structure = childStructure; map.put( keyName, subDoc.getValue(keyName).accept(VALUE_TRANSLATOR, arg) ); } for (Map.Entry<String, StructureElement> entry : structure.getElements().entrySet()) { if (entry.getValue() instanceof DocStructure) { //arrays has already been mapped as values StructureElement childStructure = structure.getElements().get(entry.getKey()); arg.structure = childStructure; map.put( entry.getKey(), translateDocStructure(arg) ); } } return new MapKVDocument(map); }
@Override public void insertSubdocuments(String collection, SubDocType type, Iterable<? extends SubDocument> subDocuments) { try { SubDocTable table = meta.getCollectionSchema(collection).getSubDocTable(type); InsertSetMoreStep<?> insert = null; for (SubDocument subDocument : subDocuments) { assert subDocument.getType().equals(type); SubDocTableRecord record = new SubDocTableRecord(table, subDocTypeBuilderProvider); record.setDid(subDocument.getDocumentId()); record.setIndex(translateSubDocIndexToDatabase(subDocument.getIndex())); record.setSubDoc(subDocument); if (insert == null) { insert = dsl.insertInto(table).set(record); } else { insert = insert.newRecord().set(record); } } if (insert != null) { insert.execute(); } else { assert false : "Call to insertSubdocuments with an empty set of subdocuments"; LOGGER.warn("Call to insertSubdocuments with an empty set of subdocuments"); } } catch (DataAccessException ex) { //TODO: Change exception throw new RuntimeException(ex); } }
@Override TriValuedResult<ScalarType> finalStep(DocStructure structure, AttributeReference.ObjectKey key, AbstractResolver.Argument arg) { SubDocAttribute attribute = structure.getType().getAttribute(key .getKey()); if (attribute == null) { return TriValuedResult.NULL; } return TriValuedResult.createValue(attribute.getType()); }
docStructure.getType().getAttributeKeys(), docStructure.getElements().keySet() );
String attName = getAttributeName(columnName); if (attName != null) { //it is an attribute SubDocAttribute attribute = subDocType.getAttribute(attName);
SubDocAttribute attribute = lastDocStructure .getType() .getAttribute( objKey.getKey() );