diff --git a/src/main/java/org/alfresco/repo/domain/solr/NodeParametersEntity.java b/src/main/java/org/alfresco/repo/domain/solr/NodeParametersEntity.java index d3da1fef84..d89822eb03 100644 --- a/src/main/java/org/alfresco/repo/domain/solr/NodeParametersEntity.java +++ b/src/main/java/org/alfresco/repo/domain/solr/NodeParametersEntity.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.domain.solr; import java.util.ArrayList; @@ -48,8 +48,10 @@ public class NodeParametersEntity extends NodeParameters private List includeAspectIds; private List excludeAspectIds; - private Long originalIdPropQNameId; + private Long originalIdPropQNameId; private Long shardPropertyQNameId; + + private String shardPropertyType; /** * Public constructor, but not generally useful @@ -57,7 +59,7 @@ public class NodeParametersEntity extends NodeParameters public NodeParametersEntity(QNameDAO qnameDAO) { Pair qnamePair = qnameDAO.getQName(ContentModel.PROP_ORIGINAL_ID); - this.setOriginalIdPropQNameId(qnamePair == null ? -1 : qnamePair.getFirst()); + this.setOriginalIdPropQNameId(qnamePair == null ? Long.valueOf(-1) : qnamePair.getFirst()); } /** @@ -161,17 +163,24 @@ public class NodeParametersEntity extends NodeParameters public boolean isIncludeNodesTable() { return (getFromNodeId() != null || getToNodeId() != null || getIncludeTypeIds() != null || getExcludeTypeIds() != null || getIncludeAspectIds() != null || getExcludeAspectIds() != null); - } - - public Long getShardPropertyQNameId() - { - return this.shardPropertyQNameId; - } - - public void setShardPropertyQNameId(Long shardPropertyQNameId) - { - this.shardPropertyQNameId = shardPropertyQNameId; - } - - + } + + public Long getShardPropertyQNameId() + { + return this.shardPropertyQNameId; + } + + public void setShardPropertyQNameId(Long shardPropertyQNameId) + { + this.shardPropertyQNameId = shardPropertyQNameId; + } + + + public String getShardPropertyType() { + return shardPropertyType; + } + + public void setShardPropertyType(String shardPropertyType) { + this.shardPropertyType = shardPropertyType; + } } diff --git a/src/main/java/org/alfresco/repo/domain/solr/SOLRDAO.java b/src/main/java/org/alfresco/repo/domain/solr/SOLRDAO.java index e25b311b20..3e19204290 100644 --- a/src/main/java/org/alfresco/repo/domain/solr/SOLRDAO.java +++ b/src/main/java/org/alfresco/repo/domain/solr/SOLRDAO.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.domain.solr; import java.util.List; @@ -31,7 +31,7 @@ import org.alfresco.repo.domain.node.Node; import org.alfresco.repo.solr.Acl; import org.alfresco.repo.solr.AclChangeSet; import org.alfresco.repo.solr.NodeParameters; -import org.alfresco.repo.solr.Transaction; +import org.alfresco.repo.solr.Transaction; import org.alfresco.service.namespace.QName; /** @@ -78,9 +78,10 @@ public interface SOLRDAO /** * Get the nodes satisfying the constraints in nodeParameters * - * @param nodeParameters set of constraints for which nodes to return - * @param shardPropertQName + * @param nodeParameters set of constraints for which nodes to return + * @param shardPropertQName qname of property to use as shard_key + * @param shardPropertyTypeName type name (text, int, long) of property to use as shard_key * @return list of matching nodes */ - public List getNodes(NodeParameters nodeParameters, QName shardPropertQName); + public List getNodes(NodeParameters nodeParameters, QName shardPropertQName, QName shardPropertyTypeName); } diff --git a/src/main/java/org/alfresco/repo/domain/solr/ibatis/SOLRDAOImpl.java b/src/main/java/org/alfresco/repo/domain/solr/ibatis/SOLRDAOImpl.java index 161c1cf4fc..8a4f3ce6b4 100644 --- a/src/main/java/org/alfresco/repo/domain/solr/ibatis/SOLRDAOImpl.java +++ b/src/main/java/org/alfresco/repo/domain/solr/ibatis/SOLRDAOImpl.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.domain.solr.ibatis; import java.util.ArrayList; @@ -31,18 +31,19 @@ import java.util.List; import java.util.TreeSet; import org.alfresco.model.ContentModel; +import org.alfresco.repo.admin.registry.RegistryServiceImpl; import org.alfresco.repo.domain.node.Node; import org.alfresco.repo.domain.qname.QNameDAO; import org.alfresco.repo.domain.solr.AclEntity; import org.alfresco.repo.domain.solr.NodeParametersEntity; import org.alfresco.repo.domain.solr.SOLRDAO; -import org.alfresco.repo.domain.solr.SOLRTrackingParameters; -import org.alfresco.repo.search.impl.QueryParserUtils; +import org.alfresco.repo.domain.solr.SOLRTrackingParameters; +import org.alfresco.repo.search.impl.QueryParserUtils; import org.alfresco.repo.solr.Acl; import org.alfresco.repo.solr.AclChangeSet; import org.alfresco.repo.solr.NodeParameters; -import org.alfresco.repo.solr.Transaction; -import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.repo.solr.Transaction; +import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; import org.alfresco.util.PropertyCheck; @@ -63,6 +64,7 @@ public class SOLRDAOImpl implements SOLRDAO private SqlSessionTemplate template; private QNameDAO qnameDAO; + private RegistryServiceImpl dictionaryService; public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { @@ -97,7 +99,7 @@ public class SOLRDAOImpl implements SOLRDAO // We simulate an ID for the sys:deleted type Pair deletedTypeQNamePair = qnameDAO.getQName(ContentModel.TYPE_DELETED); - Long deletedTypeQNameId = deletedTypeQNamePair == null ? -1L : deletedTypeQNamePair.getFirst(); + Long deletedTypeQNameId = deletedTypeQNamePair == null ? -1L : deletedTypeQNamePair.getFirst(); SOLRTrackingParameters params = new SOLRTrackingParameters(deletedTypeQNameId); params.setFromIdInclusive(minAclChangeSetId); @@ -199,36 +201,37 @@ public class SOLRDAOImpl implements SOLRDAO * {@inheritDoc} */ @SuppressWarnings("unchecked") - public List getNodes(NodeParameters nodeParameters, QName shardPropertyQName) + public List getNodes(NodeParameters nodeParameters, QName shardPropertyQName, QName shardPropertyTypeName) { - NodeParametersEntity params = new NodeParametersEntity(nodeParameters, qnameDAO); - - if(shardPropertyQName !=null) - { - if(shardPropertyQName.equals(ContentModel.PROP_CREATED)) - { - params.setShardPropertyQNameId(-1L); - } - else if (shardPropertyQName.equals(ContentModel.PROP_MODIFIED)) - { - params.setShardPropertyQNameId(-2L); - } - else if (shardPropertyQName.equals(ContentModel.PROP_CREATOR)) - { - params.setShardPropertyQNameId(-3L); - } - else if (shardPropertyQName.equals(ContentModel.PROP_MODIFIER)) - { - params.setShardPropertyQNameId(-4L); - } - else - { - Pair propertyQNamePair = qnameDAO.getQName(shardPropertyQName); - if(propertyQNamePair != null) - { - params.setShardPropertyQNameId(propertyQNamePair.getFirst()); - } - } + NodeParametersEntity params = new NodeParametersEntity(nodeParameters, qnameDAO); + + if(shardPropertyQName != null && shardPropertyTypeName != null) + { + if(shardPropertyQName.equals(ContentModel.PROP_CREATED)) + { + params.setShardPropertyQNameId(-1L); + } + else if (shardPropertyQName.equals(ContentModel.PROP_MODIFIED)) + { + params.setShardPropertyQNameId(-2L); + } + else if (shardPropertyQName.equals(ContentModel.PROP_CREATOR)) + { + params.setShardPropertyQNameId(-3L); + } + else if (shardPropertyQName.equals(ContentModel.PROP_MODIFIER)) + { + params.setShardPropertyQNameId(-4L); + } + else + { + Pair propertyQNamePair = qnameDAO.getQName(shardPropertyQName); + if(propertyQNamePair != null) + { + params.setShardPropertyQNameId(propertyQNamePair.getFirst()); + params.setShardPropertyType(shardPropertyTypeName.getLocalName()); + } + } } if(nodeParameters.getMaxResults() != 0 && nodeParameters.getMaxResults() != Integer.MAX_VALUE) diff --git a/src/main/java/org/alfresco/repo/search/impl/solr/DbOrIndexSwitchingQueryLanguage.java b/src/main/java/org/alfresco/repo/search/impl/solr/DbOrIndexSwitchingQueryLanguage.java index fa740e3d4b..dba79a08e1 100644 --- a/src/main/java/org/alfresco/repo/search/impl/solr/DbOrIndexSwitchingQueryLanguage.java +++ b/src/main/java/org/alfresco/repo/search/impl/solr/DbOrIndexSwitchingQueryLanguage.java @@ -333,7 +333,7 @@ public class DbOrIndexSwitchingQueryLanguage extends AbstractLuceneQueryLanguage // TODO: setToTxnId(null) when SolrDAO behaviour is fixed. nodeParameters.setToTxnId(Long.MAX_VALUE); stopWatch.start("get changed nodes"); - List changedNodeList = solrDao.getNodes(nodeParameters, null); + List changedNodeList = solrDao.getNodes(nodeParameters, null, null); stopWatch.stop(); if (logger.isDebugEnabled()) { diff --git a/src/main/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java b/src/main/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java index fe1041a5ba..657fb4b320 100644 --- a/src/main/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java +++ b/src/main/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java @@ -359,6 +359,8 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent if(enabled) { QName shardPropertQName = null; + QName shardPropertyType = null; + if(nodeParameters.getShardProperty() != null) { PropertyDefinition pdef = QueryParserUtils.matchPropertyDefinition(NamespaceService.CONTENT_MODEL_1_0_URI, namespaceService, dictionaryService, nodeParameters.getShardProperty()); @@ -366,14 +368,30 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent { throw new AlfrescoRuntimeException("Invalid shard property: "+nodeParameters.getShardProperty()); } - if((!pdef.getDataType().getName().equals(DataTypeDefinition.TEXT)) && (!pdef.getDataType().getName().equals(DataTypeDefinition.DATE)) && (!pdef.getDataType().getName().equals(DataTypeDefinition.DATETIME))) + + shardPropertyType = pdef.getDataType().getName(); + + final Set allowedShardKeyTypes = Set.of( + DataTypeDefinition.TEXT, + DataTypeDefinition.DATE, + DataTypeDefinition.INT, + DataTypeDefinition.LONG); + + + if (!shardPropertyType.equals(DataTypeDefinition.TEXT) + && !shardPropertyType.equals(DataTypeDefinition.DATE) + && !shardPropertyType.equals(DataTypeDefinition.DATETIME) + && !shardPropertyType.equals(DataTypeDefinition.INT) + && !shardPropertyType.equals(DataTypeDefinition.LONG)) { throw new AlfrescoRuntimeException("Unsupported shard property type: "+(pdef.getDataType().getName() + " for " +nodeParameters.getShardProperty())); } + shardPropertQName = pdef.getName(); } - - List nodes = solrDAO.getNodes(nodeParameters, shardPropertQName); + + + List nodes = solrDAO.getNodes(nodeParameters, shardPropertQName, shardPropertyType); for (Node node : nodes) { @@ -385,7 +403,6 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent } - callback.handleNode(node); } } diff --git a/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/solr-common-SqlMap.xml b/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/solr-common-SqlMap.xml index c7744bc5fc..94b8d92638 100644 --- a/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/solr-common-SqlMap.xml +++ b/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/solr-common-SqlMap.xml @@ -139,8 +139,11 @@ node.audit_modifier as shard_key + + shardkey.long_value as shard_key + - shardkey.string_value as shard_key + shardkey.string_value as shard_key from diff --git a/src/test/java/org/alfresco/repo/domain/solr/SOLRDAOTest.java b/src/test/java/org/alfresco/repo/domain/solr/SOLRDAOTest.java index 564d2ed616..feffccbb2d 100644 --- a/src/test/java/org/alfresco/repo/domain/solr/SOLRDAOTest.java +++ b/src/test/java/org/alfresco/repo/domain/solr/SOLRDAOTest.java @@ -103,7 +103,7 @@ public class SOLRDAOTest extends TestCase @Override public List execute() throws Throwable { - return solrDAO.getNodes(nodeParameters, null); + return solrDAO.getNodes(nodeParameters, null, null); } }, true); } diff --git a/src/test/java/org/alfresco/repo/search/impl/solr/DbOrIndexSwitchingQueryLanguageTest.java b/src/test/java/org/alfresco/repo/search/impl/solr/DbOrIndexSwitchingQueryLanguageTest.java index 97df17e0ba..859cc157a4 100644 --- a/src/test/java/org/alfresco/repo/search/impl/solr/DbOrIndexSwitchingQueryLanguageTest.java +++ b/src/test/java/org/alfresco/repo/search/impl/solr/DbOrIndexSwitchingQueryLanguageTest.java @@ -91,7 +91,7 @@ public class DbOrIndexSwitchingQueryLanguageTest when(indexQueryLang.executeQuery(argThat(isSearchParamsSinceTxId(null)))).thenReturn(indexResults); when(indexResults.getLastIndexedTxId()).thenReturn(80L); when(dbQueryLang.executeQuery(argThat(isSearchParamsSinceTxId(80L)))).thenReturn(dbResults); - when(solrDAO.getNodes(argThat(isNodeParamsFromTxnId(81L)), eq(null))).thenReturn(changedNodes); + when(solrDAO.getNodes(argThat(isNodeParamsFromTxnId(81L)), eq(null), eq(null))).thenReturn(changedNodes); searchParameters.setQueryConsistency(QueryConsistency.HYBRID);