use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class ValidationVisitor method visit.
public void visit(Insert obj) {
validateGroupSupportsUpdate(obj.getGroup());
validateInsert(obj);
try {
if (obj.isUpsert()) {
Collection keys = getMetadata().getUniqueKeysInGroup(obj.getGroup().getMetadataID());
if (keys.isEmpty()) {
handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31132, obj.getGroup()), obj);
} else {
Set<Object> keyCols = new LinkedHashSet<Object>(getMetadata().getElementIDsInKey(keys.iterator().next()));
for (ElementSymbol es : obj.getVariables()) {
keyCols.remove(es.getMetadataID());
}
if (!keyCols.isEmpty()) {
handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31133, obj.getGroup(), obj.getVariables()), obj);
}
}
}
} catch (QueryMetadataException e1) {
handleException(e1);
} catch (TeiidComponentException e1) {
handleException(e1);
}
if (obj.getQueryExpression() != null) {
validateMultisourceInsert(obj.getGroup());
}
if (obj.getUpdateInfo() != null && obj.getUpdateInfo().isInherentInsert()) {
validateUpdate(obj, Command.TYPE_INSERT, obj.getUpdateInfo());
try {
if (obj.getUpdateInfo().findInsertUpdateMapping(obj, false) == null) {
handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30376, obj.getVariables()), obj);
}
} catch (QueryValidatorException e) {
handleValidationError(e.getMessage(), obj);
}
}
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class ValidationVisitor method validateInto.
private void validateInto(LanguageObject query, List<Expression> symbols, GroupSymbol intoGroup) {
try {
List elementIDs = getMetadata().getElementIDsInGroupID(intoGroup.getMetadataID());
// Check if there are too many elements in the SELECT clause
if (symbols.size() != elementIDs.size()) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.select_into_wrong_elements", new Object[] { new Integer(elementIDs.size()), new Integer(symbols.size()) }), query);
return;
}
for (int symbolNum = 0; symbolNum < symbols.size(); symbolNum++) {
Expression symbol = symbols.get(symbolNum);
Object elementID = elementIDs.get(symbolNum);
// Check if supports updates
if (!getMetadata().elementSupports(elementID, SupportConstants.Element.UPDATE)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.element_updates_not_allowed", getMetadata().getFullName(elementID)), intoGroup);
}
Class<?> symbolType = symbol.getType();
String symbolTypeName = DataTypeManager.getDataTypeName(symbolType);
String targetTypeName = getMetadata().getElementRuntimeTypeName(elementID);
if (symbolTypeName.equals(targetTypeName)) {
continue;
}
if (!DataTypeManager.isImplicitConversion(symbolTypeName, targetTypeName)) {
// If there's no implicit conversion between the two
Object[] params = new Object[] { symbolTypeName, targetTypeName, new Integer(symbolNum + 1), query };
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.select_into_no_implicit_conversion", params), query);
continue;
}
}
} catch (TeiidComponentException e) {
handleException(e, query);
}
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class Validator method executeValidation.
private static final void executeValidation(LanguageObject object, final QueryMetadataInterface metadata, final AbstractValidationVisitor visitor) throws TeiidComponentException {
// Reset visitor
visitor.reset();
visitor.setMetadata(metadata);
setTempMetadata(metadata, visitor, object);
PreOrderNavigator nav = new PreOrderNavigator(visitor) {
protected void visitNode(LanguageObject obj) {
QueryMetadataInterface previous = visitor.getMetadata();
setTempMetadata(metadata, visitor, obj);
super.visitNode(obj);
visitor.setMetadata(previous);
}
@Override
protected void preVisitVisitor(LanguageObject obj) {
super.preVisitVisitor(obj);
visitor.stack.add(obj);
}
@Override
protected void postVisitVisitor(LanguageObject obj) {
visitor.stack.pop();
}
};
object.acceptVisitor(nav);
// If an error occurred, throw an exception
TeiidComponentException e = visitor.getException();
if (e != null) {
throw e;
}
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class GlobalTableStoreImpl method getState.
@Override
public void getState(String stateId, OutputStream ostream) {
try {
ObjectOutputStream oos = new ObjectOutputStream(ostream);
sendTable(stateId, oos, false);
oos.close();
} catch (IOException e) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30220, e);
} catch (TeiidComponentException e) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30221, e);
}
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class TempTableDataManager method registerQuery.
private TupleSource registerQuery(final CommandContext context, final TempTableStore contextStore, final Query query) {
final GroupSymbol group = query.getFrom().getGroups().get(0);
if (!group.isTempGroupSymbol()) {
return null;
}
final String tableName = group.getNonCorrelationName();
if (group.isGlobalTable()) {
TempMetadataID matTableId = (TempMetadataID) group.getMetadataID();
final GlobalTableStore globalStore = getGlobalStore(context, matTableId);
final MatTableInfo info = globalStore.getMatTableInfo(tableName);
return new ProxyTupleSource() {
Future<Void> moreWork = null;
TupleSource loadingTupleSource;
DQPWorkContext newWorkContext;
@Override
protected TupleSource createTupleSource() throws TeiidComponentException, TeiidProcessingException {
if (loadingTupleSource != null) {
load();
} else {
boolean load = false;
if (!info.isUpToDate()) {
boolean invalidate = shouldInvalidate(context.getVdb());
load = globalStore.needsLoading(tableName, globalStore.getAddress(), true, false, info.isValid() && invalidate);
if (load) {
load = globalStore.needsLoading(tableName, globalStore.getAddress(), false, false, info.isValid() && invalidate);
}
if (!load) {
synchronized (info) {
if (!info.isUpToDate()) {
RequestWorkItem workItem = context.getWorkItem();
info.addWaiter(workItem);
if (moreWork != null) {
moreWork.cancel(false);
}
// fail-safe - attempt again in 10 seconds
moreWork = workItem.scheduleWork(10000);
// $NON-NLS-1$
throw BlockedException.block("Blocking on mat view load", tableName);
}
}
} else {
if (!info.isValid() || executor == null) {
// TODO: we should probably do all loads using a temp session
if (info.getVdbMetaData() != null && context.getDQPWorkContext() != null && !info.getVdbMetaData().getFullName().equals(context.getDQPWorkContext().getVDB().getFullName())) {
assert executor != null;
// load with by pretending we're in the imported vdb
newWorkContext = createWorkContext(context, info.getVdbMetaData());
CommandContext newContext = context.clone();
newContext.setNewVDBState(newWorkContext);
loadingTupleSource = loadGlobalTable(newContext, group, tableName, newContext.getGlobalTableStore());
} else {
loadingTupleSource = loadGlobalTable(context, group, tableName, globalStore);
}
load();
} else {
loadViaRefresh(context, tableName, context.getDQPWorkContext().getVDB(), info);
}
}
}
}
TempTable table = globalStore.getTempTable(tableName);
context.accessedDataObject(group.getMetadataID());
if (context.isParallel() && query.getCriteria() == null && query.getOrderBy() != null && table.getRowCount() > MIN_ASYNCH_SIZE) {
return new AsyncTupleSource(new Callable<TupleSource>() {
@Override
public TupleSource call() throws Exception {
synchronized (this) {
TupleSource result = table.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy());
cancelMoreWork();
return result;
}
}
}, context);
}
TupleSource result = table.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy());
cancelMoreWork();
return result;
}
private void load() throws TeiidComponentException, TeiidProcessingException {
try {
if (newWorkContext != null) {
newWorkContext.runInContext(new Callable<Void>() {
@Override
public Void call() throws Exception {
loadingTupleSource.nextTuple();
return null;
}
});
} else {
loadingTupleSource.nextTuple();
}
} catch (Throwable e) {
rethrow(e);
}
}
private void cancelMoreWork() {
if (moreWork != null) {
moreWork.cancel(false);
moreWork = null;
}
}
@Override
public void closeSource() {
if (loadingTupleSource != null) {
loadingTupleSource.closeSource();
}
super.closeSource();
cancelMoreWork();
}
};
}
// it's not expected for a blocked exception to bubble up from here, so return a tuplesource to perform getOrCreateTempTable
return new ProxyTupleSource() {
@Override
protected TupleSource createTupleSource() throws TeiidComponentException, TeiidProcessingException {
TempTableStore tts = contextStore;
TempTable tt = tts.getOrCreateTempTable(tableName, query, bufferManager, true, false, context, group);
if (context.getDataObjects() != null) {
Object id = RelationalPlanner.getTrackableGroup(group, context.getMetadata());
if (id != null) {
context.accessedDataObject(id);
}
}
if (context.isParallel() && query.getCriteria() == null && query.getOrderBy() != null && tt.getRowCount() > MIN_ASYNCH_SIZE) {
return new AsyncTupleSource(new Callable<TupleSource>() {
@Override
public TupleSource call() throws Exception {
synchronized (this) {
return tt.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy());
}
}
}, context);
}
return tt.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy());
}
};
}
Aggregations