public static OIndexDefinition getIndexDefinitionFromIndex(IndexWriter writer) { final Document metaDoc = retrieveIndexMetadata(writer); final ODocument defAsJson = new ODocument().fromJSON(metaDoc.get("_DEF_JSON")); final String defClassName = metaDoc.get("_DEF_CLASS_NAME"); try { final Class<?> indexDefClass = Class.forName(defClassName); OIndexDefinition indexDefinition = (OIndexDefinition) indexDefClass.getDeclaredConstructor().newInstance(); indexDefinition.fromStream(defAsJson); return indexDefinition; } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { throw OException.wrapException(new OLuceneIndexException("Error during deserialization of index definition"), e); } }
private OIndexDefinition importIndexDefinition() throws IOException, ParseException { jsonReader.readString(OJSONReader.BEGIN_OBJECT); jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT); final String className = jsonReader.readString(OJSONReader.NEXT_IN_OBJECT); jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT); final String value = jsonReader.readString(OJSONReader.END_OBJECT, true); final OIndexDefinition indexDefinition; final ODocument indexDefinitionDoc = (ODocument) ORecordSerializerJSON.INSTANCE.fromString(value, null, null); try { final Class<?> indexDefClass = Class.forName(className); indexDefinition = (OIndexDefinition) indexDefClass.getDeclaredConstructor().newInstance(); indexDefinition.fromStream(indexDefinitionDoc); } catch (final ClassNotFoundException e) { throw new IOException("Error during deserialization of index definition", e); } catch (final NoSuchMethodException e) { throw new IOException("Error during deserialization of index definition", e); } catch (final InvocationTargetException e) { throw new IOException("Error during deserialization of index definition", e); } catch (final InstantiationException e) { throw new IOException("Error during deserialization of index definition", e); } catch (final IllegalAccessException e) { throw new IOException("Error during deserialization of index definition", e); } jsonReader.readNext(OJSONReader.NEXT_IN_OBJECT); return indexDefinition; }
indexDefinition.fromStream(indDoc);
final Class<?> indexDefClass = Class.forName(indexDefClassName); loadedIndexDefinition = (OIndexDefinition) indexDefClass.getDeclaredConstructor().newInstance(); loadedIndexDefinition.fromStream(indexDefinitionDoc);