start embedded orientdb server if no configuration is available

This commit is contained in:
Sebastian Sdorra
2012-03-18 17:08:50 +01:00
parent 4c504adeab
commit 6127aa1f7a
3 changed files with 113 additions and 6 deletions

View File

@@ -36,6 +36,18 @@
<version>1.0rc8</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-server</artifactId>
<version>1.0rc8</version>
<exclusions>
<exclusion>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- test -->
<dependency>

View File

@@ -33,18 +33,27 @@ package sonia.scm.orientdb;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Resources;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.server.OServer;
import com.orientechnologies.orient.server.OServerMain;
import com.orientechnologies.orient.server.config.OServerConfiguration;
import sonia.scm.ConfigurationException;
import sonia.scm.SCMContext;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.net.URL;
import java.nio.charset.Charset;
import javax.xml.bind.JAXB;
/**
@@ -67,6 +76,10 @@ public class ConnectionProvider implements Provider<ODatabaseDocumentTx>
/** Field description */
public static final String DEFAULT_USERNAME = "admin";
/** Field description */
public static final String EMBEDDED_CONFIGURATION =
"sonia/scm/orientdb/server-configuration.xml";
/** Field description */
public static final String PATH =
"config".concat(File.separator).concat("orientdb.xml");
@@ -87,14 +100,44 @@ public class ConnectionProvider implements Provider<ODatabaseDocumentTx>
}
else
{
try
{
// create default connection configuration
File directory = new File(SCMContext.getContext().getBaseDirectory(),
DEFAULT_DB_DIRECTORY);
String url = DEFAULT_DB_SHEME.concat(directory.getAbsolutePath());
// create connection configuration for embedded server
File directory = new File(SCMContext.getContext().getBaseDirectory(),
DEFAULT_DB_DIRECTORY);
OServer server = OServerMain.create();
URL configUrl = Resources.getResource(EMBEDDED_CONFIGURATION);
String config = Resources.toString(configUrl, Charset.defaultCharset());
init(new ConnectionConfiguration(url, DEFAULT_USERNAME,
DEFAULT_PASSWORD));
server.startup(config);
server.activate();
String url = DEFAULT_DB_SHEME.concat(directory.getAbsolutePath());
if (!directory.exists())
{
ODatabaseDocumentTx connection = null;
try
{
connection = new ODatabaseDocumentTx(url);
connection.create();
}
finally
{
OrientDBUtil.close(connection);
}
}
init(new ConnectionConfiguration(url, DEFAULT_USERNAME,
DEFAULT_PASSWORD));
}
catch (Exception ex)
{
throw new ConfigurationException("could not start embedded database",
ex);
}
}
}

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--*
Copyright (c) 2010, Sebastian Sdorra
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of SCM-Manager; nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
http://bitbucket.org/sdorra/scm-manager
-->
<orient-server>
<network>
<protocols />
<listeners />
</network>
<users>
<user name="root" password="3CE6B7C8457D522B21E662C0F2CEC9428A3D8FCFB7BC2E45EBCD8F1CA19E39F3" resources="*"/>
<user name="guest" password="guest" resources="connect,server.listDatabases"/>
<user name="replicator" password="0E382D82060FB027777D7135C90F43F99C2DEDB66DED9177DE84DA9BDA421243" resources="connect,database.passthrough"/>
</users>
<properties>
<entry name="server.cache.file.static" value="false"/>
<entry name="log.console.level" value="info"/>
<entry name="log.file.level" value="fine"/>
</properties>
</orient-server>