use of com.orientechnologies.orient.core.db.ODatabaseInternal in project wicket-orientdb by OrienteerBAP.
the class OrientDbWebApplication method init.
@Override
protected void init() {
super.init();
Orient.instance().registerThreadDatabaseFactory(new DefaultODatabaseThreadLocalFactory(this));
Orient.instance().addDbLifecycleListener(new ODatabaseLifecycleListener() {
private ORecordHook createHook(Class<? extends ORecordHook> clazz, ODatabaseInternal iDatabase) {
if (!(iDatabase instanceof ODatabaseDocument))
return null;
try {
return (ORecordHook) clazz.getConstructor(ODatabaseDocument.class).newInstance(iDatabase);
} catch (Exception e) {
try {
return (ORecordHook) clazz.newInstance();
} catch (Exception e1) {
throw new IllegalStateException("Can't initialize hook " + clazz.getName(), e);
}
}
}
@Override
public void onOpen(ODatabaseInternal iDatabase) {
registerHooks(iDatabase);
}
@Override
public void onCreate(ODatabaseInternal iDatabase) {
registerHooks(iDatabase);
// Fix for "feature" appeared in OrientDB 2.1.1
// Issue: https://github.com/orientechnologies/orientdb/issues/4906
fixOrientDBRights(iDatabase);
}
public void registerHooks(ODatabaseInternal iDatabase) {
Set<ORecordHook> hooks = iDatabase.getHooks().keySet();
List<Class<? extends ORecordHook>> hooksToRegister = new ArrayList<Class<? extends ORecordHook>>(getOrientDbSettings().getORecordHooks());
for (ORecordHook hook : hooks) {
if (hooksToRegister.contains(hook.getClass()))
hooksToRegister.remove(hook.getClass());
}
for (Class<? extends ORecordHook> oRecordHookClass : hooksToRegister) {
ORecordHook hook = createHook(oRecordHookClass, iDatabase);
if (hook != null) {
if (hook instanceof IHookPosition) {
iDatabase.registerHook(hook, ((IHookPosition) hook).getPosition());
} else {
iDatabase.registerHook(hook);
}
}
}
}
@Override
public void onClose(ODatabaseInternal iDatabase) {
/*NOP*/
}
@Override
public void onDrop(ODatabaseInternal iDatabase) {
/*NOP*/
}
public PRIORITY getPriority() {
return PRIORITY.REGULAR;
}
@Override
public void onCreateClass(ODatabaseInternal iDatabase, OClass iClass) {
/*NOP*/
}
@Override
public void onDropClass(ODatabaseInternal iDatabase, OClass iClass) {
/*NOP*/
}
@Override
public void onLocalNodeConfigurationRequest(ODocument arg0) {
/*NOP*/
}
});
getRequestCycleListeners().add(newTransactionRequestCycleListener());
getRequestCycleListeners().add(new OrientDefaultExceptionsHandlingListener());
getSecuritySettings().setAuthorizationStrategy(new WicketOrientDbAuthorizationStrategy(this));
getApplicationListeners().add(new IApplicationListener() {
@Override
public void onAfterInitialized(Application application) {
Orient.instance().startup();
Orient.instance().removeShutdownHook();
}
@Override
public void onBeforeDestroyed(Application application) {
Orient.instance().shutdown();
}
});
getAjaxRequestTargetListeners().add(new FixFormEncTypeListener());
// workaround to support changing system users passwords in web interface
getOrientDbSettings().getORecordHooks().add(OUserCatchPasswordHook.class);
PropertyResolver.setLocator(this, new ODocumentPropertyLocator(new PropertyResolver.CachingPropertyLocator(new PropertyResolver.DefaultPropertyLocator())));
}
use of com.orientechnologies.orient.core.db.ODatabaseInternal 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.db.ODatabaseInternal in project orientdb by orientechnologies.
the class OIndexManagerShared method createIndex.
/**
* Create a new index.
* <p>
* May require quite a long time if big amount of data should be indexed.
*
* @param iName name of index
* @param type index type. Specified by plugged index factories.
* @param indexDefinition metadata that describes index structure
* @param clusterIdsToIndex ids of clusters that index should track for changes.
* @param progressListener listener to track task progress.
* @param metadata document with additional properties that can be used by index engine.
* @param algorithm tip to an index factory what algorithm to use
*
* @return a newly created index instance
*/
public OIndex<?> createIndex(final String iName, String type, final OIndexDefinition indexDefinition, final int[] clusterIdsToIndex, OProgressListener progressListener, ODocument metadata, String algorithm) {
if (getDatabase().getTransaction().isActive())
throw new IllegalStateException("Cannot create a new index inside a transaction");
final Character c = OSchemaShared.checkFieldNameIfValid(iName);
if (c != null)
throw new IllegalArgumentException("Invalid index name '" + iName + "'. Character '" + c + "' is invalid");
ODatabaseInternal database = getDatabase();
OStorage storage = database.getStorage();
final Locale locale = getServerLocale();
type = type.toUpperCase(locale);
if (algorithm == null) {
algorithm = OIndexes.chooseDefaultIndexAlgorithm(type);
}
final String valueContainerAlgorithm = chooseContainerAlgorithm(type);
final OIndexInternal<?> index;
acquireExclusiveLock();
try {
if (indexes.containsKey(iName.toLowerCase(locale)))
throw new OIndexException("Index with name " + iName.toLowerCase(locale) + " already exists.");
// manual indexes are always durable
if (clusterIdsToIndex == null || clusterIdsToIndex.length == 0) {
if (metadata == null)
metadata = new ODocument().setTrackingChanges(false);
final Object durable = metadata.field("durableInNonTxMode");
if (!(durable instanceof Boolean))
metadata.field("durableInNonTxMode", true);
if (metadata.field("trackMode") == null)
metadata.field("trackMode", "FULL");
}
index = OIndexes.createIndex(getDatabase(), iName, type, algorithm, valueContainerAlgorithm, metadata, -1);
if (progressListener == null)
// ASSIGN DEFAULT PROGRESS LISTENER
progressListener = new OIndexRebuildOutputListener(index);
final Set<String> clustersToIndex = findClustersByIds(clusterIdsToIndex, database);
if (indexDefinition != null) {
Object ignoreNullValues = metadata == null ? null : metadata.field("ignoreNullValues");
if (Boolean.TRUE.equals(ignoreNullValues)) {
indexDefinition.setNullValuesIgnored(true);
} else if (Boolean.FALSE.equals(ignoreNullValues)) {
indexDefinition.setNullValuesIgnored(false);
} else {
indexDefinition.setNullValuesIgnored(OGlobalConfiguration.INDEX_IGNORE_NULL_VALUES_DEFAULT.getValueAsBoolean());
}
}
// decide which cluster to use ("index" - for automatic and "manindex" for manual)
final String clusterName = indexDefinition != null && indexDefinition.getClassName() != null ? defaultClusterName : manualClusterName;
index.create(iName, indexDefinition, clusterName, clustersToIndex, true, progressListener);
addIndexInternal(index);
if (metadata != null) {
final ODocument config = index.getConfiguration();
config.field("metadata", metadata, OType.EMBEDDED);
}
setDirty();
save();
} finally {
releaseExclusiveLock();
}
notifyInvolvedClasses(clusterIdsToIndex);
if (OGlobalConfiguration.INDEX_FLUSH_AFTER_CREATE.getValueAsBoolean())
storage.synch();
return preProcessBeforeReturn(index);
}
use of com.orientechnologies.orient.core.db.ODatabaseInternal in project orientdb by orientechnologies.
the class OClassImpl method fireDatabaseMigration.
public void fireDatabaseMigration(final ODatabaseDocument database, final String propertyName, 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) + ".type() <> \"" + type.name() + "\"", new OCommandResultListener() {
@Override
public boolean result(Object iRecord) {
final ODocument record = ((OIdentifiable) iRecord).getRecord();
record.field(propertyName, record.field(propertyName), type);
database.save(record);
return true;
}
@Override
public void end() {
}
@Override
public Object getResult() {
return null;
}
}));
}
Aggregations