-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(workflows): make Flowable schema upgrades idempotent to survive partial migrations #27234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1832519
32d2e8e
24621ee
aa744e9
6f9cad1
3890473
31ef20a
6324e90
96981e7
40332af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Copyright 2021 Collate | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.openmetadata.service.governance.workflows; | ||
|
|
||
| import java.io.PrintWriter; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.lang.reflect.Method; | ||
| import java.lang.reflect.Proxy; | ||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
| import java.sql.SQLFeatureNotSupportedException; | ||
| import java.sql.Statement; | ||
| import java.util.logging.Logger; | ||
| import javax.sql.DataSource; | ||
|
|
||
| /** | ||
| * A {@link DataSource} wrapper that intercepts every {@link Connection} it vends and ensures | ||
| * that all {@link Statement} variants created from that connection go through | ||
| * {@link IdempotentDdlStatement}. Only used in migration context so Flowable upgrade scripts | ||
| * skip already-existing DDL objects instead of failing. | ||
| */ | ||
| final class IdempotentDdlDataSource implements DataSource { | ||
|
|
||
| private final DataSource delegate; | ||
|
|
||
| IdempotentDdlDataSource(DataSource delegate) { | ||
| this.delegate = delegate; | ||
| } | ||
|
|
||
| @Override | ||
| public Connection getConnection() throws SQLException { | ||
| return wrapConnection(delegate.getConnection()); | ||
| } | ||
|
|
||
| @Override | ||
| public Connection getConnection(String username, String password) throws SQLException { | ||
| return wrapConnection(delegate.getConnection(username, password)); | ||
| } | ||
|
|
||
| private Connection wrapConnection(Connection real) { | ||
| return (Connection) | ||
| Proxy.newProxyInstance( | ||
| real.getClass().getClassLoader(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be tricky: we are manipulating via reflection
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mohityadav766 The alternative is a 250-line concrete Connection implementation that delegates all 40+ methods just to override 3, which is more code with no functional difference, we can go by this approach as well, ill go with your take |
||
| new Class<?>[] {Connection.class}, | ||
| (proxy, method, args) -> { | ||
| if ("createStatement".equals(method.getName())) { | ||
| Statement stmt = (Statement) invokeDelegate(method, real, args); | ||
| return new IdempotentDdlStatement(stmt, real); | ||
| } | ||
| return invokeDelegate(method, real, args); | ||
| }); | ||
|
Comment on lines
+51
to
+62
|
||
| } | ||
|
|
||
| /** | ||
| * Invokes a method on the real connection, unwrapping any {@link InvocationTargetException} | ||
| * so callers receive the original exception type (e.g. {@link SQLException}). | ||
| */ | ||
| private static Object invokeDelegate(Method method, Object target, Object[] args) | ||
| throws Throwable { | ||
| try { | ||
| return method.invoke(target, args); | ||
| } catch (InvocationTargetException e) { | ||
| throw e.getCause(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public PrintWriter getLogWriter() throws SQLException { | ||
| return delegate.getLogWriter(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setLogWriter(PrintWriter out) throws SQLException { | ||
| delegate.setLogWriter(out); | ||
| } | ||
|
|
||
| @Override | ||
| public void setLoginTimeout(int seconds) throws SQLException { | ||
| delegate.setLoginTimeout(seconds); | ||
| } | ||
|
|
||
| @Override | ||
| public int getLoginTimeout() throws SQLException { | ||
| return delegate.getLoginTimeout(); | ||
| } | ||
|
|
||
| @Override | ||
| public Logger getParentLogger() throws SQLFeatureNotSupportedException { | ||
| return delegate.getParentLogger(); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T unwrap(Class<T> iface) throws SQLException { | ||
| return delegate.unwrap(iface); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isWrapperFor(Class<?> iface) throws SQLException { | ||
| return delegate.isWrapperFor(iface); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.