mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
removed experimental scm-dao-orientdb module, should be later implemented as plugin
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -70,7 +70,6 @@
|
|||||||
<module>scm-plugins</module>
|
<module>scm-plugins</module>
|
||||||
<module>scm-samples</module>
|
<module>scm-samples</module>
|
||||||
<module>scm-dao-xml</module>
|
<module>scm-dao-xml</module>
|
||||||
<module>scm-dao-orientdb</module>
|
|
||||||
<module>scm-webapp</module>
|
<module>scm-webapp</module>
|
||||||
<module>scm-server</module>
|
<module>scm-server</module>
|
||||||
<module>scm-plugin-backend</module>
|
<module>scm-plugin-backend</module>
|
||||||
|
|||||||
@@ -1,78 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>sonia.scm</groupId>
|
|
||||||
<artifactId>scm</artifactId>
|
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<groupId>sonia.scm</groupId>
|
|
||||||
<artifactId>scm-dao-orientdb</artifactId>
|
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
|
||||||
<name>scm-dao-orientdb</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>servlet-api</artifactId>
|
|
||||||
<version>${servlet.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>sonia.scm</groupId>
|
|
||||||
<artifactId>scm-core</artifactId>
|
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.orientechnologies</groupId>
|
|
||||||
<artifactId>orientdb-client</artifactId>
|
|
||||||
<version>${orientdb.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.orientechnologies</groupId>
|
|
||||||
<artifactId>orientdb-server</artifactId>
|
|
||||||
<version>${orientdb.version}</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.orientechnologies</groupId>
|
|
||||||
<artifactId>orientdb-client</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- test -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>sonia.scm</groupId>
|
|
||||||
<artifactId>scm-test</artifactId>
|
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<orientdb.version>1.1.0</orientdb.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
|
|
||||||
<repository>
|
|
||||||
<id>orientechnologies-repository</id>
|
|
||||||
<name>Orient Technologies Maven2 Repository</name>
|
|
||||||
<url>http://www.orientechnologies.com/listing/m2</url>
|
|
||||||
<releases>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</releases>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.group.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass.INDEX_TYPE;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OType;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
|
|
||||||
import sonia.scm.group.Group;
|
|
||||||
import sonia.scm.orientdb.AbstractConverter;
|
|
||||||
import sonia.scm.orientdb.Converter;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class GroupConverter extends AbstractConverter
|
|
||||||
implements Converter<Group>
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String DOCUMENT_CLASS = "Group";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_CREATIONDATE = "creationDate";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_DESCRIPTION = "description";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_MEMBERS = "members";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String INDEX_ID = "groupId";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final GroupConverter INSTANCE = new GroupConverter();
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param group
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ODocument convert(Group group)
|
|
||||||
{
|
|
||||||
ODocument doc = new ODocument(DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
return convert(doc, group);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param group
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ODocument convert(ODocument doc, Group group)
|
|
||||||
{
|
|
||||||
appendModelObjectFields(doc, group);
|
|
||||||
appendField(doc, FIELD_DESCRIPTION, group.getDescription());
|
|
||||||
appendField(doc, FIELD_CREATIONDATE, group.getCreationDate(), OType.LONG);
|
|
||||||
appendField(doc, FIELD_MEMBERS, group.getMembers(), OType.EMBEDDEDLIST);
|
|
||||||
appendPropertiesField(doc, group);
|
|
||||||
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Group convert(ODocument doc)
|
|
||||||
{
|
|
||||||
Group group = new Group();
|
|
||||||
|
|
||||||
group.setName(getStringField(doc, FIELD_ID));
|
|
||||||
group.setDescription(getStringField(doc, FIELD_DESCRIPTION));
|
|
||||||
group.setType(getStringField(doc, FIELD_TYPE));
|
|
||||||
group.setCreationDate(getLongField(doc, FIELD_CREATIONDATE));
|
|
||||||
group.setLastModified(getLongField(doc, FIELD_LASTMODIFIED));
|
|
||||||
|
|
||||||
Map<String, String> properties = doc.field(FIELD_PROPERTIES);
|
|
||||||
|
|
||||||
group.setProperties(properties);
|
|
||||||
|
|
||||||
List<String> members = doc.field(FIELD_MEMBERS);
|
|
||||||
|
|
||||||
group.setMembers(members);
|
|
||||||
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void createShema(ODatabaseDocumentTx connection)
|
|
||||||
{
|
|
||||||
OSchema schema = connection.getMetadata().getSchema();
|
|
||||||
OClass oclass = schema.getClass(DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
if (oclass == null)
|
|
||||||
{
|
|
||||||
oclass = schema.createClass(DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
// model properites
|
|
||||||
oclass.createProperty(FIELD_ID, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_TYPE, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_LASTMODIFIED, OType.LONG);
|
|
||||||
|
|
||||||
// user properties
|
|
||||||
oclass.createProperty(FIELD_DESCRIPTION, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_CREATIONDATE, OType.LONG);
|
|
||||||
oclass.createProperty(FIELD_MEMBERS, OType.EMBEDDEDLIST);
|
|
||||||
oclass.createProperty(FIELD_PROPERTIES, OType.EMBEDDEDMAP);
|
|
||||||
|
|
||||||
// indexes
|
|
||||||
oclass.createIndex(INDEX_ID, INDEX_TYPE.UNIQUE, FIELD_ID);
|
|
||||||
schema.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.group.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
|
|
||||||
import sonia.scm.group.Group;
|
|
||||||
import sonia.scm.group.GroupDAO;
|
|
||||||
import sonia.scm.orientdb.AbstractOrientDBModelDAO;
|
|
||||||
import sonia.scm.orientdb.OrientDBUtil;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class OrientDBGroupDAO extends AbstractOrientDBModelDAO<Group>
|
|
||||||
implements GroupDAO
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String QUERY_ALL = "select from Group";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String QUERY_SINGLE_BYID =
|
|
||||||
"select from Group where id = ?";
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connectionProvider
|
|
||||||
*/
|
|
||||||
@Inject
|
|
||||||
public OrientDBGroupDAO(Provider<ODatabaseDocumentTx> connectionProvider)
|
|
||||||
{
|
|
||||||
super(connectionProvider, GroupConverter.INSTANCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected List<ODocument> getAllDocuments(ODatabaseDocumentTx connection)
|
|
||||||
{
|
|
||||||
return OrientDBUtil.executeListResultQuery(connection, QUERY_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
* @param id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected ODocument getDocument(ODatabaseDocumentTx connection, String id)
|
|
||||||
{
|
|
||||||
return OrientDBUtil.executeSingleResultQuery(connection, QUERY_SINGLE_BYID,
|
|
||||||
id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OType;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
|
|
||||||
import sonia.scm.ModelObject;
|
|
||||||
import sonia.scm.PropertiesAware;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public abstract class AbstractConverter
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_ID = "id";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_LASTMODIFIED = "lastModified";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_PROPERTIES = "properties";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_TYPE = "type";
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param name
|
|
||||||
* @param value
|
|
||||||
*/
|
|
||||||
protected void appendField(ODocument doc, String name, Object value)
|
|
||||||
{
|
|
||||||
appendField(doc, name, value, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param name
|
|
||||||
* @param value
|
|
||||||
* @param type
|
|
||||||
*/
|
|
||||||
protected void appendField(ODocument doc, String name, Object value,
|
|
||||||
OType type)
|
|
||||||
{
|
|
||||||
if (value != null)
|
|
||||||
{
|
|
||||||
if (type != null)
|
|
||||||
{
|
|
||||||
doc.field(name, value, type);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
doc.field(name, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (doc.containsField(name))
|
|
||||||
{
|
|
||||||
doc.removeField(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param name
|
|
||||||
* @param converter
|
|
||||||
* @param list
|
|
||||||
* @param <T>
|
|
||||||
*/
|
|
||||||
protected <T> void appendListField(ODocument doc, String name,
|
|
||||||
Converter<T> converter, List<T> list)
|
|
||||||
{
|
|
||||||
List<ODocument> docs = OrientDBUtil.transformToDocuments(converter, list);
|
|
||||||
|
|
||||||
appendField(doc, name, docs, OType.EMBEDDEDLIST);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param model
|
|
||||||
*/
|
|
||||||
protected void appendModelObjectFields(ODocument doc, ModelObject model)
|
|
||||||
{
|
|
||||||
appendField(doc, FIELD_ID, model.getId());
|
|
||||||
appendField(doc, FIELD_TYPE, model.getType());
|
|
||||||
appendField(doc, FIELD_LASTMODIFIED, model.getLastModified(), OType.LONG);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param object
|
|
||||||
*/
|
|
||||||
protected void appendPropertiesField(ODocument doc, PropertiesAware object)
|
|
||||||
{
|
|
||||||
appendField(doc, FIELD_PROPERTIES, object.getProperties(),
|
|
||||||
OType.EMBEDDEDMAP);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param name
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected Boolean getBooleanField(ODocument doc, String name)
|
|
||||||
{
|
|
||||||
return doc.field(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param name
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected Long getLongField(ODocument doc, String name)
|
|
||||||
{
|
|
||||||
return doc.field(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param name
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected String getStringField(ODocument doc, String name)
|
|
||||||
{
|
|
||||||
return doc.field(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,366 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import sonia.scm.GenericDAO;
|
|
||||||
import sonia.scm.ModelObject;
|
|
||||||
import sonia.scm.util.Util;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
*/
|
|
||||||
public abstract class AbstractOrientDBModelDAO<T extends ModelObject>
|
|
||||||
implements GenericDAO<T>
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String TYPE = "orientdb";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the logger for AbstractOrientDBModelDAO
|
|
||||||
*/
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(AbstractOrientDBModelDAO.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connectionProvider
|
|
||||||
* @param converter
|
|
||||||
*/
|
|
||||||
public AbstractOrientDBModelDAO(
|
|
||||||
Provider<ODatabaseDocumentTx> connectionProvider,
|
|
||||||
Converter<T> converter)
|
|
||||||
{
|
|
||||||
this.connectionProvider = connectionProvider;
|
|
||||||
this.converter = converter;
|
|
||||||
createShema();
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected abstract List<ODocument> getAllDocuments(
|
|
||||||
ODatabaseDocumentTx connection);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
* @param id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected abstract ODocument getDocument(ODatabaseDocumentTx connection,
|
|
||||||
String id);
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void add(T item)
|
|
||||||
{
|
|
||||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ODocument doc = converter.convert(item);
|
|
||||||
|
|
||||||
doc.save();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
OrientDBUtil.close(connection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param item
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean contains(T item)
|
|
||||||
{
|
|
||||||
return contains(item.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean contains(String id)
|
|
||||||
{
|
|
||||||
return get(id) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void delete(T item)
|
|
||||||
{
|
|
||||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ODocument doc = getDocument(connection, item.getId());
|
|
||||||
|
|
||||||
if (doc != null)
|
|
||||||
{
|
|
||||||
doc.delete();
|
|
||||||
}
|
|
||||||
else if (logger.isErrorEnabled())
|
|
||||||
{
|
|
||||||
logger.error("could not find document for delete");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
OrientDBUtil.close(connection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void modify(T item)
|
|
||||||
{
|
|
||||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ODocument doc = getDocument(connection, item.getId());
|
|
||||||
|
|
||||||
if (doc != null)
|
|
||||||
{
|
|
||||||
doc = converter.convert(doc, item);
|
|
||||||
doc.save();
|
|
||||||
}
|
|
||||||
else if (logger.isErrorEnabled())
|
|
||||||
{
|
|
||||||
logger.error("could not find document for modify");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
OrientDBUtil.close(connection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public T get(String id)
|
|
||||||
{
|
|
||||||
T item = null;
|
|
||||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ODocument doc = getDocument(connection, id);
|
|
||||||
|
|
||||||
if (doc != null)
|
|
||||||
{
|
|
||||||
item = converter.convert(doc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
OrientDBUtil.close(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<T> getAll()
|
|
||||||
{
|
|
||||||
List<T> items = null;
|
|
||||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
List<ODocument> result = getAllDocuments(connection);
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(result))
|
|
||||||
{
|
|
||||||
items = OrientDBUtil.transformToItems(converter, result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
items = Lists.newArrayList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
OrientDBUtil.close(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Long getCreationTime()
|
|
||||||
{
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
return System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Long getLastModified()
|
|
||||||
{
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
return System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getType()
|
|
||||||
{
|
|
||||||
return TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void createShema()
|
|
||||||
{
|
|
||||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
converter.createShema(connection);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
OrientDBUtil.close(connection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
protected Provider<ODatabaseDocumentTx> connectionProvider;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
protected Converter<T> converter;
|
|
||||||
}
|
|
||||||
@@ -1,281 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
|
||||||
@XmlRootElement(name = "connection-configuration")
|
|
||||||
public class ConnectionConfiguration
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public ConnectionConfiguration() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param url
|
|
||||||
* @param username
|
|
||||||
* @param password
|
|
||||||
*/
|
|
||||||
public ConnectionConfiguration(String url, String username, String password)
|
|
||||||
{
|
|
||||||
this.url = url;
|
|
||||||
this.username = username;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param obj
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj)
|
|
||||||
{
|
|
||||||
if (obj == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final ConnectionConfiguration other = (ConnectionConfiguration) obj;
|
|
||||||
|
|
||||||
//J-
|
|
||||||
return Objects.equal(url, other.url)
|
|
||||||
&& Objects.equal(username, other.username)
|
|
||||||
&& Objects.equal(password, other.password)
|
|
||||||
&& Objects.equal(minPoolSize, other.minPoolSize)
|
|
||||||
&& Objects.equal(maxPoolSize, other.maxPoolSize);
|
|
||||||
//J+
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return Objects.hashCode(url, username, password, minPoolSize, maxPoolSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
String pwd = null;
|
|
||||||
|
|
||||||
if (password != null)
|
|
||||||
{
|
|
||||||
pwd = "xxx";
|
|
||||||
}
|
|
||||||
|
|
||||||
//J-
|
|
||||||
return Objects.toStringHelper(this)
|
|
||||||
.add("url", url)
|
|
||||||
.add("username", username)
|
|
||||||
.add("password", pwd)
|
|
||||||
.add("minPoolSize", minPoolSize)
|
|
||||||
.add("maxPoolSize", maxPoolSize)
|
|
||||||
.toString();
|
|
||||||
//J+
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public int getMaxPoolSize()
|
|
||||||
{
|
|
||||||
return maxPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public int getMinPoolSize()
|
|
||||||
{
|
|
||||||
return minPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getPassword()
|
|
||||||
{
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getUrl()
|
|
||||||
{
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getUsername()
|
|
||||||
{
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param maxPoolSize
|
|
||||||
*/
|
|
||||||
public void setMaxPoolSize(int maxPoolSize)
|
|
||||||
{
|
|
||||||
this.maxPoolSize = maxPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param minPoolSize
|
|
||||||
*/
|
|
||||||
public void setMinPoolSize(int minPoolSize)
|
|
||||||
{
|
|
||||||
this.minPoolSize = minPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param password
|
|
||||||
*/
|
|
||||||
public void setPassword(String password)
|
|
||||||
{
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param url
|
|
||||||
*/
|
|
||||||
public void setUrl(String url)
|
|
||||||
{
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param username
|
|
||||||
*/
|
|
||||||
public void setUsername(String username)
|
|
||||||
{
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
@XmlElement(name = "max-pool-size")
|
|
||||||
private int maxPoolSize = 10;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
@XmlElement(name = "min-pool-size")
|
|
||||||
private int minPoolSize = 2;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private String url;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private String username;
|
|
||||||
}
|
|
||||||
@@ -1,295 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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.config.OGlobalConfiguration;
|
|
||||||
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 org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import sonia.scm.ConfigurationException;
|
|
||||||
import sonia.scm.SCMContext;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXB;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class ConnectionProvider
|
|
||||||
implements Provider<ODatabaseDocumentTx>, Closeable
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String DEFAULT_DB_DIRECTORY = "db";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String DEFAULT_DB_SHEME = "local:";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String DEFAULT_PASSWORD = "admin";
|
|
||||||
|
|
||||||
/** 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 CONFIG_PATH_SERVER =
|
|
||||||
"config".concat(File.separator).concat("orientdb-server.xml");
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String CONFIG_PATH_CLIENT =
|
|
||||||
"config".concat(File.separator).concat("orientdb-client.xml");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the logger for ConnectionProvider
|
|
||||||
*/
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(ConnectionProvider.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public ConnectionProvider()
|
|
||||||
{
|
|
||||||
File file = new File(SCMContext.getContext().getBaseDirectory(),
|
|
||||||
CONFIG_PATH_CLIENT);
|
|
||||||
|
|
||||||
if (file.exists())
|
|
||||||
{
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("read database configuration from file {}", file);
|
|
||||||
}
|
|
||||||
|
|
||||||
init(JAXB.unmarshal(file, ConnectionConfiguration.class));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File baseDirectory = SCMContext.getContext().getBaseDirectory();
|
|
||||||
|
|
||||||
// create connection configuration for embedded server
|
|
||||||
File directory = new File(baseDirectory, DEFAULT_DB_DIRECTORY);
|
|
||||||
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("create configuration for embedded database at {}",
|
|
||||||
directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set oritentdb tuning option
|
|
||||||
* https://groups.google.com/forum/#!msg/orient-database/DrJ3zPY3oao/RQQayirg4mYJ
|
|
||||||
*/
|
|
||||||
OGlobalConfiguration.STORAGE_KEEP_OPEN.setValue(Boolean.FALSE);
|
|
||||||
OGlobalConfiguration.MVRBTREE_LAZY_UPDATES.setValue(1);
|
|
||||||
server = OServerMain.create();
|
|
||||||
|
|
||||||
URL configUrl = null;
|
|
||||||
File serverConfiguration = new File(baseDirectory, CONFIG_PATH_SERVER);
|
|
||||||
|
|
||||||
if (serverConfiguration.exists())
|
|
||||||
{
|
|
||||||
configUrl = serverConfiguration.toURI().toURL();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
configUrl = Resources.getResource(EMBEDDED_CONFIGURATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("load orientdb server configuration from {}", configUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
String config = Resources.toString(configUrl, Charset.defaultCharset());
|
|
||||||
|
|
||||||
server.startup(config);
|
|
||||||
server.activate();
|
|
||||||
|
|
||||||
String url = DEFAULT_DB_SHEME.concat(directory.getAbsolutePath());
|
|
||||||
|
|
||||||
if (!directory.exists())
|
|
||||||
{
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("create new database at {}", directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param configuration
|
|
||||||
*/
|
|
||||||
public ConnectionProvider(ConnectionConfiguration configuration)
|
|
||||||
{
|
|
||||||
init(configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void close()
|
|
||||||
{
|
|
||||||
if (connectionPool != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connectionPool.close();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.error("could not close connection pool", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (server != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
server.shutdown();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.error("shutdown of orientdb server failed", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ODatabaseDocumentTx get()
|
|
||||||
{
|
|
||||||
if (logger.isTraceEnabled())
|
|
||||||
{
|
|
||||||
logger.trace("acquire new connection for database {}",
|
|
||||||
configuration.getUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
return connectionPool.acquire(configuration.getUrl(),
|
|
||||||
configuration.getUsername(),
|
|
||||||
configuration.getPassword());
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param configuration
|
|
||||||
*/
|
|
||||||
private void init(ConnectionConfiguration configuration)
|
|
||||||
{
|
|
||||||
this.configuration = configuration;
|
|
||||||
this.connectionPool = new ODatabaseDocumentPool();
|
|
||||||
this.connectionPool.setup(configuration.getMinPoolSize(),
|
|
||||||
configuration.getMaxPoolSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private ConnectionConfiguration configuration;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private ODatabaseDocumentPool connectionPool;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private OServer server;
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
*/
|
|
||||||
public interface Converter<T>
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param item
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ODocument convert(T item);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param item
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ODocument convert(ODocument doc, T item);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public T convert(ODocument doc);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*/
|
|
||||||
public void createShema(ODatabaseDocumentTx connection);
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.multibindings.Multibinder;
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import javax.servlet.ServletContextListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class OrientDBModule extends AbstractModule
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void configure()
|
|
||||||
{
|
|
||||||
bind(ODatabaseDocumentTx.class).toProvider(ConnectionProvider.class);
|
|
||||||
|
|
||||||
Multibinder<ServletContextListener> servletContextListenerBinder =
|
|
||||||
Multibinder.newSetBinder(binder(), ServletContextListener.class);
|
|
||||||
|
|
||||||
servletContextListenerBinder.addBinding().to(
|
|
||||||
OrientDBServletContextListener.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import javax.servlet.ServletContextEvent;
|
|
||||||
import javax.servlet.ServletContextListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class OrientDBServletContextListener implements ServletContextListener
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the logger for OrientDBServletContextListener
|
|
||||||
*/
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(OrientDBServletContextListener.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connectionProvider
|
|
||||||
*/
|
|
||||||
@Inject
|
|
||||||
public OrientDBServletContextListener(ConnectionProvider connectionProvider)
|
|
||||||
{
|
|
||||||
this.connectionProvider = connectionProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param sce
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void contextDestroyed(ServletContextEvent sce)
|
|
||||||
{
|
|
||||||
connectionProvider.close();
|
|
||||||
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("orientdb context listener destroyed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param sce
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void contextInitialized(ServletContextEvent sce)
|
|
||||||
{
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("orientdb context listener initialized");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private ConnectionProvider connectionProvider;
|
|
||||||
}
|
|
||||||
@@ -1,295 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import sonia.scm.util.Util;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public final class OrientDBUtil
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FETCH_PLAN = "*:-1";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the logger for OrientDBUtil
|
|
||||||
*/
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(OrientDBUtil.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private OrientDBUtil() {}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*/
|
|
||||||
public static void close(ODatabaseDocumentTx connection)
|
|
||||||
{
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
* @param query
|
|
||||||
* @param parameters
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static List<ODocument> executeListResultQuery(
|
|
||||||
ODatabaseDocumentTx connection, String query, Object... parameters)
|
|
||||||
{
|
|
||||||
if (logger.isTraceEnabled())
|
|
||||||
{
|
|
||||||
logger.trace("execute list result query '{}'", query);
|
|
||||||
}
|
|
||||||
|
|
||||||
OSQLSynchQuery<ODocument> osqlQuery = new OSQLSynchQuery<ODocument>(query);
|
|
||||||
|
|
||||||
osqlQuery.setFetchPlan(FETCH_PLAN);
|
|
||||||
|
|
||||||
return connection.command(osqlQuery).execute(parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
* @param query
|
|
||||||
* @param parameters
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static ODocument executeSingleResultQuery(
|
|
||||||
ODatabaseDocumentTx connection, String query, Object... parameters)
|
|
||||||
{
|
|
||||||
if (logger.isTraceEnabled())
|
|
||||||
{
|
|
||||||
logger.trace("execute single result query '{}'", query);
|
|
||||||
}
|
|
||||||
|
|
||||||
ODocument result = null;
|
|
||||||
OSQLSynchQuery<ODocument> osqlQuery = new OSQLSynchQuery<ODocument>(query);
|
|
||||||
|
|
||||||
osqlQuery.setFetchPlan(FETCH_PLAN);
|
|
||||||
|
|
||||||
List<ODocument> resultList =
|
|
||||||
connection.command(osqlQuery).setLimit(1).execute(parameters);
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(resultList))
|
|
||||||
{
|
|
||||||
result = resultList.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param converter
|
|
||||||
* @param items
|
|
||||||
* @param <T>
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static <T> List<ODocument> transformToDocuments(
|
|
||||||
Converter<T> converter, List<T> items)
|
|
||||||
{
|
|
||||||
List<ODocument> docs = null;
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(items))
|
|
||||||
{
|
|
||||||
docs = Lists.transform(items, new ItemConverterFunction<T>(converter));
|
|
||||||
}
|
|
||||||
|
|
||||||
return docs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param converter
|
|
||||||
* @param docs
|
|
||||||
* @param <T>
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static <T> List<T> transformToItems(Converter<T> converter,
|
|
||||||
List<ODocument> docs)
|
|
||||||
{
|
|
||||||
List<T> items = null;
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(docs))
|
|
||||||
{
|
|
||||||
items = Lists.transform(docs,
|
|
||||||
new DocumentConverterFunction<T>(converter));
|
|
||||||
}
|
|
||||||
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- inner classes --------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
*
|
|
||||||
* @version Enter version here..., 12/03/12
|
|
||||||
* @author Enter your name here...
|
|
||||||
*/
|
|
||||||
private static class DocumentConverterFunction<T>
|
|
||||||
implements Function<ODocument, T>
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param converter
|
|
||||||
*/
|
|
||||||
public DocumentConverterFunction(Converter<T> converter)
|
|
||||||
{
|
|
||||||
this.converter = converter;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods ------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public T apply(ODocument doc)
|
|
||||||
{
|
|
||||||
return converter.convert(doc);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields -------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Converter<T> converter;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param <F>
|
|
||||||
*
|
|
||||||
* @version Enter version here..., 12/03/12
|
|
||||||
* @author Enter your name here...
|
|
||||||
*/
|
|
||||||
private static class ItemConverterFunction<F>
|
|
||||||
implements Function<F, ODocument>
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param converter
|
|
||||||
*/
|
|
||||||
public ItemConverterFunction(Converter<F> converter)
|
|
||||||
{
|
|
||||||
this.converter = converter;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods ------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param f
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ODocument apply(F f)
|
|
||||||
{
|
|
||||||
return converter.convert(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields -------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Converter<F> converter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
|
|
||||||
import sonia.scm.orientdb.AbstractOrientDBModelDAO;
|
|
||||||
import sonia.scm.orientdb.OrientDBUtil;
|
|
||||||
import sonia.scm.repository.Repository;
|
|
||||||
import sonia.scm.repository.RepositoryDAO;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class OrientDBRepositoryDAO extends AbstractOrientDBModelDAO<Repository>
|
|
||||||
implements RepositoryDAO
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String QUERY_ALL = "select from Repository";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String QUERY_SINGLE_BYID =
|
|
||||||
"select from Repository where id = ?";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String QUERY_SINGLE_BYTYPEANDNAME =
|
|
||||||
"select from Repository where type = ? and name = ?";
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connectionProvider
|
|
||||||
*/
|
|
||||||
@Inject
|
|
||||||
public OrientDBRepositoryDAO(Provider<ODatabaseDocumentTx> connectionProvider)
|
|
||||||
{
|
|
||||||
super(connectionProvider, RepositoryConverter.INSTANCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @param name
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean contains(String type, String name)
|
|
||||||
{
|
|
||||||
return get(type, name) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @param name
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Repository get(String type, String name)
|
|
||||||
{
|
|
||||||
Repository repository = null;
|
|
||||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ODocument doc = getDocument(connection, type, name);
|
|
||||||
|
|
||||||
if (doc != null)
|
|
||||||
{
|
|
||||||
repository = converter.convert(doc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
OrientDBUtil.close(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
return repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected List<ODocument> getAllDocuments(ODatabaseDocumentTx connection)
|
|
||||||
{
|
|
||||||
return OrientDBUtil.executeListResultQuery(connection, QUERY_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
* @param id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected ODocument getDocument(ODatabaseDocumentTx connection, String id)
|
|
||||||
{
|
|
||||||
return OrientDBUtil.executeSingleResultQuery(connection, QUERY_SINGLE_BYID,
|
|
||||||
id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
* @param type
|
|
||||||
* @param name
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private ODocument getDocument(ODatabaseDocumentTx connection, String type,
|
|
||||||
String name)
|
|
||||||
{
|
|
||||||
return OrientDBUtil.executeSingleResultQuery(connection,
|
|
||||||
QUERY_SINGLE_BYTYPEANDNAME, type, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OType;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
|
|
||||||
import sonia.scm.orientdb.AbstractConverter;
|
|
||||||
import sonia.scm.orientdb.Converter;
|
|
||||||
import sonia.scm.repository.Permission;
|
|
||||||
import sonia.scm.repository.PermissionType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class PermissionConverter extends AbstractConverter
|
|
||||||
implements Converter<Permission>
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String DOCUMENT_CLASS = "Permission";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_GROUP = "group";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_NAME = "name";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final PermissionConverter INSTANCE = new PermissionConverter();
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param permission
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ODocument convert(ODocument doc, Permission permission)
|
|
||||||
{
|
|
||||||
appendField(doc, FIELD_NAME, permission.getName());
|
|
||||||
appendField(doc, FIELD_TYPE, permission.getType().toString());
|
|
||||||
appendField(doc, FIELD_GROUP, permission.isGroupPermission(),
|
|
||||||
OType.BOOLEAN);
|
|
||||||
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param permission
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ODocument convert(Permission permission)
|
|
||||||
{
|
|
||||||
ODocument doc = new ODocument(DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
convert(doc, permission);
|
|
||||||
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Permission convert(ODocument doc)
|
|
||||||
{
|
|
||||||
Permission permission = new Permission();
|
|
||||||
|
|
||||||
permission.setName(getStringField(doc, FIELD_NAME));
|
|
||||||
|
|
||||||
String typeString = doc.field(FIELD_TYPE);
|
|
||||||
|
|
||||||
if (typeString != null)
|
|
||||||
{
|
|
||||||
permission.setType(PermissionType.valueOf(typeString));
|
|
||||||
}
|
|
||||||
|
|
||||||
permission.setGroupPermission(getBooleanField(doc, FIELD_GROUP));
|
|
||||||
|
|
||||||
return permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void createShema(ODatabaseDocumentTx connection)
|
|
||||||
{
|
|
||||||
OSchema schema = connection.getMetadata().getSchema();
|
|
||||||
OClass oclass = schema.getClass(DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
if (oclass == null)
|
|
||||||
{
|
|
||||||
oclass = schema.createClass(DOCUMENT_CLASS);
|
|
||||||
oclass.createProperty(FIELD_NAME, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_TYPE, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_GROUP, OType.BOOLEAN);
|
|
||||||
schema.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass.INDEX_TYPE;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OType;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
|
|
||||||
import sonia.scm.orientdb.AbstractConverter;
|
|
||||||
import sonia.scm.orientdb.Converter;
|
|
||||||
import sonia.scm.orientdb.OrientDBUtil;
|
|
||||||
import sonia.scm.repository.Repository;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class RepositoryConverter extends AbstractConverter
|
|
||||||
implements Converter<Repository>
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String DOCUMENT_CLASS = "Repository";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_ARCHIVED = "archived";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_CONTACT = "contact";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_CREATIONDATE = "creationDate";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_DESCRIPTION = "description";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_NAME = "name";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_PERMISSIONS = "permissions";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_PUBLIC = "public";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String INDEX_ID = "RepositoryId";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String INDEX_TYPEANDNAME = "RepositoryTypeAndName";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final RepositoryConverter INSTANCE = new RepositoryConverter();
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param repository
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ODocument convert(ODocument doc, Repository repository)
|
|
||||||
{
|
|
||||||
appendModelObjectFields(doc, repository);
|
|
||||||
appendField(doc, FIELD_NAME, repository.getName());
|
|
||||||
appendField(doc, FIELD_CONTACT, repository.getContact());
|
|
||||||
appendField(doc, FIELD_DESCRIPTION, repository.getDescription());
|
|
||||||
appendField(doc, FIELD_PUBLIC, repository.isPublicReadable(),
|
|
||||||
OType.BOOLEAN);
|
|
||||||
appendField(doc, FIELD_ARCHIVED, repository.isArchived(), OType.BOOLEAN);
|
|
||||||
appendField(doc, FIELD_CREATIONDATE, repository.getCreationDate(),
|
|
||||||
OType.LONG);
|
|
||||||
appendPropertiesField(doc, repository);
|
|
||||||
appendListField(doc, FIELD_PERMISSIONS, PermissionConverter.INSTANCE,
|
|
||||||
repository.getPermissions());
|
|
||||||
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repository
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ODocument convert(Repository repository)
|
|
||||||
{
|
|
||||||
ODocument doc = new ODocument(DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
convert(doc, repository);
|
|
||||||
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Repository convert(ODocument doc)
|
|
||||||
{
|
|
||||||
Repository repository = new Repository();
|
|
||||||
|
|
||||||
repository.setId(getStringField(doc, FIELD_ID));
|
|
||||||
repository.setType(getStringField(doc, FIELD_TYPE));
|
|
||||||
repository.setName(getStringField(doc, FIELD_NAME));
|
|
||||||
repository.setContact(getStringField(doc, FIELD_CONTACT));
|
|
||||||
repository.setDescription(getStringField(doc, FIELD_DESCRIPTION));
|
|
||||||
repository.setPublicReadable(getBooleanField(doc, FIELD_PUBLIC));
|
|
||||||
repository.setArchived(getBooleanField(doc, FIELD_ARCHIVED));
|
|
||||||
repository.setLastModified(getLongField(doc, FIELD_LASTMODIFIED));
|
|
||||||
repository.setCreationDate(getLongField(doc, FIELD_CREATIONDATE));
|
|
||||||
|
|
||||||
Map<String, String> properties = doc.field(FIELD_PROPERTIES);
|
|
||||||
|
|
||||||
repository.setProperties(properties);
|
|
||||||
|
|
||||||
List<ODocument> permissions = doc.field(FIELD_PERMISSIONS);
|
|
||||||
|
|
||||||
repository.setPermissions(
|
|
||||||
OrientDBUtil.transformToItems(
|
|
||||||
PermissionConverter.INSTANCE, permissions));
|
|
||||||
|
|
||||||
return repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void createShema(ODatabaseDocumentTx connection)
|
|
||||||
{
|
|
||||||
OSchema schema = connection.getMetadata().getSchema();
|
|
||||||
OClass oclass = schema.getClass(DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
if (oclass == null)
|
|
||||||
{
|
|
||||||
oclass = schema.createClass(DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
// model properites
|
|
||||||
oclass.createProperty(FIELD_ID, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_TYPE, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_LASTMODIFIED, OType.LONG);
|
|
||||||
|
|
||||||
// repository properties
|
|
||||||
oclass.createProperty(FIELD_CONTACT, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_CREATIONDATE, OType.LONG);
|
|
||||||
oclass.createProperty(FIELD_DESCRIPTION, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_NAME, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_PERMISSIONS, OType.EMBEDDEDLIST);
|
|
||||||
oclass.createProperty(FIELD_PROPERTIES, OType.EMBEDDEDMAP);
|
|
||||||
oclass.createProperty(FIELD_PUBLIC, OType.BOOLEAN);
|
|
||||||
|
|
||||||
// indexes
|
|
||||||
oclass.createIndex(INDEX_ID, INDEX_TYPE.UNIQUE, FIELD_ID);
|
|
||||||
oclass.createIndex(INDEX_TYPEANDNAME, INDEX_TYPE.UNIQUE, FIELD_NAME,
|
|
||||||
FIELD_TYPE);
|
|
||||||
schema.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
PermissionConverter.INSTANCE.createShema(connection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,222 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.store.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import sonia.scm.orientdb.OrientDBUtil;
|
|
||||||
import sonia.scm.store.AbstractStore;
|
|
||||||
import sonia.scm.util.Util;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
*/
|
|
||||||
public class OrientDBStore<T> extends AbstractStore<T>
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String DOCUMENT_CLASS = "StoreObject";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_DATA = "data";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_NAME = "name";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_TYPE = "type";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String INDEX_NAME = "StoreTypeAndName";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String QUERY_STORE =
|
|
||||||
"select from StoreObject where name = ? and type = ?";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the logger for OrientDBStore
|
|
||||||
*/
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(OrientDBStore.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connectionProvider
|
|
||||||
* @param context
|
|
||||||
* @param type
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
public OrientDBStore(Provider<ODatabaseDocumentTx> connectionProvider,
|
|
||||||
JAXBContext context, Class<T> type, String name)
|
|
||||||
{
|
|
||||||
this.connectionProvider = connectionProvider;
|
|
||||||
this.context = context;
|
|
||||||
this.type = type;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected T readObject()
|
|
||||||
{
|
|
||||||
T result = null;
|
|
||||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ODocument doc = getStoreDocument(connection);
|
|
||||||
|
|
||||||
if (doc != null)
|
|
||||||
{
|
|
||||||
String data = doc.field(FIELD_DATA);
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(data))
|
|
||||||
{
|
|
||||||
StringReader reader = new StringReader(data);
|
|
||||||
|
|
||||||
result = (T) context.createUnmarshaller().unmarshal(reader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (JAXBException ex)
|
|
||||||
{
|
|
||||||
logger.error("could not unmarshall object", ex);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
OrientDBUtil.close(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param t
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void writeObject(T t)
|
|
||||||
{
|
|
||||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ODocument doc = getStoreDocument(connection);
|
|
||||||
|
|
||||||
if (doc == null)
|
|
||||||
{
|
|
||||||
doc = new ODocument(DOCUMENT_CLASS);
|
|
||||||
doc.field(FIELD_NAME, name);
|
|
||||||
doc.field(FIELD_TYPE, type.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
StringWriter buffer = new StringWriter();
|
|
||||||
|
|
||||||
context.createMarshaller().marshal(t, buffer);
|
|
||||||
doc.field(FIELD_DATA, buffer.toString());
|
|
||||||
doc.save();
|
|
||||||
}
|
|
||||||
catch (JAXBException ex)
|
|
||||||
{
|
|
||||||
logger.error("could not marshall object", ex);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
OrientDBUtil.close(connection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private ODocument getStoreDocument(ODatabaseDocumentTx connection)
|
|
||||||
{
|
|
||||||
return OrientDBUtil.executeSingleResultQuery(connection, QUERY_STORE, name,
|
|
||||||
type.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Provider<ODatabaseDocumentTx> connectionProvider;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private JAXBContext context;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Class<T> type;
|
|
||||||
}
|
|
||||||
@@ -1,162 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.store.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass.INDEX_TYPE;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OType;
|
|
||||||
|
|
||||||
import sonia.scm.SCMContextProvider;
|
|
||||||
import sonia.scm.orientdb.OrientDBUtil;
|
|
||||||
import sonia.scm.util.AssertUtil;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
import sonia.scm.store.StoreFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class OrientDBStoreFactory implements StoreFactory
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connectionProvider
|
|
||||||
*/
|
|
||||||
@Inject
|
|
||||||
public OrientDBStoreFactory(Provider<ODatabaseDocumentTx> connectionProvider)
|
|
||||||
{
|
|
||||||
this.connectionProvider = connectionProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException
|
|
||||||
{
|
|
||||||
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void init(SCMContextProvider context)
|
|
||||||
{
|
|
||||||
ODatabaseDocumentTx connection = connectionProvider.get();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
OSchema schema = connection.getMetadata().getSchema();
|
|
||||||
OClass oclass = schema.getClass(OrientDBStore.DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
if (oclass == null)
|
|
||||||
{
|
|
||||||
oclass = schema.createClass(OrientDBStore.DOCUMENT_CLASS);
|
|
||||||
oclass.createProperty(OrientDBStore.FIELD_NAME, OType.STRING);
|
|
||||||
oclass.createProperty(OrientDBStore.FIELD_TYPE, OType.STRING);
|
|
||||||
oclass.createProperty(OrientDBStore.FIELD_DATA, OType.STRING);
|
|
||||||
oclass.createIndex(OrientDBStore.INDEX_NAME, INDEX_TYPE.UNIQUE,
|
|
||||||
OrientDBStore.FIELD_NAME, OrientDBStore.FIELD_TYPE);
|
|
||||||
schema.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
OrientDBUtil.close(connection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @param name
|
|
||||||
* @param <T>
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public <T> OrientDBStore<T> getStore(Class<T> type, String name)
|
|
||||||
{
|
|
||||||
AssertUtil.assertIsNotNull(type);
|
|
||||||
AssertUtil.assertIsNotEmpty(name);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return new OrientDBStore<T>(connectionProvider,
|
|
||||||
JAXBContext.newInstance(type), type, name);
|
|
||||||
}
|
|
||||||
catch (JAXBException ex)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(
|
|
||||||
"could not create jaxb context for ".concat(type.getName()), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private final Provider<ODatabaseDocumentTx> connectionProvider;
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.user.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
|
|
||||||
import sonia.scm.orientdb.AbstractOrientDBModelDAO;
|
|
||||||
import sonia.scm.orientdb.OrientDBUtil;
|
|
||||||
import sonia.scm.user.User;
|
|
||||||
import sonia.scm.user.UserDAO;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class OrientDBUserDAO extends AbstractOrientDBModelDAO<User>
|
|
||||||
implements UserDAO
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String QUERY_ALL = "select from User";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String QUERY_SINGLE_BYID =
|
|
||||||
"select from User where id = ?";
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connectionProvider
|
|
||||||
*/
|
|
||||||
@Inject
|
|
||||||
public OrientDBUserDAO(Provider<ODatabaseDocumentTx> connectionProvider)
|
|
||||||
{
|
|
||||||
super(connectionProvider, UserConverter.INSTANCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected List<ODocument> getAllDocuments(ODatabaseDocumentTx connection)
|
|
||||||
{
|
|
||||||
return OrientDBUtil.executeListResultQuery(connection, QUERY_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
* @param id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected ODocument getDocument(ODatabaseDocumentTx connection, String id)
|
|
||||||
{
|
|
||||||
return OrientDBUtil.executeSingleResultQuery(connection, QUERY_SINGLE_BYID,
|
|
||||||
id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.user.orientdb;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass.INDEX_TYPE;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OType;
|
|
||||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
|
||||||
|
|
||||||
import sonia.scm.orientdb.AbstractConverter;
|
|
||||||
import sonia.scm.orientdb.Converter;
|
|
||||||
import sonia.scm.user.User;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class UserConverter extends AbstractConverter implements Converter<User>
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String DOCUMENT_CLASS = "User";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_ACTIVE = "active";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_ADMIN = "admin";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_CREATIONDATE = "creationDate";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_DISPLAYNAME = "displayName";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_MAIL = "mail";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FIELD_PASSWORD = "password";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String INDEX_ID = "UserId";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final UserConverter INSTANCE = new UserConverter();
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param item
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ODocument convert(User item)
|
|
||||||
{
|
|
||||||
ODocument doc = new ODocument(DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
return convert(doc, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
* @param user
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ODocument convert(ODocument doc, User user)
|
|
||||||
{
|
|
||||||
appendModelObjectFields(doc, user);
|
|
||||||
appendField(doc, FIELD_DISPLAYNAME, user.getDisplayName());
|
|
||||||
appendField(doc, FIELD_MAIL, user.getMail());
|
|
||||||
appendField(doc, FIELD_PASSWORD, user.getPassword());
|
|
||||||
appendField(doc, FIELD_ADMIN, user.isAdmin());
|
|
||||||
appendField(doc, FIELD_ACTIVE, user.isActive());
|
|
||||||
appendField(doc, FIELD_CREATIONDATE, user.getCreationDate(), OType.LONG);
|
|
||||||
appendPropertiesField(doc, user);
|
|
||||||
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param doc
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public User convert(ODocument doc)
|
|
||||||
{
|
|
||||||
User user = new User();
|
|
||||||
|
|
||||||
user.setName(getStringField(doc, FIELD_ID));
|
|
||||||
user.setDisplayName(getStringField(doc, FIELD_DISPLAYNAME));
|
|
||||||
user.setMail(getStringField(doc, FIELD_MAIL));
|
|
||||||
user.setPassword(getStringField(doc, FIELD_PASSWORD));
|
|
||||||
user.setType(getStringField(doc, FIELD_TYPE));
|
|
||||||
user.setAdmin(getBooleanField(doc, FIELD_ADMIN));
|
|
||||||
user.setAdmin(getBooleanField(doc, FIELD_ACTIVE));
|
|
||||||
user.setLastModified(getLongField(doc, FIELD_LASTMODIFIED));
|
|
||||||
user.setCreationDate(getLongField(doc, FIELD_CREATIONDATE));
|
|
||||||
|
|
||||||
Map<String, String> properties = doc.field(FIELD_PROPERTIES);
|
|
||||||
|
|
||||||
user.setProperties(properties);
|
|
||||||
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void createShema(ODatabaseDocumentTx connection)
|
|
||||||
{
|
|
||||||
OSchema schema = connection.getMetadata().getSchema();
|
|
||||||
OClass oclass = schema.getClass(DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
if (oclass == null)
|
|
||||||
{
|
|
||||||
oclass = schema.createClass(DOCUMENT_CLASS);
|
|
||||||
|
|
||||||
// model properites
|
|
||||||
oclass.createProperty(FIELD_ID, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_TYPE, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_LASTMODIFIED, OType.LONG);
|
|
||||||
|
|
||||||
// user properties
|
|
||||||
oclass.createProperty(FIELD_ADMIN, OType.BOOLEAN);
|
|
||||||
oclass.createProperty(FIELD_CREATIONDATE, OType.LONG);
|
|
||||||
oclass.createProperty(FIELD_DISPLAYNAME, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_MAIL, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_ACTIVE, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_PASSWORD, OType.STRING);
|
|
||||||
oclass.createProperty(FIELD_PROPERTIES, OType.EMBEDDEDMAP);
|
|
||||||
|
|
||||||
// indexes
|
|
||||||
oclass.createIndex(INDEX_ID, INDEX_TYPE.UNIQUE, FIELD_ID);
|
|
||||||
schema.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
<?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
|
|
||||||
|
|
||||||
|
|
||||||
-->
|
|
||||||
<overrides>
|
|
||||||
|
|
||||||
<override>
|
|
||||||
<bind>sonia.scm.user.UserDAO</bind>
|
|
||||||
<to>sonia.scm.user.orientdb.OrientDBUserDAO</to>
|
|
||||||
</override>
|
|
||||||
|
|
||||||
<override>
|
|
||||||
<bind>sonia.scm.group.GroupDAO</bind>
|
|
||||||
<to>sonia.scm.group.orientdb.OrientDBGroupDAO</to>
|
|
||||||
</override>
|
|
||||||
|
|
||||||
<override>
|
|
||||||
<bind>sonia.scm.repository.RepositoryDAO</bind>
|
|
||||||
<to>sonia.scm.repository.orientdb.OrientDBRepositoryDAO</to>
|
|
||||||
</override>
|
|
||||||
|
|
||||||
<override>
|
|
||||||
<bind>sonia.scm.store.StoreFactory</bind>
|
|
||||||
<to>sonia.scm.store.orientdb.OrientDBStoreFactory</to>
|
|
||||||
</override>
|
|
||||||
|
|
||||||
<module>sonia.scm.orientdb.OrientDBModule</module>
|
|
||||||
|
|
||||||
</overrides>
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<?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>
|
|
||||||
Reference in New Issue
Block a user