Skip to content

Commit

Permalink
0003342: Implement SymmetricDS JDBC driver wrapper for optional logging,
Browse files Browse the repository at this point in the history
stats, and other diagnostics.
  • Loading branch information
mmichalek committed Dec 20, 2017
1 parent 515e3eb commit ce4aa13
Show file tree
Hide file tree
Showing 10 changed files with 3,280 additions and 0 deletions.

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions symmetric-jdbc/src/main/java/org/jumpmind/driver/Driver.java
@@ -0,0 +1,97 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* 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.jumpmind.driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger;

public class Driver implements java.sql.Driver {

private static final String DRIVER_PREFIX = "jdbc:symds:";

static {
try {
DriverManager.registerDriver(new Driver());
} catch (Exception ex) {
throw new RuntimeException("Failed to register SymmetricDS driver", ex);
}
}

@Override
public Connection connect(String url, Properties info) throws SQLException {
if (url == null || !url.toLowerCase().startsWith(DRIVER_PREFIX)) {
return null;
}

// Properties props = setupConnectProperties(url, info);

String realUrl = getRealUrl(url);

Connection connection = DriverManager.getConnection(realUrl);

return new ConnectionWrapper(connection);
}

private String getRealUrl(String url) {
// transform "jdbc:symds:jtds:" to just jdbc:jtds:
return url.replace("symds:", "");
}

@Override
public boolean acceptsURL(String url) throws SQLException {
if (url == null) {
return false;
}

return url.toLowerCase().startsWith(DRIVER_PREFIX);
}

@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
return null;
}

@Override
public int getMajorVersion() {
return 1;
}

@Override
public int getMinorVersion() {
return 0;
}

@Override
public boolean jdbcCompliant() {
return false;
}

@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return null;
}

}
@@ -0,0 +1,61 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* 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.jumpmind.driver;


/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* 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.
*/
public class DummyInterceptor extends WrapperInterceptor {

public DummyInterceptor(Object wrapped) {
super(wrapped);
}

@Override
public InterceptResult preExecute(String methodName, Object... parameters) {
InterceptResult interceptResult = new InterceptResult();
return interceptResult;
}

@Override
public InterceptResult postExecute(String methodName, Object result, long startTime, long endTime, Object... parameters) {
InterceptResult interceptResult = new InterceptResult();
return interceptResult;
}
}
@@ -0,0 +1,61 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* 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.jumpmind.driver;

/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* 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.
*/
public class InterceptResult {

private boolean intercepted;
private Object interceptResult;

public boolean isIntercepted() {
return intercepted;
}
public void setIntercepted(boolean intercepted) {
this.intercepted = intercepted;
}
public Object getInterceptResult() {
return interceptResult;
}
public void setInterceptResult(Object interceptResult) {
this.interceptResult = interceptResult;
}

}

0 comments on commit ce4aa13

Please sign in to comment.