use of com.orientechnologies.orient.core.config.OGlobalConfiguration 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.config.OGlobalConfiguration in project orientdb by orientechnologies.
the class OServerInfo method getGlobalProperties.
public static void getGlobalProperties(final OServer server, final OJSONWriter json) throws IOException {
json.beginCollection(2, true, "globalProperties");
for (OGlobalConfiguration c : OGlobalConfiguration.values()) {
json.beginObject(3, true, null);
json.writeAttribute(4, false, "key", c.getKey());
json.writeAttribute(4, false, "description", c.getDescription());
json.writeAttribute(4, false, "value", c.isHidden() ? "<hidden>" : c.getValue());
json.writeAttribute(4, false, "defaultValue", c.getDefValue());
json.writeAttribute(4, false, "canChange", c.isChangeableAtRuntime());
json.endObject(3, true);
}
json.endCollection(2, true);
}
use of com.orientechnologies.orient.core.config.OGlobalConfiguration in project orientdb by orientechnologies.
the class OServerConfigurationLoaderXml method load.
public OServerConfiguration load() throws IOException {
try {
if (file != null) {
fileLastModified = file.lastModified();
String path = OFileUtils.getPath(file.getAbsolutePath());
String current = OFileUtils.getPath(new File("").getAbsolutePath());
if (path.startsWith(current))
path = path.substring(current.length() + 1);
OLogManager.instance().info(this, "Loading configuration from: %s...", path);
} else {
OLogManager.instance().info(this, "Loading configuration from input stream");
}
context = JAXBContext.newInstance(rootClass);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(null);
final OServerConfiguration obj;
if (file != null) {
if (file.exists())
obj = rootClass.cast(unmarshaller.unmarshal(file));
else {
OLogManager.instance().error(this, "Server configuration file not found: %s", file);
return rootClass.getConstructor(OServerConfigurationLoaderXml.class).newInstance(this);
}
obj.location = file.getAbsolutePath();
} else {
obj = rootClass.cast(unmarshaller.unmarshal(inputStream));
obj.location = "memory";
}
// AUTO CONFIGURE SYSTEM CONFIGURATION
OGlobalConfiguration config;
if (obj.properties != null)
for (OServerEntryConfiguration prop : obj.properties) {
try {
config = OGlobalConfiguration.findByKey(prop.name);
if (config != null) {
config.setValue(prop.value);
}
} catch (Exception e) {
}
}
return obj;
} catch (Exception e) {
// SYNTAX ERROR? PRINT AN EXAMPLE
OLogManager.instance().error(this, "Invalid syntax. Below an example of how it should be:", e);
try {
context = JAXBContext.newInstance(rootClass);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Object example = rootClass.getConstructor(OServerConfigurationLoaderXml.class).newInstance(this);
marshaller.marshal(example, System.out);
} catch (Exception ex) {
}
throw new IOException(e);
}
}
use of com.orientechnologies.orient.core.config.OGlobalConfiguration in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method config.
@ConsoleCommand(description = "Return all the configuration values")
public void config() throws IOException {
if (serverAdmin != null) {
// REMOTE STORAGE
final Map<String, String> values = serverAdmin.getGlobalConfigurations();
message("\nREMOTE SERVER CONFIGURATION");
final List<ODocument> resultSet = new ArrayList<ODocument>();
for (Entry<String, String> p : values.entrySet()) {
final ODocument row = new ODocument();
resultSet.add(row);
row.field("NAME", p.getKey());
row.field("VALUE", p.getValue());
}
final OTableFormatter formatter = new OTableFormatter(this);
formatter.writeRecords(resultSet, -1);
} else {
// LOCAL STORAGE
message("\nLOCAL SERVER CONFIGURATION");
final List<ODocument> resultSet = new ArrayList<ODocument>();
for (OGlobalConfiguration cfg : OGlobalConfiguration.values()) {
final ODocument row = new ODocument();
resultSet.add(row);
row.field("NAME", cfg.getKey());
row.field("VALUE", cfg.getValue());
}
final OTableFormatter formatter = new OTableFormatter(this);
formatter.writeRecords(resultSet, -1);
}
message("\n");
}
use of com.orientechnologies.orient.core.config.OGlobalConfiguration in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method configGet.
@ConsoleCommand(description = "Return the value of a configuration value")
public void configGet(@ConsoleParameter(name = "config-name", description = "Name of the configuration") final String iConfigName) throws IOException {
final OGlobalConfiguration config = OGlobalConfiguration.findByKey(iConfigName);
if (config == null)
throw new IllegalArgumentException("Configuration variable '" + iConfigName + "' wasn't found");
final String value;
if (serverAdmin != null) {
value = serverAdmin.getGlobalConfiguration(config);
message("\nRemote configuration: ");
} else {
value = config.getValueAsString();
message("\nLocal configuration: ");
}
out.println(iConfigName + " = " + value);
}
Aggregations