use of com.orientechnologies.orient.core.metadata.schema.OType in project orientdb by orientechnologies.
the class ORecordSerializerNetworkV0 method writeLinkMap.
private int writeLinkMap(final BytesContainer bytes, final Map<Object, OIdentifiable> map) {
final boolean disabledAutoConversion = map instanceof ORecordLazyMultiValue && ((ORecordLazyMultiValue) map).isAutoConvertToRecord();
if (disabledAutoConversion)
// AVOID TO FETCH RECORD
((ORecordLazyMultiValue) map).setAutoConvertToRecord(false);
try {
final int fullPos = OVarIntSerializer.write(bytes, map.size());
for (Entry<Object, OIdentifiable> entry : map.entrySet()) {
// TODO:check skip of complex types
// FIXME: changed to support only string key on map
final OType type = OType.STRING;
writeOType(bytes, bytes.alloc(1), type);
writeString(bytes, entry.getKey().toString());
if (entry.getValue() == null)
writeNullLink(bytes);
else
writeOptimizedLink(bytes, entry.getValue());
}
return fullPos;
} finally {
if (disabledAutoConversion)
((ORecordLazyMultiValue) map).setAutoConvertToRecord(true);
}
}
use of com.orientechnologies.orient.core.metadata.schema.OType in project orientdb by orientechnologies.
the class ORecordSerializerNetworkV0 method writeEmbeddedMap.
@SuppressWarnings("unchecked")
private int writeEmbeddedMap(BytesContainer bytes, Map<Object, Object> map) {
final int[] pos = new int[map.size()];
int i = 0;
Entry<Object, Object>[] values = new Entry[map.size()];
final int fullPos = OVarIntSerializer.write(bytes, map.size());
for (Entry<Object, Object> entry : map.entrySet()) {
// TODO:check skip of complex types
// FIXME: changed to support only string key on map
OType type = OType.STRING;
writeOType(bytes, bytes.alloc(1), type);
writeString(bytes, entry.getKey().toString());
pos[i] = bytes.alloc(OIntegerSerializer.INT_SIZE + 1);
values[i] = entry;
i++;
}
for (i = 0; i < values.length; i++) {
int pointer = 0;
final Object value = values[i].getValue();
if (value != null) {
final OType type = getTypeFromValueEmbedded(value);
if (type == null) {
throw new OSerializationException("Impossible serialize value of type " + value.getClass() + " with the ODocument binary serializer");
}
pointer = serializeValue(bytes, value, type, null);
OIntegerSerializer.INSTANCE.serializeLiteral(pointer, bytes.bytes, pos[i]);
writeOType(bytes, (pos[i] + OIntegerSerializer.INT_SIZE), type);
}
}
return fullPos;
}
use of com.orientechnologies.orient.core.metadata.schema.OType in project orientdb by orientechnologies.
the class OSecurityShared method createOrUpdateORoleClass.
private OClass createOrUpdateORoleClass(final ODatabaseDocument database, OClass identityClass) {
OClass roleClass = database.getMetadata().getSchema().getClass("ORole");
boolean unsafe = false;
if (roleClass == null) {
roleClass = database.getMetadata().getSchema().createClass("ORole", identityClass);
unsafe = true;
} else if (!roleClass.getSuperClasses().contains(identityClass))
// MIGRATE AUTOMATICALLY TO 1.2.0
roleClass.setSuperClasses(Arrays.asList(identityClass));
if (!roleClass.existsProperty("name")) {
roleClass.createProperty("name", OType.STRING, (OType) null, unsafe).setMandatory(true).setNotNull(true).setCollate("ci");
roleClass.createIndex("ORole.name", INDEX_TYPE.UNIQUE, ONullOutputListener.INSTANCE, "name");
} else {
final OProperty name = roleClass.getProperty("name");
if (name.getAllIndexes().isEmpty())
roleClass.createIndex("ORole.name", INDEX_TYPE.UNIQUE, ONullOutputListener.INSTANCE, "name");
}
if (!roleClass.existsProperty("mode"))
roleClass.createProperty("mode", OType.BYTE, (OType) null, unsafe);
if (!roleClass.existsProperty("rules"))
roleClass.createProperty("rules", OType.EMBEDDEDMAP, OType.BYTE, unsafe);
if (!roleClass.existsProperty("inheritedRole"))
roleClass.createProperty("inheritedRole", OType.LINK, roleClass, unsafe);
return roleClass;
}
use of com.orientechnologies.orient.core.metadata.schema.OType in project orientdb by orientechnologies.
the class OCompositeKeySerializer method preprocess.
@Override
public OCompositeKey preprocess(OCompositeKey value, Object... hints) {
if (value == null)
return null;
final OType[] types = getKeyTypes(hints);
final List<Object> keys = value.getKeys();
final OCompositeKey compositeKey = new OCompositeKey();
final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
for (int i = 0; i < keys.size(); i++) {
final Object key = keys.get(i);
final OType type;
if (types.length > i)
type = types[i];
else
type = OType.getTypeByClass(key.getClass());
OBinarySerializer<Object> keySerializer = ((OBinarySerializer<Object>) factory.getObjectSerializer(type));
compositeKey.addKey(keySerializer.preprocess(key));
}
return compositeKey;
}
use of com.orientechnologies.orient.core.metadata.schema.OType in project orientdb by orientechnologies.
the class OCSVTransformer method executeTransform.
@Override
public Object executeTransform(final Object input) {
if (skipTransform())
return null;
log(OETLProcessor.LOG_LEVELS.DEBUG, "parsing=%s", input);
final List<String> fields = OStringSerializerHelper.smartSplit(input.toString(), new char[] { separator }, 0, -1, false, false, false, false, unicode);
if (!isColumnNamesCorrect(fields))
return null;
final ODocument doc = new ODocument();
for (int i = 0; i < columnNames.size() && i < fields.size(); ++i) {
final String fieldName = columnNames.get(i);
Object fieldValue = null;
try {
final String fieldStringValue = getCellContent(fields.get(i));
final OType fieldType = columnTypes != null ? columnTypes.get(i) : null;
if (fieldType != null && fieldType != OType.ANY) {
// DEFINED TYPE
fieldValue = processKnownType(doc, i, fieldName, fieldStringValue, fieldType);
} else {
// DETERMINE THE TYPE
if (fieldStringValue != null)
fieldValue = determineTheType(fieldStringValue);
}
doc.field(fieldName, fieldValue);
} catch (Exception e) {
processor.getStats().incrementErrors();
log(OETLProcessor.LOG_LEVELS.ERROR, "Error on setting document field %s=%s (cause=%s)", fieldName, fieldValue, e.toString());
}
}
log(OETLProcessor.LOG_LEVELS.DEBUG, "document=%s", doc);
return doc;
}
Aggregations