public LocalProfile getConnectionProfile() { if (connectionProfile == null) { try { connectionProfile = (LocalProfile) ReflectionHelper.create( "org.teiid.jdbc.jboss.ModuleLocalProfile", null, //$NON-NLS-1$ getClass().getClassLoader()); } catch (TeiidException e) { throw new TeiidRuntimeException(e); } } return connectionProfile; }
public LocalProfile getConnectionProfile() { if (connectionProfile == null) { try { connectionProfile = (LocalProfile) ReflectionHelper.create( "org.teiid.jdbc.jboss.ModuleLocalProfile", null, //$NON-NLS-1$ getClass().getClassLoader()); } catch (TeiidException e) { throw new TeiidRuntimeException(e); } } return connectionProfile; }
public static String getSpanContext() { if (INJECTOR == null) { try { INJECTOR = (Injector) ReflectionHelper.create("org.teiid.jdbc.tracing.GlobalTracerInjector", null, TracingHelper.class.getClassLoader()); //$NON-NLS-1$ } catch (Throwable e) { //must catch both Error and Exception logger.log(Level.FINE, "Unable to load opentracing libraries, propagation will not be used", e); //$NON-NLS-1$ } if (INJECTOR == null) { INJECTOR = new Injector() { @Override public String getSpanContext() { return null; } }; } } return INJECTOR.getSpanContext(); }
public static String getSpanContext() { if (INJECTOR == null) { try { INJECTOR = (Injector) ReflectionHelper.create("org.teiid.jdbc.tracing.GlobalTracerInjector", null, TracingHelper.class.getClassLoader()); //$NON-NLS-1$ } catch (Throwable e) { //must catch both Error and Exception logger.log(Level.FINE, "Unable to load opentracing libraries, propagation will not be used", e); //$NON-NLS-1$ } if (INJECTOR == null) { INJECTOR = new Injector() { @Override public String getSpanContext() { return null; } }; } } return INJECTOR.getSpanContext(); }
return create(className, objArray, names, classLoader); } catch (Exception e) { throw new TeiidException(CorePlugin.Event.TEIID10033, e);
return create(className, objArray, names, classLoader); } catch (Exception e) { throw new TeiidException(CorePlugin.Event.TEIID10033, e);
@Override public ServerConnection createServerConnection(Properties info) throws TeiidException { ClassLoader tccl = Thread.currentThread().getContextClassLoader(); try { ModuleLoader callerModuleLoader = Module.getCallerModuleLoader(); if (callerModuleLoader == null) { logger.fine(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20033)); return (ServerConnection)ReflectionHelper.create("org.teiid.transport.LocalServerConnection", Arrays.asList(info, PropertiesUtils.getBooleanProperty(info, LocalProfile.USE_CALLING_THREAD, true)), Thread.currentThread().getContextClassLoader()); //$NON-NLS-1$ } final Module module = callerModuleLoader.loadModule("org.jboss.teiid"); //$NON-NLS-1$ Thread.currentThread().setContextClassLoader(module.getClassLoader()); return (ServerConnection)ReflectionHelper.create("org.teiid.transport.LocalServerConnection", Arrays.asList(info, PropertiesUtils.getBooleanProperty(info, LocalProfile.USE_CALLING_THREAD, true)), Thread.currentThread().getContextClassLoader()); //$NON-NLS-1$ } catch (ModuleLoadException e) { throw new ConnectionException(JDBCPlugin.Event.TEIID20008, e, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20008)); } finally { Thread.currentThread().setContextClassLoader(tccl); } }
public static void createPreParser(VDBMetaData deployment) throws TeiidException { String preparserClass = deployment.getPropertyValue(VDBMetaData.PREPARSER_CLASS); if (preparserClass != null) { ClassLoader vdbClassLoader = deployment.getAttachment(ClassLoader.class); PreParser preParser = (PreParser) ReflectionHelper.create(preparserClass, Collections.emptyList(), vdbClassLoader); deployment.addAttchment(PreParser.class, preParser); } }
public SQLDialect getDialect() { if (dialect == null) { String name = getHibernateDialectClassName(); if (name != null) { try { Object impl = ReflectionHelper.create(name, null, this.getClass().getClassLoader()); InvocationHandler handler = new MixinProxy(new Object[] {impl}); this.dialect = (SQLDialect) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[]{SQLDialect.class}, handler); } catch (TeiidException e) { LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, name, "could not be loaded"); //$NON-NLS-1$ } } if (dialect == null) { dialect = new DefaultSQLDialect(); } } return dialect; }
private Throwable buildException(List<String> classNames, String message, StackTraceElement[] stackTrace, String code) { String originalClass = Exception.class.getName(); if (!classNames.isEmpty()) { originalClass = classNames.get(0); } List<String> args = Arrays.asList(CorePlugin.Util.getString("ExceptionHolder.converted_exception", message, originalClass)); //$NON-NLS-1$ Throwable result = null; for (String className : classNames) { try { result = (Throwable)ReflectionHelper.create(className, args, ExceptionHolder.class.getClassLoader()); break; } catch (TeiidException e1) { // } } if (result == null) { result = new TeiidRuntimeException(args.get(0)); } else if (result instanceof TeiidException) { ((TeiidException)result).setCode(code); ((TeiidException)result).setOriginalType(classNames.get(0)); } result.setStackTrace(stackTrace); return result; }
private Throwable buildException(List<String> classNames, String message, StackTraceElement[] stackTrace, String code) { String originalClass = Exception.class.getName(); if (!classNames.isEmpty()) { originalClass = classNames.get(0); } List<String> args = Arrays.asList(CorePlugin.Util.getString("ExceptionHolder.converted_exception", message, originalClass)); //$NON-NLS-1$ Throwable result = null; for (String className : classNames) { try { result = (Throwable)ReflectionHelper.create(className, args, ExceptionHolder.class.getClassLoader()); break; } catch (TeiidException e1) { // } } if (result == null) { result = new TeiidRuntimeException(args.get(0)); } else if (result instanceof TeiidException) { ((TeiidException)result).setCode(code); ((TeiidException)result).setOriginalType(classNames.get(0)); } result.setStackTrace(stackTrace); return result; }
public static <T> T getInstance(Class<T> expectedType, String className, Collection<?> ctorObjs, Class<? extends T> defaultClass) throws TranslatorException { try { if (className == null) { if (defaultClass == null) { throw new TranslatorException(DataPlugin.Event.TEIID60004, DataPlugin.Util.gs(DataPlugin.Event.TEIID60004)); } return expectedType.cast(defaultClass.newInstance()); } return expectedType.cast(ReflectionHelper.create(className, ctorObjs, Thread.currentThread().getContextClassLoader())); } catch (TeiidException e) { throw new TranslatorException(DataPlugin.Event.TEIID60005, e); } catch (IllegalAccessException e) { throw new TranslatorException(DataPlugin.Event.TEIID60005, e); } catch(InstantiationException e) { throw new TranslatorException(DataPlugin.Event.TEIID60005, e); } }
@Test public void testCreate() throws Exception { ReflectionHelper.create(SomeClass.class.getName(), Arrays.asList(true), null); }
@Test public void testDeserializationUnknownChildException2() throws Exception { ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$ ArrayList<String> args = new ArrayList<String>(); args.add("Unknown Exception"); //$NON-NLS-1$ Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", args, cl); //$NON-NLS-1$ ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(new ExceptionHolder(obj)); oos.flush(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); ExceptionHolder holder = (ExceptionHolder)ois.readObject(); Throwable e = holder.getException(); assertTrue(e instanceof TeiidRuntimeException); assertEquals("Remote test.UnknownException: Unknown Exception", e.getMessage()); //$NON-NLS-1$ }
@Test public void testDeserializationUnknownException() throws Exception { ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$ Object obj = ReflectionHelper.create("test.Test", null, cl); //$NON-NLS-1$ ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(new ExceptionHolder(new BadException(obj))); oos.flush(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); ExceptionHolder holder = (ExceptionHolder)ois.readObject(); assertTrue(holder.getException() instanceof BadException); assertEquals("Remote org.teiid.client.util.TestExceptionHolder$BadException: null", holder.getException().getMessage()); //$NON-NLS-1$ }
if (localProfile == null) { try { localProfile = (ConnectionProfile) ReflectionHelper.create( "org.teiid.jdbc.jboss.ModuleLocalProfile", null, //$NON-NLS-1$ getClass().getClassLoader());
@Test public void testDeserializationUnknownChildException() throws Exception { ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$ Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", null, cl); //$NON-NLS-1$ obj.initCause(new SQLException("something bad happended")); //$NON-NLS-1$ ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(new ExceptionHolder(new BadException2(obj, "I have foreign exception embedded in me"))); //$NON-NLS-1$ oos.flush(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); ExceptionHolder holder = (ExceptionHolder)ois.readObject(); Throwable e = holder.getException(); assertTrue(e instanceof BadException2); assertEquals("Remote org.teiid.client.util.TestExceptionHolder$BadException2: I have foreign exception embedded in me", e.getMessage()); //$NON-NLS-1$ e = e.getCause(); assertTrue(e instanceof TeiidRuntimeException); e = e.getCause(); assertTrue(e instanceof SQLException); assertEquals("Remote java.sql.SQLException: something bad happended", e.getMessage()); //$NON-NLS-1$ }
@Test public void testSourceWarning() throws Exception { ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$ ArrayList<String> args = new ArrayList<String>(); args.add("Unknown Exception"); //$NON-NLS-1$ Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", args, cl); //$NON-NLS-1$ ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(new ExceptionHolder(new SourceWarning("x", "y", obj, true))); oos.flush(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); ExceptionHolder holder = (ExceptionHolder)ois.readObject(); SourceWarning sw = (SourceWarning)holder.getException(); assertEquals(sw.getConnectorBindingName(), "y"); assertEquals(sw.getModelName(), "x"); assertTrue(sw.isPartialResultsError()); try { ois = new ObjectInputStream(new FileInputStream(UnitTestUtil.getTestDataFile("old-exceptionholder.ser"))); holder = (ExceptionHolder)ois.readObject(); assertTrue(holder.getException() instanceof TeiidException); } finally { ois.close(); } } }
private Object handleInsert(Insert insert) throws TranslatorException { try { String entityClassName = insert.getTable().getMetadataObject().getProperty(JPAMetadataProcessor.ENTITYCLASS, false); Object entity = ReflectionHelper.create(entityClassName, null, this.executionContext.getCommandContext().getVDBClassLoader());
@Test public void testSQLExceptionChain() throws Exception { ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$ Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", null, cl); //$NON-NLS-1$ SQLException se = new SQLException("something bad happened");