use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OClassImpl method firePropertyNameMigration.
public void firePropertyNameMigration(final ODatabaseDocument database, final String propertyName, final String newPropertyName, final OType type) {
final boolean strictSQL = ((ODatabaseInternal) database).getStorage().getConfiguration().isStrictSql();
database.query(new OSQLAsynchQuery<Object>("select from " + getEscapedName(name, strictSQL) + " where " + getEscapedName(propertyName, strictSQL) + " is not null ", new OCommandResultListener() {
@Override
public boolean result(Object iRecord) {
final ODocument record = ((OIdentifiable) iRecord).getRecord();
record.setFieldType(propertyName, type);
record.field(newPropertyName, record.field(propertyName), type);
database.save(record);
return true;
}
@Override
public void end() {
}
@Override
public Object getResult() {
return null;
}
}));
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OGlobalPropertyImpl method toDocument.
@Override
public ODocument toDocument() {
final ODocument doc = new ODocument();
doc.field("name", name);
doc.field("type", type.name());
doc.field("id", id);
return doc;
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OClassIndexManager method checkIndexes.
private ODocument checkIndexes(ODocument document, TYPE hookType) {
document = checkForLoading(document);
ODocument replaced = null;
final OClass cls = ODocumentInternal.getImmutableSchemaClass(document);
if (cls != null) {
final Collection<OIndex<?>> indexes = cls.getIndexes();
switch(hookType) {
case BEFORE_CREATE:
replaced = checkIndexedPropertiesOnCreation(document, indexes);
break;
case BEFORE_UPDATE:
checkIndexedPropertiesOnUpdate(document, indexes);
break;
default:
throw new IllegalArgumentException("Invalid hook type: " + hookType);
}
}
return replaced;
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OCompositeIndexDefinition method serializeToStream.
@Override
protected void serializeToStream() {
super.serializeToStream();
final List<ODocument> inds = new ArrayList<ODocument>(indexDefinitions.size());
final List<String> indClasses = new ArrayList<String>(indexDefinitions.size());
document.field("className", className);
for (final OIndexDefinition indexDefinition : indexDefinitions) {
final ODocument indexDocument = indexDefinition.toStream();
inds.add(indexDocument);
indClasses.add(indexDefinition.getClass().getName());
}
document.field("indexDefinitions", inds, OType.EMBEDDEDLIST);
document.field("indClasses", indClasses, OType.EMBEDDEDLIST);
document.field("nullValuesIgnored", isNullValuesIgnored());
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OIndexAbstract method loadMetadataInternal.
public static OIndexMetadata loadMetadataInternal(final ODocument config, final String type, final String algorithm, final String valueContainerAlgorithm) {
final String indexName = config.field(OIndexInternal.CONFIG_NAME);
final ODocument indexDefinitionDoc = config.field(OIndexInternal.INDEX_DEFINITION);
OIndexDefinition loadedIndexDefinition = null;
if (indexDefinitionDoc != null) {
try {
final String indexDefClassName = config.field(OIndexInternal.INDEX_DEFINITION_CLASS);
final Class<?> indexDefClass = Class.forName(indexDefClassName);
loadedIndexDefinition = (OIndexDefinition) indexDefClass.getDeclaredConstructor().newInstance();
loadedIndexDefinition.fromStream(indexDefinitionDoc);
} catch (final ClassNotFoundException e) {
throw OException.wrapException(new OIndexException("Error during deserialization of index definition"), e);
} catch (final NoSuchMethodException e) {
throw OException.wrapException(new OIndexException("Error during deserialization of index definition"), e);
} catch (final InvocationTargetException e) {
throw OException.wrapException(new OIndexException("Error during deserialization of index definition"), e);
} catch (final InstantiationException e) {
throw OException.wrapException(new OIndexException("Error during deserialization of index definition"), e);
} catch (final IllegalAccessException e) {
throw OException.wrapException(new OIndexException("Error during deserialization of index definition"), e);
}
} else {
// @COMPATIBILITY 1.0rc6 new index model was implemented
final Boolean isAutomatic = config.field(OIndexInternal.CONFIG_AUTOMATIC);
OIndexFactory factory = OIndexes.getFactory(type, algorithm);
if (Boolean.TRUE.equals(isAutomatic)) {
final int pos = indexName.lastIndexOf('.');
if (pos < 0)
throw new OIndexException("Cannot convert from old index model to new one. " + "Invalid index name. Dot (.) separator should be present");
final String className = indexName.substring(0, pos);
final String propertyName = indexName.substring(pos + 1);
final String keyTypeStr = config.field(OIndexInternal.CONFIG_KEYTYPE);
if (keyTypeStr == null)
throw new OIndexException("Cannot convert from old index model to new one. " + "Index key type is absent");
final OType keyType = OType.valueOf(keyTypeStr.toUpperCase(Locale.ENGLISH));
loadedIndexDefinition = new OPropertyIndexDefinition(className, propertyName, keyType);
config.removeField(OIndexInternal.CONFIG_AUTOMATIC);
config.removeField(OIndexInternal.CONFIG_KEYTYPE);
} else if (config.field(OIndexInternal.CONFIG_KEYTYPE) != null) {
final String keyTypeStr = config.field(OIndexInternal.CONFIG_KEYTYPE);
final OType keyType = OType.valueOf(keyTypeStr.toUpperCase(Locale.ENGLISH));
loadedIndexDefinition = new OSimpleKeyIndexDefinition(factory.getLastVersion(), keyType);
config.removeField(OIndexInternal.CONFIG_KEYTYPE);
}
}
final Set<String> clusters = new HashSet<String>((Collection<String>) config.field(CONFIG_CLUSTERS, OType.EMBEDDEDSET));
return new OIndexMetadata(indexName, loadedIndexDefinition, clusters, type, algorithm, valueContainerAlgorithm);
}
Aggregations