diff --git a/pom.xml b/pom.xml index 26291e1f66..4e13ace753 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,6 @@ scm-plugins scm-samples scm-dao-xml - scm-dao-orientdb scm-webapp scm-server scm-plugin-backend diff --git a/scm-dao-orientdb/pom.xml b/scm-dao-orientdb/pom.xml deleted file mode 100644 index 2c850e2321..0000000000 --- a/scm-dao-orientdb/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - 4.0.0 - - - sonia.scm - scm - 2.0.0-SNAPSHOT - - - sonia.scm - scm-dao-orientdb - 2.0.0-SNAPSHOT - scm-dao-orientdb - - - - - javax.servlet - servlet-api - ${servlet.version} - provided - - - - sonia.scm - scm-core - 2.0.0-SNAPSHOT - - - - com.orientechnologies - orientdb-client - ${orientdb.version} - - - - com.orientechnologies - orientdb-server - ${orientdb.version} - - - com.orientechnologies - orientdb-client - - - - - - - - sonia.scm - scm-test - 2.0.0-SNAPSHOT - test - - - - - - 1.1.0 - - - - - - orientechnologies-repository - Orient Technologies Maven2 Repository - http://www.orientechnologies.com/listing/m2 - - true - - - - - - diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/group/orientdb/GroupConverter.java b/scm-dao-orientdb/src/main/java/sonia/scm/group/orientdb/GroupConverter.java deleted file mode 100644 index e25ce9a327..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/group/orientdb/GroupConverter.java +++ /dev/null @@ -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 -{ - - /** 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 properties = doc.field(FIELD_PROPERTIES); - - group.setProperties(properties); - - List 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(); - } - } -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/group/orientdb/OrientDBGroupDAO.java b/scm-dao-orientdb/src/main/java/sonia/scm/group/orientdb/OrientDBGroupDAO.java deleted file mode 100644 index 56f2187537..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/group/orientdb/OrientDBGroupDAO.java +++ /dev/null @@ -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 - 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 connectionProvider) - { - super(connectionProvider, GroupConverter.INSTANCE); - } - - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param connection - * - * @return - */ - @Override - protected List 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); - } -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/AbstractConverter.java b/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/AbstractConverter.java deleted file mode 100644 index f811e56f20..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/AbstractConverter.java +++ /dev/null @@ -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 - */ - protected void appendListField(ODocument doc, String name, - Converter converter, List list) - { - List 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); - } -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/AbstractOrientDBModelDAO.java b/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/AbstractOrientDBModelDAO.java deleted file mode 100644 index 2b9585cb77..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/AbstractOrientDBModelDAO.java +++ /dev/null @@ -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 - */ -public abstract class AbstractOrientDBModelDAO - implements GenericDAO -{ - - /** 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 connectionProvider, - Converter converter) - { - this.connectionProvider = connectionProvider; - this.converter = converter; - createShema(); - } - - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param connection - * - * @return - */ - protected abstract List 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 getAll() - { - List items = null; - ODatabaseDocumentTx connection = connectionProvider.get(); - - try - { - List 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 connectionProvider; - - /** Field description */ - protected Converter converter; -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/ConnectionConfiguration.java b/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/ConnectionConfiguration.java deleted file mode 100644 index 8300fd9c5e..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/ConnectionConfiguration.java +++ /dev/null @@ -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; -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/ConnectionProvider.java b/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/ConnectionProvider.java deleted file mode 100644 index c1bd0738e4..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/ConnectionProvider.java +++ /dev/null @@ -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, 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; -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/Converter.java b/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/Converter.java deleted file mode 100644 index 0575d47e5d..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/Converter.java +++ /dev/null @@ -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 - */ -public interface Converter -{ - - /** - * 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); -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/OrientDBModule.java b/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/OrientDBModule.java deleted file mode 100644 index 57d4a14b9a..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/OrientDBModule.java +++ /dev/null @@ -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 servletContextListenerBinder = - Multibinder.newSetBinder(binder(), ServletContextListener.class); - - servletContextListenerBinder.addBinding().to( - OrientDBServletContextListener.class); - } -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/OrientDBServletContextListener.java b/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/OrientDBServletContextListener.java deleted file mode 100644 index 7dc5468be6..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/OrientDBServletContextListener.java +++ /dev/null @@ -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; -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/OrientDBUtil.java b/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/OrientDBUtil.java deleted file mode 100644 index 02ccb6066b..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/orientdb/OrientDBUtil.java +++ /dev/null @@ -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 executeListResultQuery( - ODatabaseDocumentTx connection, String query, Object... parameters) - { - if (logger.isTraceEnabled()) - { - logger.trace("execute list result query '{}'", query); - } - - OSQLSynchQuery osqlQuery = new OSQLSynchQuery(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 osqlQuery = new OSQLSynchQuery(query); - - osqlQuery.setFetchPlan(FETCH_PLAN); - - List 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 - * - * @return - */ - public static List transformToDocuments( - Converter converter, List items) - { - List docs = null; - - if (Util.isNotEmpty(items)) - { - docs = Lists.transform(items, new ItemConverterFunction(converter)); - } - - return docs; - } - - /** - * Method description - * - * - * @param converter - * @param docs - * @param - * - * @return - */ - public static List transformToItems(Converter converter, - List docs) - { - List items = null; - - if (Util.isNotEmpty(docs)) - { - items = Lists.transform(docs, - new DocumentConverterFunction(converter)); - } - - return items; - } - - //~--- inner classes -------------------------------------------------------- - - /** - * Class description - * - * - * @param - * - * @version Enter version here..., 12/03/12 - * @author Enter your name here... - */ - private static class DocumentConverterFunction - implements Function - { - - /** - * Constructs ... - * - * - * @param converter - */ - public DocumentConverterFunction(Converter 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 converter; - } - - - /** - * Class description - * - * - * @param - * - * @version Enter version here..., 12/03/12 - * @author Enter your name here... - */ - private static class ItemConverterFunction - implements Function - { - - /** - * Constructs ... - * - * - * @param converter - */ - public ItemConverterFunction(Converter 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 converter; - } -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/repository/orientdb/OrientDBRepositoryDAO.java b/scm-dao-orientdb/src/main/java/sonia/scm/repository/orientdb/OrientDBRepositoryDAO.java deleted file mode 100644 index de013e8698..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/repository/orientdb/OrientDBRepositoryDAO.java +++ /dev/null @@ -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 - 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 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 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); - } -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/repository/orientdb/PermissionConverter.java b/scm-dao-orientdb/src/main/java/sonia/scm/repository/orientdb/PermissionConverter.java deleted file mode 100644 index 6e152b4d87..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/repository/orientdb/PermissionConverter.java +++ /dev/null @@ -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 -{ - - /** 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(); - } - } -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/repository/orientdb/RepositoryConverter.java b/scm-dao-orientdb/src/main/java/sonia/scm/repository/orientdb/RepositoryConverter.java deleted file mode 100644 index bd96ca3444..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/repository/orientdb/RepositoryConverter.java +++ /dev/null @@ -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 -{ - - /** 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 properties = doc.field(FIELD_PROPERTIES); - - repository.setProperties(properties); - - List 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); - } -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/store/orientdb/OrientDBStore.java b/scm-dao-orientdb/src/main/java/sonia/scm/store/orientdb/OrientDBStore.java deleted file mode 100644 index 077e9fb443..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/store/orientdb/OrientDBStore.java +++ /dev/null @@ -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 - */ -public class OrientDBStore extends AbstractStore -{ - - /** 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 connectionProvider, - JAXBContext context, Class 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 connectionProvider; - - /** Field description */ - private JAXBContext context; - - /** Field description */ - private String name; - - /** Field description */ - private Class type; -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/store/orientdb/OrientDBStoreFactory.java b/scm-dao-orientdb/src/main/java/sonia/scm/store/orientdb/OrientDBStoreFactory.java deleted file mode 100644 index e597382659..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/store/orientdb/OrientDBStoreFactory.java +++ /dev/null @@ -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 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 - * - * @return - */ - @Override - public OrientDBStore getStore(Class type, String name) - { - AssertUtil.assertIsNotNull(type); - AssertUtil.assertIsNotEmpty(name); - - try - { - return new OrientDBStore(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 connectionProvider; -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/user/orientdb/OrientDBUserDAO.java b/scm-dao-orientdb/src/main/java/sonia/scm/user/orientdb/OrientDBUserDAO.java deleted file mode 100644 index e2fdf0d59d..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/user/orientdb/OrientDBUserDAO.java +++ /dev/null @@ -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 - 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 connectionProvider) - { - super(connectionProvider, UserConverter.INSTANCE); - } - - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param connection - * - * @return - */ - @Override - protected List 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); - } -} diff --git a/scm-dao-orientdb/src/main/java/sonia/scm/user/orientdb/UserConverter.java b/scm-dao-orientdb/src/main/java/sonia/scm/user/orientdb/UserConverter.java deleted file mode 100644 index 7aabd57101..0000000000 --- a/scm-dao-orientdb/src/main/java/sonia/scm/user/orientdb/UserConverter.java +++ /dev/null @@ -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 -{ - - /** 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 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(); - } - } -} diff --git a/scm-dao-orientdb/src/main/resources/META-INF/scm/override.xml b/scm-dao-orientdb/src/main/resources/META-INF/scm/override.xml deleted file mode 100644 index f15b1f30e8..0000000000 --- a/scm-dao-orientdb/src/main/resources/META-INF/scm/override.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - sonia.scm.user.UserDAO - sonia.scm.user.orientdb.OrientDBUserDAO - - - - sonia.scm.group.GroupDAO - sonia.scm.group.orientdb.OrientDBGroupDAO - - - - sonia.scm.repository.RepositoryDAO - sonia.scm.repository.orientdb.OrientDBRepositoryDAO - - - - sonia.scm.store.StoreFactory - sonia.scm.store.orientdb.OrientDBStoreFactory - - - sonia.scm.orientdb.OrientDBModule - - \ No newline at end of file diff --git a/scm-dao-orientdb/src/main/resources/sonia/scm/orientdb/server-configuration.xml b/scm-dao-orientdb/src/main/resources/sonia/scm/orientdb/server-configuration.xml deleted file mode 100644 index 797270bbdb..0000000000 --- a/scm-dao-orientdb/src/main/resources/sonia/scm/orientdb/server-configuration.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file