use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ODatabaseExport method exportSchema.
private void exportSchema() throws IOException {
listener.onMessage("\nExporting schema...");
writer.beginObject(1, true, "schema");
OSchema s = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot();
writer.writeAttribute(2, true, "version", s.getVersion());
writer.writeAttribute(2, false, "blob-clusters", database.getBlobClusterIds());
if (!s.getClasses().isEmpty()) {
writer.beginCollection(2, true, "classes");
final List<OClass> classes = new ArrayList<OClass>(s.getClasses());
Collections.sort(classes);
for (OClass cls : classes) {
// CHECK TO FILTER CLASS
if (includeClasses != null) {
if (!includeClasses.contains(cls.getName().toUpperCase()))
continue;
} else if (excludeClasses != null) {
if (excludeClasses.contains(cls.getName().toUpperCase()))
continue;
}
writer.beginObject(3, true, null);
writer.writeAttribute(0, false, "name", cls.getName());
writer.writeAttribute(0, false, "default-cluster-id", cls.getDefaultClusterId());
writer.writeAttribute(0, false, "cluster-ids", cls.getClusterIds());
if (cls.getOverSize() > 1)
writer.writeAttribute(0, false, "oversize", cls.getClassOverSize());
if (cls.isStrictMode())
writer.writeAttribute(0, false, "strictMode", cls.isStrictMode());
if (!cls.getSuperClasses().isEmpty())
writer.writeAttribute(0, false, "super-classes", cls.getSuperClassesNames());
if (cls.getShortName() != null)
writer.writeAttribute(0, false, "short-name", cls.getShortName());
if (cls.isAbstract())
writer.writeAttribute(0, false, "abstract", cls.isAbstract());
// @SINCE 1.7
writer.writeAttribute(0, false, "cluster-selection", cls.getClusterSelection().getName());
if (!cls.properties().isEmpty()) {
writer.beginCollection(4, true, "properties");
final List<OProperty> properties = new ArrayList<OProperty>(cls.declaredProperties());
Collections.sort(properties);
for (OProperty p : properties) {
writer.beginObject(5, true, null);
writer.writeAttribute(0, false, "name", p.getName());
writer.writeAttribute(0, false, "type", p.getType().toString());
if (p.isMandatory())
writer.writeAttribute(0, false, "mandatory", p.isMandatory());
if (p.isReadonly())
writer.writeAttribute(0, false, "readonly", p.isReadonly());
if (p.isNotNull())
writer.writeAttribute(0, false, "not-null", p.isNotNull());
if (p.getLinkedClass() != null)
writer.writeAttribute(0, false, "linked-class", p.getLinkedClass().getName());
if (p.getLinkedType() != null)
writer.writeAttribute(0, false, "linked-type", p.getLinkedType().toString());
if (p.getMin() != null)
writer.writeAttribute(0, false, "min", p.getMin());
if (p.getMax() != null)
writer.writeAttribute(0, false, "max", p.getMax());
if (p.getCollate() != null)
writer.writeAttribute(0, false, "collate", p.getCollate().getName());
if (p.getDefaultValue() != null)
writer.writeAttribute(0, false, "default-value", p.getDefaultValue());
if (p.getRegexp() != null)
writer.writeAttribute(0, false, "regexp", p.getRegexp());
final Set<String> customKeys = p.getCustomKeys();
final Map<String, String> custom = new HashMap<String, String>();
for (String key : customKeys) custom.put(key, p.getCustom(key));
if (!custom.isEmpty())
writer.writeAttribute(0, false, "customFields", custom);
writer.endObject(0, false);
}
writer.endCollection(4, true);
}
final Set<String> customKeys = cls.getCustomKeys();
final Map<String, String> custom = new HashMap<String, String>();
for (String key : customKeys) custom.put(key, cls.getCustom(key));
if (!custom.isEmpty())
writer.writeAttribute(0, false, "customFields", custom);
writer.endObject(3, true);
}
writer.endCollection(2, true);
}
writer.endObject(1, true);
listener.onMessage("OK (" + s.getClasses().size() + " classes)");
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class OIndexManagerAbstract method acquireExclusiveLock.
protected void acquireExclusiveLock() {
final ODatabaseDocument databaseRecord = getDatabaseIfDefined();
if (databaseRecord != null && !databaseRecord.isClosed()) {
final OMetadataInternal metadata = (OMetadataInternal) databaseRecord.getMetadata();
if (metadata != null)
metadata.makeThreadLocalSchemaSnapshot();
}
lock.writeLock().lock();
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ODocument method fetchSchemaIfCan.
private void fetchSchemaIfCan() {
if (_schema == null) {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null && !db.isClosed()) {
OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
_schema = metadata.getImmutableSchemaSnapshot();
}
}
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ODocument method getGlobalPropertyById.
protected OGlobalProperty getGlobalPropertyById(int id) {
if (_schema == null) {
OMetadataInternal metadata = (OMetadataInternal) getDatabase().getMetadata();
_schema = metadata.getImmutableSchemaSnapshot();
}
OGlobalProperty prop = _schema.getGlobalPropertyById(id);
if (prop == null) {
ODatabaseDocument db = getDatabase();
if (db == null || db.isClosed())
throw new ODatabaseException("Cannot unmarshall the document because no database is active, use detach for use the document outside the database session scope");
OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
if (metadata.getImmutableSchemaSnapshot() != null)
metadata.clearThreadLocalSchemaSnapshot();
metadata.reload();
metadata.makeThreadLocalSchemaSnapshot();
_schema = metadata.getImmutableSchemaSnapshot();
prop = _schema.getGlobalPropertyById(id);
}
return prop;
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class ORecordSerializerCSVAbstract method fieldFromStream.
public Object fieldFromStream(final ORecord iSourceRecord, final OType iType, OClass iLinkedClass, OType iLinkedType, final String iName, final String iValue) {
if (iValue == null)
return null;
switch(iType) {
case EMBEDDEDLIST:
case EMBEDDEDSET:
return embeddedCollectionFromStream((ODocument) iSourceRecord, iType, iLinkedClass, iLinkedType, iValue);
case LINKSET:
case LINKLIST:
{
if (iValue.length() == 0)
return null;
// REMOVE BEGIN & END COLLECTIONS CHARACTERS IF IT'S A COLLECTION
final String value = iValue.startsWith("[") || iValue.startsWith("<") ? iValue.substring(1, iValue.length() - 1) : iValue;
if (iType == OType.LINKLIST) {
return new ORecordLazyList((ODocument) iSourceRecord).setStreamedContent(new StringBuilder(value));
} else {
return unserializeSet((ODocument) iSourceRecord, value);
}
}
case LINKMAP:
{
if (iValue.length() == 0)
return null;
// REMOVE BEGIN & END MAP CHARACTERS
String value = iValue.substring(1, iValue.length() - 1);
@SuppressWarnings("rawtypes") final Map map = new ORecordLazyMap((ODocument) iSourceRecord, ODocument.RECORD_TYPE);
if (value.length() == 0)
return map;
final List<String> items = OStringSerializerHelper.smartSplit(value, OStringSerializerHelper.RECORD_SEPARATOR, true, false);
// EMBEDDED LITERALS
for (String item : items) {
if (item != null && !item.isEmpty()) {
final List<String> entry = OStringSerializerHelper.smartSplit(item, OStringSerializerHelper.ENTRY_SEPARATOR);
if (!entry.isEmpty()) {
String mapValue = entry.get(1);
if (mapValue != null && !mapValue.isEmpty())
mapValue = mapValue.substring(1);
map.put(fieldTypeFromStream((ODocument) iSourceRecord, OType.STRING, entry.get(0)), new ORecordId(mapValue));
}
}
}
return map;
}
case EMBEDDEDMAP:
return embeddedMapFromStream((ODocument) iSourceRecord, iLinkedType, iValue, iName);
case LINK:
if (iValue.length() > 1) {
int pos = iValue.indexOf(OStringSerializerHelper.CLASS_SEPARATOR);
if (pos > -1)
((OMetadataInternal) ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata()).getImmutableSchemaSnapshot().getClass(iValue.substring(1, pos));
else
pos = 0;
final String linkAsString = iValue.substring(pos + 1);
try {
return new ORecordId(linkAsString);
} catch (IllegalArgumentException e) {
OLogManager.instance().error(this, "Error on unmarshalling field '%s' of record '%s': value '%s' is not a link", iName, iSourceRecord, linkAsString);
return new ORecordId();
}
} else
return null;
case EMBEDDED:
if (iValue.length() > 2) {
// REMOVE BEGIN & END EMBEDDED CHARACTERS
final String value = iValue.substring(1, iValue.length() - 1);
final Object embeddedObject = OStringSerializerEmbedded.INSTANCE.fromStream(value);
if (embeddedObject instanceof ODocument)
ODocumentInternal.addOwner((ODocument) embeddedObject, iSourceRecord);
// RECORD
return embeddedObject;
} else
return null;
case LINKBAG:
final String value = iValue.charAt(0) == OStringSerializerHelper.BAG_BEGIN ? iValue.substring(1, iValue.length() - 1) : iValue;
return ORidBag.fromStream(value);
default:
return fieldTypeFromStream((ODocument) iSourceRecord, iType, iValue);
}
}
Aggregations