You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2017/02/15 15:04:54 UTC
svn commit: r1783112 - in
/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src:
main/java/org/apache/chemistry/opencmis/inmemory/
main/java/org/apache/chemistry/opencmis/inmemory/query/
main/java/org/apache/chemist...
Author: jens
Date: Wed Feb 15 15:04:54 2017
New Revision: 1783112
URL: http://svn.apache.org/viewvc?rev=1783112&view=rev
Log:
InMemory-Server: add a flag to make relaxed parsing optional and update tests
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/StoreManager.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/AbstractQueryTest.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTypesTest.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java?rev=1783112&r1=1783111&r2=1783112&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java Wed Feb 15 15:04:54 2017
@@ -47,6 +47,7 @@ public final class ConfigConstants {
public static final String MAX_CONTENT_SIZE_KB = "InMemoryServer.MaxContentSizeKB";
public static final String CLEAN_REPOSITORY_INTERVAL = "InMemoryServer.CleanIntervalMinutes";
public static final String DEPLOYMENT_TIME = "InMemoryServer.DeploymentTime";
+ public static final String PARSER_MODE = "InMemoryServer.ParserMode";
private ConfigConstants() {
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java?rev=1783112&r1=1783111&r2=1783112&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java Wed Feb 15 15:04:54 2017
@@ -87,10 +87,12 @@ public class InMemoryQueryProcessor {
private ObjectStoreImpl objStore;
private List<TypeDefinition> secondaryTypeIds;
private CallContext callContext;
+ private boolean relaxedParserMode;
- public InMemoryQueryProcessor(ObjectStoreImpl objStore, CallContext ctx) {
+ public InMemoryQueryProcessor(ObjectStoreImpl objStore, CallContext ctx, boolean relaxedParserMode) {
this.objStore = objStore;
this.callContext = ctx;
+ this.relaxedParserMode = relaxedParserMode;
}
/**
@@ -147,7 +149,12 @@ public class InMemoryQueryProcessor {
* type manager for the repository
*/
public void processQueryAndCatchExc(String statement, TypeManager tm) {
- QueryUtilStrict queryUtil = new QueryUtilStrict(statement, tm, null);
+ QueryUtilStrict queryUtil;
+ if (relaxedParserMode) {
+ queryUtil = new QueryUtilStrict(statement, tm, null, true, QueryObject.ParserMode.MODE_ALLOW_RELAXED_SELECT);
+ } else {
+ queryUtil = new QueryUtilStrict(statement, tm, null);
+ }
queryUtil.processStatementUsingCmisExceptions();
CmisQueryWalker walker = queryUtil.getWalker();
queryObj = queryUtil.getQueryObject();
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java?rev=1783112&r1=1783111&r2=1783112&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java Wed Feb 15 15:04:54 2017
@@ -240,6 +240,12 @@ public class InMemoryServiceFactoryImpl
TypeManager tmc = typeManager;
importTypesFromFile(tmc, typeDefsFileName);
}
+
+ // check if relaxed parser mode is configured (only for unit tests)
+ String parserMode = parameters.get(ConfigConstants.PARSER_MODE);
+ if (null != parserMode) {
+ storeManager.addFlag(parserMode);
+ }
return created;
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/StoreManager.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/StoreManager.java?rev=1783112&r1=1783111&r2=1783112&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/StoreManager.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/StoreManager.java Wed Feb 15 15:04:54 2017
@@ -84,6 +84,11 @@ public interface StoreManager {
void createAndInitRepository(String repositoryId, String typeCreatorClassName);
/**
+ * Add option to specify runtime options
+ */
+ void addFlag(String flag);
+
+ /**
* Retrieve a list with all type definitions.
*
* @param repositoryId
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java?rev=1783112&r1=1783111&r2=1783112&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java Wed Feb 15 15:04:54 2017
@@ -109,6 +109,9 @@ public class StoreManagerImpl implements
* Map from repository id to a object store.
*/
private final Map<String, ObjectStore> fMapRepositoryToObjectStore = new HashMap<String, ObjectStore>();
+
+ private boolean relaxedParserMode = false;
+
public ObjectStoreImpl getStore(String repositoryId) {
return (ObjectStoreImpl) fMapRepositoryToObjectStore.get(repositoryId);
@@ -148,6 +151,13 @@ public class StoreManagerImpl implements
}
@Override
+ public void addFlag(String flag) {
+ if (flag.trim().equalsIgnoreCase("ParserModeRelaxed")) {
+ relaxedParserMode = true;
+ }
+ }
+
+ @Override
public ObjectStore getObjectStore(String repositoryId) {
return fMapRepositoryToObjectStore.get(repositoryId);
}
@@ -576,7 +586,7 @@ public class StoreManagerImpl implements
TypeManager tm = getTypeManager(repositoryId);
ObjectStore objectStore = getObjectStore(repositoryId);
- InMemoryQueryProcessor queryProcessor = new InMemoryQueryProcessor(getStore(repositoryId), callContext);
+ InMemoryQueryProcessor queryProcessor = new InMemoryQueryProcessor(getStore(repositoryId), callContext, relaxedParserMode);
ObjectList objList = queryProcessor.query(tm, objectStore, user, repositoryId, statement, searchAllVersions,
includeAllowableActions, includeRelationships, renditionFilter, maxItems, skipCount);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java?rev=1783112&r1=1783111&r2=1783112&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java Wed Feb 15 15:04:54 2017
@@ -110,12 +110,19 @@ public class AbstractServiceTest {
}
protected void setUp() {
+ setUp(false);
+ }
+
+ protected void setUp(boolean relaxedParserMode) {
LOG.debug("Initializing InMemory Test with type creator class: " + fTypeCreatorClassName);
Map<String, String> parameters = new HashMap<String, String>();
// attach repository info to the session:
parameters.put(ConfigConstants.TYPE_CREATOR_CLASS, fTypeCreatorClassName);
parameters.put(ConfigConstants.REPOSITORY_ID, REPOSITORY_ID);
+ if (relaxedParserMode) {
+ parameters.put(ConfigConstants.PARSER_MODE, "ParserModeRelaxed");
+ }
// give subclasses a chance to provide additional parameters for special
// tests
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/AbstractQueryTest.java?rev=1783112&r1=1783111&r2=1783112&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/AbstractQueryTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/AbstractQueryTest.java Wed Feb 15 15:04:54 2017
@@ -86,6 +86,13 @@ public abstract class AbstractQueryTest
return queryUtil.getWalker();
}
+ protected CmisQueryWalker getWalker(String statement, QueryObject.ParserMode mode) throws RecognitionException {
+ QueryUtilStrict queryUtil = new QueryUtilStrict(statement, typeManager, predicateWalker, true, mode);
+ queryUtil.processStatementUsingCmisExceptions();
+ queryObj = queryUtil.getQueryObject();
+ return queryUtil.getWalker();
+ }
+
// Helper to create some types for testing
protected List<TypeDefinition> createTypes() {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java?rev=1783112&r1=1783111&r2=1783112&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java Wed Feb 15 15:04:54 2017
@@ -59,14 +59,18 @@ public class EvalQueryTest extends Abstr
@Override
@Before
public void setUp() {
+ setUp(false);
+ }
+
+ protected void setUp(boolean parserMode) {
// initialize query object with type manager
super.setTypeCreatorClass(UnitTestTypeSystemCreator.class.getName());
- super.setUp();
+ super.setUp(parserMode);
// create test data
dataCreator = new QueryTestDataCreator(fRepositoryId, fRootFolderId, fObjSvc, fVerSvc);
dataCreator.createBasicTestData();
}
-
+
@Override
@After
public void tearDown() {
@@ -1103,6 +1107,7 @@ public class EvalQueryTest extends Abstr
@Test
public void testAskForSecondaryPropertyOnSimpleQuery() {
log.debug("Start testAskForSecondaryPropertyOnSimpleQuery...");
+ setUp(true); // force relaxed parser mode
dataCreator.createSecondaryTestDocuments();
String statement = "SELECT cmis:name, cmis:objectId, " + UnitTestTypeSystemCreator.SECONDARY_INTEGER_PROP
+ " AS SecInt, " + UnitTestTypeSystemCreator.SECONDARY_STRING_PROP + " FROM " + COMPLEX_TYPE +
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTypesTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTypesTest.java?rev=1783112&r1=1783111&r2=1783112&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTypesTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTypesTest.java Wed Feb 15 15:04:54 2017
@@ -38,6 +38,7 @@ import org.apache.chemistry.opencmis.ser
import org.apache.chemistry.opencmis.server.support.query.CmisQueryWalker;
import org.apache.chemistry.opencmis.server.support.query.CmisSelector;
import org.apache.chemistry.opencmis.server.support.query.ColumnReference;
+import org.apache.chemistry.opencmis.server.support.query.QueryObject;
import org.apache.chemistry.opencmis.server.support.query.QueryObject.SortSpec;
import org.junit.After;
import org.junit.Before;
@@ -127,10 +128,22 @@ public class QueryTypesTest extends Abst
}
@Test
- public void resolveTypesTest7() throws Exception {
+ public void resolveTypesTest7StrictSelect() {
String statement = "SELECT UnknownProperty FROM BookType WHERE ISBN = '100'";
+ try {
+ verifyResolveSelect(statement);
+ fail("Select of unknown property in type should fail.");
+ } catch (Exception e) {
+ assertTrue(e instanceof CmisInvalidArgumentException);
+ assertTrue(e.toString().contains("is not a property query name in any"));
+ }
+ }
- CmisQueryWalker walker = getWalker(statement);
+ @Test
+ public void resolveTypesTest7RelaxedSelect() throws Exception {
+ String statement = "SELECT UnknownProperty FROM BookType WHERE ISBN = '100'";
+
+ CmisQueryWalker walker = getWalker(statement, QueryObject.ParserMode.MODE_ALLOW_RELAXED_SELECT);
assertNotNull(queryObj);
assertNotNull(walker);
Map<String, String> types = queryObj.getTypes();
@@ -164,10 +177,11 @@ public class QueryTypesTest extends Abst
verifyResolveSelect(statement);
}
- private void verifyResolveSelect(String statement) throws Exception {
+ private void verifyResolveSelect(String statement, QueryObject.ParserMode mode) throws Exception {
CmisQueryWalker walker = getWalker(statement);
assertNotNull(queryObj);
assertNotNull(walker);
+ queryObj.setSelectMode(mode);
Map<String, String> types = queryObj.getTypes();
assertTrue(1 == types.size());
List<CmisSelector> selects = queryObj.getSelectReferences();
@@ -181,6 +195,10 @@ public class QueryTypesTest extends Abst
}
}
+ private void verifyResolveSelect(String statement) throws Exception {
+ verifyResolveSelect(statement, QueryObject.ParserMode.MODE_STRICT);
+ }
+
@Test
public void resolveTypesWithTwoFromsQualified() throws Exception {
String statement = "SELECT BookType.Title, MyDocType.MyStringProp FROM BookType JOIN MyDocType WHERE BookType.ISBN = '100'";