use of com.orientechnologies.orient.core.cache.OCommandCacheHook in project orientdb by orientechnologies.
the class ODatabaseDocumentTx method create.
@Override
public <DB extends ODatabase> DB create(final Map<OGlobalConfiguration, Object> iInitialSettings) {
setupThreadOwner();
activateOnCurrentThread();
try {
if (status == STATUS.OPEN)
throw new IllegalStateException("Database " + getName() + " is already open");
if (storage == null)
storage = Orient.instance().loadStorage(url);
final OContextConfiguration ctxCfg = storage.getConfiguration().getContextConfiguration();
if (iInitialSettings != null && !iInitialSettings.isEmpty()) {
// SETUP INITIAL SETTINGS
for (Map.Entry<OGlobalConfiguration, Object> e : iInitialSettings.entrySet()) {
ctxCfg.setValue(e.getKey(), e.getValue());
}
storage.getConfiguration().update();
}
storage.create(properties);
status = STATUS.OPEN;
componentsFactory = getStorage().getComponentsFactory();
localCache.startup();
getStorage().getConfiguration().setRecordSerializer(getSerializer().toString());
getStorage().getConfiguration().setRecordSerializerVersion(getSerializer().getCurrentVersion());
// since 2.1 newly created databases use strict SQL validation by default
getStorage().getConfiguration().setProperty(OStatement.CUSTOM_STRICT_SQL, "true");
getStorage().getConfiguration().update();
// THIS IF SHOULDN'T BE NEEDED, CREATE HAPPEN ONLY IN EMBEDDED
if (!(getStorage() instanceof OStorageProxy))
installHooksEmbedded();
// CREATE THE DEFAULT SCHEMA WITH DEFAULT USER
metadata = new OMetadataDefault(this);
metadata.create();
if (!(getStorage() instanceof OStorageProxy))
registerHook(new OCommandCacheHook(this), ORecordHook.HOOK_POSITION.REGULAR);
registerHook(new OSecurityTrackerHook(metadata.getSecurity(), this), ORecordHook.HOOK_POSITION.LAST);
final OUser usr = getMetadata().getSecurity().getUser(OUser.ADMIN);
if (usr == null)
user = null;
else
user = new OImmutableUser(getMetadata().getSecurity().getVersion(), usr);
// WAKE UP DB LIFECYCLE LISTENER
for (Iterator<ODatabaseLifecycleListener> it = Orient.instance().getDbLifecycleListeners(); it.hasNext(); ) it.next().onCreate(getDatabaseOwner());
// WAKE UP LISTENERS
for (ODatabaseListener listener : browseListeners()) try {
listener.onCreate(this);
} catch (Throwable ignore) {
}
} catch (Exception e) {
// REMOVE THE (PARTIAL) DATABASE
try {
drop();
} catch (Exception ex) {
// IGNORE IT
}
// DELETE THE STORAGE TOO
try {
if (storage == null)
storage = Orient.instance().loadStorage(url);
storage.delete();
} catch (Exception ex) {
// IGNORE IT
}
status = STATUS.CLOSED;
owner.set(null);
throw OException.wrapException(new ODatabaseException("Cannot create database '" + getName() + "'"), e);
}
return (DB) this;
}
use of com.orientechnologies.orient.core.cache.OCommandCacheHook in project orientdb by orientechnologies.
the class ODatabaseDocumentTx method initAtFirstOpen.
private void initAtFirstOpen(String iUserName, String iUserPassword) {
if (initialized)
return;
ORecordSerializerFactory serializerFactory = ORecordSerializerFactory.instance();
String serializeName = getStorage().getConfiguration().getRecordSerializer();
if (serializeName == null) {
throw new ODatabaseException("Database created with orientdb version not supported anymore, use export+import to migrate the database");
}
serializer = serializerFactory.getFormat(serializeName);
if (serializer == null)
throw new ODatabaseException("RecordSerializer with name '" + serializeName + "' not found ");
if (getStorage().getConfiguration().getRecordSerializerVersion() > serializer.getMinSupportedVersion())
throw new ODatabaseException("Persistent record serializer version is not support by the current implementation");
componentsFactory = getStorage().getComponentsFactory();
localCache.startup();
user = null;
metadata = new OMetadataDefault(this);
metadata.load();
recordFormat = DEF_RECORD_FORMAT;
if (!(getStorage() instanceof OStorageProxy)) {
if (metadata.getIndexManager().autoRecreateIndexesAfterCrash()) {
metadata.getIndexManager().recreateIndexes();
activateOnCurrentThread();
user = null;
}
installHooksEmbedded();
registerHook(new OCommandCacheHook(this), ORecordHook.HOOK_POSITION.REGULAR);
registerHook(new OSecurityTrackerHook(metadata.getSecurity(), this), ORecordHook.HOOK_POSITION.LAST);
user = null;
} else if (iUserName != null && iUserPassword != null) {
user = new OImmutableUser(-1, new OUser(iUserName, OUser.encryptPassword(iUserPassword)).addRole(new ORole("passthrough", null, ORole.ALLOW_MODES.ALLOW_ALL_BUT)));
installHooksRemote();
}
initialized = true;
}
Aggregations