/** * Get the sub-field with the given storage ID. * * @param storageId sub-field storage ID * @throws IllegalArgumentException if not found */ JSimpleField getSubField(int storageId) { for (JSimpleField subField : this.getSubFields()) { if (subField.storageId == storageId) return subField; } throw new IllegalArgumentException("storage ID " + storageId + " not found"); }
@Override public io.permazen.annotation.JMapField getDeclaringAnnotation() { return (io.permazen.annotation.JMapField)super.getDeclaringAnnotation(); }
@Override final void outputMethods(ClassGenerator<?> generator, ClassWriter cw) { this.outputCachedNonSimpleValueGetterMethod(generator, cw, this.getFieldReaderMethod()); }
for (JSimpleField subField : superField.getSubFields()) { if (buf.length() == 0) { buf.append("path may not end on complex ") description = "sub-field `" + subFieldName + "' of complex " + description; try { matchingField = superField.getSubField(subFieldName); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("invalid " + description + ": " + e.getMessage(), e);
@Override boolean isSameAs(JField that0) { if (!super.isSameAs(that0)) return false; final JCollectionField that = (JCollectionField)that0; if (!this.elementField.isSameAs(that.elementField)) return false; return true; }
void initialize(Permazen jdb, CollectionSchemaField schemaField) { super.initialize(jdb, schemaField); schemaField.setElementField(this.elementField.toSchemaItem(jdb)); }
@Override final void outputFields(ClassGenerator<?> generator, ClassWriter cw) { this.outputCachedValueField(generator, cw); }
private Set<TypeToken<?>> getTypeTokens(Permazen jdb, Class<?> context, int storageId, int parentStorageId) { final HashSet<TypeToken<?>> contextFieldTypes = new HashSet<>(); for (JClass<?> jclass : jdb.jclasses.values()) { // Check if jclass is under consideration if (!context.isAssignableFrom(jclass.type)) continue; // Find the simple field field in jclass, if it exists JSimpleField simpleField = null; if (parentStorageId != 0) { final JComplexField parentField = (JComplexField)jclass.jfields.get(parentStorageId); if (parentField != null) simpleField = parentField.getSubField(storageId); } else simpleField = (JSimpleField)jclass.jfields.get(storageId); if (simpleField == null) continue; // Add field's type in jclass contextFieldTypes.add(simpleField.typeToken); } if (contextFieldTypes.isEmpty()) { throw new IllegalArgumentException("no sub-type of " + context + " contains and indexed simple field with storage ID " + storageId); } return Util.findLowestCommonAncestors(contextFieldTypes); }
@Override SimpleFieldIndexInfo toIndexInfo() { if (!this.indexed) return null; final JComplexField parentField = this.getParentField(); return parentField != null ? parentField.toIndexInfo(this) : new RegularSimpleFieldIndexInfo(this); }
FieldSortKey(JSimpleField jfield) { super((jfield.getParentField() != null ? DefaultFieldFactory.createCaptionByPropertyId(jfield.getParentField().getName()) + "." : "") + DefaultFieldFactory.createCaptionByPropertyId(jfield.getName())); this.storageId = jfield.getStorageId(); this.isSubField = jfield.getParentField() != null; this.fieldName = (this.isSubField ? jfield.getParentField().getName() + "." : "") + jfield.getName(); this.fieldType = jfield.getTypeToken().wrap().getRawType(); }
@Override boolean isSameAs(JField that0) { if (!super.isSameAs(that0)) return false; final JMapField that = (JMapField)that0; if (!this.keyField.isSameAs(that.keyField)) return false; if (!this.valueField.isSameAs(that.valueField)) return false; return true; }
@Override MapSchemaField toSchemaItem(Permazen jdb) { final MapSchemaField schemaField = new MapSchemaField(); super.initialize(jdb, schemaField); schemaField.setKeyField(this.keyField.toSchemaItem(jdb)); schemaField.setValueField(this.valueField.toSchemaItem(jdb)); return schemaField; }
private SortKeyContainer(Permazen jdb, JClass<?> jclass, Class<?> type) { super(SortKey.class); this.jdb = jdb; this.jclass = jclass; this.type = type; // Add sort keys common to all objects final ArrayList<SortKey> sortKeys = new ArrayList<>(); sortKeys.add(new ObjectIdSortKey()); sortKeys.add(new VersionSortKey()); // Identify fields common to all sub-types of `type' SortedMap<Integer, JField> commonFields = Util.getCommonJFields(this.jdb.getJClasses(this.type)); // Add sort keys for all indexed fields common to all sub-types if (commonFields != null) { for (JField jfield : commonFields.values()) { if (jfield instanceof JComplexField) { ((JComplexField)jfield).getSubFields().stream() .filter(subField -> subField.isIndexed()) .map(FieldSortKey::new) .forEach(sortKeys::add); } else if (jfield instanceof JSimpleField && ((JSimpleField)jfield).isIndexed()) sortKeys.add(new FieldSortKey((JSimpleField)jfield)); } } // Sort indexed field sort keys Collections.sort(sortKeys.subList(2, sortKeys.size()), Comparator.comparing(SortKey::getDescription)); // Load container this.load(sortKeys); }
} else if (jfield instanceof JComplexField) { final JComplexField parentField = (JComplexField)jfield; for (JSimpleField subField : parentField.getSubFields()) { if (subField.indexed) this.addIndexInfo(subField, descriptionMap); if (jfield instanceof JComplexField) { final JComplexField parentField = (JComplexField)jfield; for (JSimpleField subField : parentField.getSubFields()) this.typeFieldMap.put(this.getTypeFieldKey(jclass.storageId, subField.storageId), subField);