/** * Read in this item's start tag attributes. * * <p> * The implementation in {@link AbstractSchemaItem} reads in required storage ID and name attributes. * * <p> * Start state: positioned at opening XML tag. * Return state: same. */ void readAttributes(XMLStreamReader reader, int formatVersion) throws XMLStreamException { final Integer storageIdAttr = this.getIntAttr(reader, XMLConstants.STORAGE_ID_ATTRIBUTE, false); if (storageIdAttr != null) this.setStorageId(storageIdAttr); final String nameAttr = this.getAttr(reader, XMLConstants.NAME_ATTRIBUTE, false); if (nameAttr != null) this.setName(nameAttr); }
@Override public SchemaField clone() { return (SchemaField)super.clone(); } }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (!super.equals(obj)) return false; final SchemaCompositeIndex that = (SchemaCompositeIndex)obj; return this.indexedFields.equals(that.indexedFields); }
void initialize(JSimpleDB jdb, AbstractSchemaItem schemaItem) { schemaItem.setName(this.name); schemaItem.setStorageId(this.storageId); }
static <T extends AbstractSchemaItem> void verifyUniqueStorageId(TreeMap<Integer, T> itemsByStorageId, T item) { final int storageId = item.getStorageId(); final T previous = itemsByStorageId.get(storageId); if (previous != null && !previous.equals(item)) { throw new InvalidSchemaException("incompatible duplicate use of storage ID " + storageId + " by both " + previous + " and " + item); } itemsByStorageId.put(storageId, item); }
@Override public Diffs differencesFrom(SchemaCompositeIndex that) { final Diffs diffs = new Diffs(super.differencesFrom(that)); if (!this.indexedFields.equals(that.indexedFields)) diffs.add("changed indexed field storage IDs from " + that.indexedFields + " to " + this.indexedFields); return diffs; }
/** * Read in this item's sub-elements. * * <p> * The implementation in {@link AbstractSchemaItem} expects no sub-elements. * * <p> * Start state: positioned at opening XML tag. * Return state: positioned at closing XML tag. */ void readSubElements(XMLStreamReader reader, int formatVersion) throws XMLStreamException { this.expectClose(reader); }
/** * Read an {@link Enum} attribute. * * @param reader XML reader * @param type {@link Enum} type * @param name attribute name * @param defaultValue default value, or null if value is required */ <T extends Enum<T>> T readAttr(XMLStreamReader reader, Class<T> type, QName name, T defaultValue) throws XMLStreamException { final String text = this.getAttr(reader, name, defaultValue == null); if (text == null) return defaultValue; try { return Enum.valueOf(type, text); } catch (IllegalArgumentException e) { throw new XMLStreamException("invalid value `" + text + " for \"" + name.getLocalPart() + "\" attribute in " + this, reader.getLocation()); } }
/** * Read an element found in the given map. * * @return element found, or null if closing XML tag encountered instead */ <T> T readMappedType(XMLStreamReader reader, boolean closingOK, Map<QName, Class<? extends T>> tagMap) throws XMLStreamException { // Expect to see one of the map's XML tag keys if (!this.expect(reader, closingOK, tagMap.keySet().toArray(new QName[tagMap.size()]))) return null; // Instantiate the corresponding type T obj = null; for (Map.Entry<QName, Class<? extends T>> entry : tagMap.entrySet()) { if (reader.getName().equals(entry.getKey())) { try { return entry.getValue().newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException("unexpected exception", e); } } } throw new RuntimeException("internal error: didn't find " + reader.getName() + " in tagMap"); }
@Override public Diffs differencesFrom(SchemaObjectType that) { final Diffs diffs = new Diffs(super.differencesFrom(that));
@Override @SuppressWarnings("unchecked") public SchemaCompositeIndex clone() { final SchemaCompositeIndex clone = (SchemaCompositeIndex)super.clone(); clone.indexedFields = new ArrayList<>(clone.indexedFields); return clone; } }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (!super.equals(obj)) return false; final SchemaObjectType that = (SchemaObjectType)obj; return this.schemaFields.equals(that.schemaFields) && this.schemaCompositeIndexes.equals(that.schemaCompositeIndexes); }
@Override @SuppressWarnings("unchecked") public SchemaObjectType clone() { final SchemaObjectType clone = (SchemaObjectType)super.clone(); clone.schemaFields = new TreeMap<>(clone.schemaFields); for (Map.Entry<Integer, SchemaField> entry : clone.schemaFields.entrySet()) entry.setValue(entry.getValue().clone()); clone.schemaCompositeIndexes = new TreeMap<>(clone.schemaCompositeIndexes); for (Map.Entry<Integer, SchemaCompositeIndex> entry : clone.schemaCompositeIndexes.entrySet()) entry.setValue(entry.getValue().clone()); return clone; } }