use of org.teiid.query.parser.ParseInfo in project teiid by teiid.
the class TestSessionAwareCache method testSessionSpecfic.
@Test
public void testSessionSpecfic() {
SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Cachable result = Mockito.mock(Cachable.class);
id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
cache.put(id, Determinism.SESSION_DETERMINISTIC, result, null);
// make sure that in the case of session specific; we do not call prepare
// as session is local only call for distributed
Mockito.verify(result, times(0)).prepare((BufferManager) anyObject());
Object c = cache.get(id);
Mockito.verify(result, times(0)).restore((BufferManager) anyObject());
assertTrue(result == c);
}
use of org.teiid.query.parser.ParseInfo in project teiid by teiid.
the class TestSessionAwareCache method testTtl.
@Test
public void testTtl() {
SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Cachable result = Mockito.mock(Cachable.class);
// make sure defaults are returned
assertNull(cache.computeTtl(id, result, null));
assertEquals(Long.valueOf(1), cache.computeTtl(id, result, 1l));
AccessInfo ai = new AccessInfo();
Mockito.stub(result.getAccessInfo()).toReturn(ai);
Table t = new Table();
t.setProperty(DataModifiable.DATA_TTL, "2");
ai.addAccessedObject(t);
assertEquals(Long.valueOf(2), cache.computeTtl(id, result, null));
Table t1 = new Table();
Schema s = new Schema();
t1.setParent(s);
s.setProperty(DataModifiable.DATA_TTL, "0");
ai.addAccessedObject(t1);
// ensure that the min and the parent are used
assertEquals(Long.valueOf(0), cache.computeTtl(id, result, null));
}
use of org.teiid.query.parser.ParseInfo in project teiid by teiid.
the class TestSessionAwareCache method testNoScope.
@Test
public void testNoScope() {
SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Cachable result = Mockito.mock(Cachable.class);
Mockito.stub(result.prepare((BufferManager) anyObject())).toReturn(true);
Mockito.stub(result.restore((BufferManager) anyObject())).toReturn(true);
cache.put(id, Determinism.VDB_DETERMINISTIC, result, null);
// make sure that in the case of session specific; we do not call prepare
// as session is local only call for distributed
Mockito.verify(result, times(1)).prepare((BufferManager) anyObject());
id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Object c = cache.get(id);
Mockito.verify(result, times(1)).restore((BufferManager) anyObject());
assertTrue(result == c);
}
use of org.teiid.query.parser.ParseInfo in project teiid by teiid.
the class TestSessionAwareCache method testUserSpecfic.
@Test
public void testUserSpecfic() {
SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Cachable result = Mockito.mock(Cachable.class);
Mockito.stub(result.prepare((BufferManager) anyObject())).toReturn(true);
Mockito.stub(result.restore((BufferManager) anyObject())).toReturn(true);
cache.put(id, Determinism.USER_DETERMINISTIC, result, null);
// make sure that in the case of session specific; we do not call prepare
// as session is local only call for distributed
Mockito.verify(result, times(1)).prepare((BufferManager) anyObject());
id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Object c = cache.get(id);
Mockito.verify(result, times(1)).restore((BufferManager) anyObject());
assertTrue(result == c);
}
use of org.teiid.query.parser.ParseInfo in project teiid by teiid.
the class Request method parseCommand.
private Command parseCommand() throws QueryParserException {
if (requestMsg.getCommand() != null) {
return (Command) requestMsg.getCommand();
}
String[] commands = requestMsg.getCommands();
ParseInfo parseInfo = createParseInfo(this.requestMsg, this.workContext.getSession());
QueryParser queryParser = QueryParser.getQueryParser();
if (requestMsg.isPreparedStatement() || requestMsg.isCallableStatement() || !requestMsg.isBatchedUpdate()) {
String commandStr = commands[0];
if (preParser != null) {
commandStr = preParser.preParse(commandStr, this.context);
}
return queryParser.parseCommand(commandStr, parseInfo);
}
List<Command> parsedCommands = new ArrayList<Command>(commands.length);
for (int i = 0; i < commands.length; i++) {
String updateCommand = commands[i];
if (preParser != null) {
updateCommand = preParser.preParse(updateCommand, this.context);
}
parsedCommands.add(queryParser.parseCommand(updateCommand, parseInfo));
}
return new BatchedUpdateCommand(parsedCommands);
}
Aggregations