use of org.teiid.metadata.MetadataException in project teiid by teiid.
the class FunctionTree method createFunctionDescriptor.
private FunctionDescriptor createFunctionDescriptor(FunctionMetadataSource source, FunctionMethod method, Class<?>[] types, boolean system) {
// Get return type
FunctionParameter outputParam = method.getOutputParameter();
Class<?> outputType = null;
if (outputParam != null) {
outputType = DataTypeManager.getDataTypeClass(outputParam.getRuntimeType());
}
List<Class<?>> inputTypes = new ArrayList<Class<?>>(Arrays.asList(types));
boolean hasWrappedArg = false;
if (!system) {
for (int i = 0; i < types.length; i++) {
if (types[i] == DataTypeManager.DefaultDataClasses.VARBINARY) {
hasWrappedArg = true;
inputTypes.set(i, byte[].class);
}
}
}
if (method.isVarArgs()) {
inputTypes.set(inputTypes.size() - 1, DataTypeManager.getArrayType(inputTypes.get(inputTypes.size() - 1)));
}
Method invocationMethod = method.getMethod();
boolean requiresContext = false;
// Defect 20007 - Ignore the invocation method if pushdown is not required.
if (validateClass && (method.getPushdown() == PushDown.CAN_PUSHDOWN || method.getPushdown() == PushDown.CANNOT_PUSHDOWN)) {
if (invocationMethod == null) {
if (method.getInvocationClass() == null || method.getInvocationMethod() == null) {
throw new MetadataException(QueryPlugin.Event.TEIID31123, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31123, method.getName()));
}
try {
Class<?> methodClass = source.getInvocationClass(method.getInvocationClass());
ReflectionHelper helper = new ReflectionHelper(methodClass);
try {
invocationMethod = helper.findBestMethodWithSignature(method.getInvocationMethod(), inputTypes);
} catch (NoSuchMethodException e) {
inputTypes.add(0, CommandContext.class);
invocationMethod = helper.findBestMethodWithSignature(method.getInvocationMethod(), inputTypes);
requiresContext = true;
}
} catch (ClassNotFoundException e) {
throw new MetadataException(QueryPlugin.Event.TEIID30387, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30387, method.getName(), method.getInvocationClass()));
} catch (NoSuchMethodException e) {
throw new MetadataException(QueryPlugin.Event.TEIID30388, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30388, method, method.getInvocationClass(), method.getInvocationMethod()));
} catch (Exception e) {
throw new MetadataException(QueryPlugin.Event.TEIID30389, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30389, method, method.getInvocationClass(), method.getInvocationMethod()));
}
} else {
requiresContext = (invocationMethod.getParameterTypes().length > 0 && org.teiid.CommandContext.class.isAssignableFrom(invocationMethod.getParameterTypes()[0]));
}
if (invocationMethod != null) {
// Check return type is non void
Class<?> methodReturn = invocationMethod.getReturnType();
if (method.getAggregateAttributes() == null && methodReturn.equals(Void.TYPE)) {
throw new MetadataException(QueryPlugin.Event.TEIID30390, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30390, method.getName(), invocationMethod));
}
// Check that method is public
int modifiers = invocationMethod.getModifiers();
if (!Modifier.isPublic(modifiers)) {
throw new MetadataException(QueryPlugin.Event.TEIID30391, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30391, method.getName(), invocationMethod));
}
// Check that method is static
if (!Modifier.isStatic(modifiers)) {
if (method.getAggregateAttributes() == null) {
throw new MetadataException(QueryPlugin.Event.TEIID30392, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30392, method.getName(), invocationMethod));
}
} else if (method.getAggregateAttributes() != null) {
throw new MetadataException(QueryPlugin.Event.TEIID30600, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30600, method.getName(), invocationMethod));
}
if (method.getAggregateAttributes() != null && !(UserDefinedAggregate.class.isAssignableFrom(invocationMethod.getDeclaringClass()))) {
throw new MetadataException(QueryPlugin.Event.TEIID30601, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30601, method.getName(), method.getInvocationClass(), UserDefinedAggregate.class.getName()));
}
try {
// turn off access checks for a small performance boost
invocationMethod.setAccessible(true);
} catch (SecurityException e) {
// just ignore
}
method.setMethod(invocationMethod);
}
}
FunctionDescriptor result = new FunctionDescriptor(method, types, outputType, invocationMethod, requiresContext, source.getClassLoader());
if (validateClass && method.getAggregateAttributes() != null && (method.getPushdown() == PushDown.CAN_PUSHDOWN || method.getPushdown() == PushDown.CANNOT_PUSHDOWN)) {
try {
result.newInstance();
} catch (FunctionExecutionException e) {
// should only happen if the method is null / not found
throw new MetadataException(QueryPlugin.Event.TEIID30387, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30387, method.getName(), method.getInvocationClass()));
}
}
result.setHasWrappedArgs(hasWrappedArg);
return result;
}
use of org.teiid.metadata.MetadataException in project teiid by teiid.
the class VDBRepository method finishDeployment.
public void finishDeployment(String name, String version) {
VDBKey key = new VDBKey(name, version);
CompositeVDB v = this.vdbRepo.get(key);
if (v == null) {
return;
}
VDBMetaData metadataAwareVDB = v.getVDB();
if (v.getOriginalVDB().getStatus() == Status.FAILED) {
if (v.getOriginalVDB() != metadataAwareVDB && metadataAwareVDB.getStatus() == Status.LOADING) {
metadataAwareVDB.setStatus(Status.FAILED);
}
return;
}
synchronized (metadataAwareVDB) {
try {
try {
v.metadataLoadFinished(allowEnv);
} catch (MetadataException e) {
// $NON-NLS-1$
LogManager.logWarning(LogConstants.CTX_RUNTIME, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version, e.getMessage()));
if (!metadataAwareVDB.isPreview()) {
ValidatorReport report = new ValidatorReport();
report.addItem(new ValidatorFailure(e.getMessage()));
if (!processMetadataValidatorReport(key, report)) {
metadataAwareVDB.setStatus(Status.FAILED);
notifyFinished(name, version, v);
return;
}
}
}
MetadataStore store = metadataAwareVDB.removeAttachment(MetadataStore.class);
ValidatorReport report = new MetadataValidator(store.getDatatypes(), QueryParser.getQueryParser()).validate(metadataAwareVDB, store);
if (report.hasItems()) {
LogManager.logWarning(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version, report.getItems().iterator().next()));
if (!metadataAwareVDB.isPreview() && !processMetadataValidatorReport(key, report)) {
metadataAwareVDB.setStatus(Status.FAILED);
notifyFinished(name, version, v);
return;
}
}
validateDataSources(metadataAwareVDB);
metadataAwareVDB.setStatus(Status.ACTIVE);
// for replication of events, temp tables and mat views
GlobalTableStore gts = CompositeGlobalTableStore.createInstance(v, this.bufferManager, this.objectReplictor);
metadataAwareVDB.addAttchment(GlobalTableStore.class, gts);
if (this.databaseStore != null) {
metadataAwareVDB.addAttchment(DatabaseStore.class, this.databaseStore);
}
notifyFinished(name, version, v);
} finally {
if (metadataAwareVDB.getStatus() != Status.ACTIVE && metadataAwareVDB.getStatus() != Status.FAILED) {
// guard against an unexpected exception - probably bad validation logic
metadataAwareVDB.setStatus(Status.FAILED);
notifyFinished(name, version, v);
}
}
}
}
use of org.teiid.metadata.MetadataException in project teiid by teiid.
the class AbstractVDBDeployer method processVDBDDL.
private void processVDBDDL(final VDBMetaData vdb, final MetadataStore vdbMetadataStore, final ConnectorManagerRepository cmr, final VDBResources vdbResources) {
if (vdb.getStatus() == Status.FAILED) {
return;
}
String ddl = vdb.getPropertyValue(VDBMetaData.TEIID_DDL);
if (ddl != null) {
final Database database = DatabaseUtil.convert(vdb, vdbMetadataStore);
CompositeMetadataStore compositeStore = new CompositeMetadataStore(vdbMetadataStore);
final TransformationMetadata metadata = new TransformationMetadata(vdb, compositeStore, null, getVDBRepository().getSystemFunctionManager().getSystemFunctions(), null);
DeploymentBasedDatabaseStore deploymentStore = new DeploymentBasedDatabaseStore(getVDBRepository()) {
@Override
protected TransformationMetadata getTransformationMetadata() {
return metadata;
}
@Override
public void importSchema(String schemaName, String serverType, String serverName, String foreignSchemaName, List<String> includeTables, List<String> excludeTables, Map<String, String> properties) {
ModelMetaData model = vdb.getModel(schemaName);
MetadataFactory factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
factory.getModelProperties().putAll(model.getPropertiesMap());
factory.getModelProperties().putAll(properties);
if (!includeTables.isEmpty()) {
// $NON-NLS-1$
factory.getModelProperties().put("importer.includeTables", StringUtil.join(includeTables, ","));
}
if (!excludeTables.isEmpty()) {
// $NON-NLS-1$
factory.getModelProperties().put("importer.excludeTables", StringUtil.join(excludeTables, ","));
}
factory.setParser(new QueryParser());
if (vdbResources != null) {
factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
}
MetadataRepository baseRepo = model.getAttachment(MetadataRepository.class);
MetadataRepository metadataRepository;
try {
metadataRepository = getMetadataRepository(serverType);
if (metadataRepository == null) {
throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), serverType));
}
} catch (VirtualDatabaseException e1) {
throw new MetadataException(e1);
}
metadataRepository = new ChainingMetadataRepository(Arrays.asList(new MetadataRepositoryWrapper(metadataRepository, null), baseRepo));
ExecutionFactory ef = null;
Object cf = null;
Exception te = null;
for (ConnectorManager cm : getConnectorManagers(model, cmr)) {
if (te != null) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_RUNTIME, te, "Failed to get metadata, trying next source.");
te = null;
}
try {
if (cm != null) {
ef = cm.getExecutionFactory();
cf = cm.getConnectionFactory();
}
} catch (TranslatorException e) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_RUNTIME, e, "Failed to get a connection factory for metadata load.");
}
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_RUNTIME, MessageLevel.TRACE)) {
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logTrace(LogConstants.CTX_RUNTIME, "CREATE SCHEMA", factory.getSchema().getName(), ";\n", DDLStringVisitor.getDDLString(factory.getSchema(), null, null));
}
try {
metadataRepository.loadMetadata(factory, ef, cf);
break;
} catch (Exception e) {
te = e;
factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
factory.getModelProperties().putAll(model.getPropertiesMap());
factory.getModelProperties().putAll(properties);
factory.setParser(new QueryParser());
if (vdbResources != null) {
factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
}
}
}
if (te != null) {
if (te instanceof RuntimeException) {
throw (RuntimeException) te;
}
throw new MetadataException(te);
}
}
};
deploymentStore.startEditing(false);
deploymentStore.databaseCreated(database);
deploymentStore.databaseSwitched(database.getName(), database.getVersion());
deploymentStore.setMode(Mode.SCHEMA);
try {
QueryParser.getQueryParser().parseDDL(deploymentStore, new StringReader(ddl));
} finally {
deploymentStore.stopEditing();
}
DatabaseUtil.copyDatabaseGrantsAndRoles(database, vdb);
}
}
Aggregations