diff options
3 files changed, 161 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF index 057ddc0a4d1..a217caff6f3 100644 --- a/plugins/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF @@ -19,6 +19,7 @@ Import-Package: org.eclipse.core.runtime, org.eclipse.osee.framework.logging, org.eclipse.osee.framework.plugin.core, org.eclipse.osee.framework.plugin.core.util, + org.eclipse.osee.jdbc, org.osgi.framework Export-Package: org.eclipse.osee.framework.core.client, org.eclipse.osee.framework.core.client.server diff --git a/plugins/org.eclipse.osee.framework.core.client/OSGI-INF/client.jdbc.service.xml b/plugins/org.eclipse.osee.framework.core.client/OSGI-INF/client.jdbc.service.xml new file mode 100644 index 00000000000..d6528daea93 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.client/OSGI-INF/client.jdbc.service.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" > + <implementation class="org.eclipse.osee.framework.core.client.internal.ClientJdbcServiceImpl"/> + <service> + <provide interface="org.eclipse.osee.jdbc.JdbcService"/> + </service> + <property name="osgi.binding" type="String"> +skynet.jdbc.service +activity.jdbc.service + </property> +</scr:component> diff --git a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ClientJdbcServiceImpl.java b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ClientJdbcServiceImpl.java new file mode 100644 index 00000000000..fbb9f4dcef8 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ClientJdbcServiceImpl.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.client.internal; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; +import org.eclipse.osee.framework.core.data.IDatabaseInfo; +import org.eclipse.osee.framework.core.data.OseeSessionGrant; +import org.eclipse.osee.jdbc.JdbcClient; +import org.eclipse.osee.jdbc.JdbcClientBuilder; +import org.eclipse.osee.jdbc.JdbcConstants; +import org.eclipse.osee.jdbc.JdbcServerConfig; +import org.eclipse.osee.jdbc.JdbcService; + +/** + * Temporary Service implementation until client is dynamically configured using ConfigAdmin + * + * @author Roberto E. Escobar + */ +public class ClientJdbcServiceImpl implements JdbcService { + + private final AtomicReference<JdbcClient> clientRef = new AtomicReference<JdbcClient>(); + + private final JdbcClient clientProxy = createClientProxy(); + + private String id = "N/A"; + private Set<String> bindings; + + public void start(Map<String, Object> props) { + bindings = new LinkedHashSet<String>(); + String[] values = getBindings(props); + for (String value : values) { + bindings.add(value); + } + synchronized (clientRef) { + InternalClientSessionManager instance = InternalClientSessionManager.getInstance(); + OseeSessionGrant sessionGrant = instance.getOseeSessionGrant(); + IDatabaseInfo dbInfo = sessionGrant.getDatabaseInfo(); + + JdbcClient jdbcClient = newClient(dbInfo); + clientRef.set(jdbcClient); + + id = dbInfo.getId(); + } + } + + private String[] getBindings(Map<String, Object> props) { + String[] toReturn = new String[0]; + if (props != null && !props.isEmpty()) { + Object binding = props.get(JdbcConstants.JDBC_SERVICE__OSGI_BINDING); + if (binding instanceof String) { + toReturn = new String[] {(String) binding}; + } else if (binding instanceof String[]) { + toReturn = (String[]) binding; + } + } + return toReturn; + } + + public void stop(Map<String, Object> props) { + bindings = null; + } + + private JdbcClient newClient(IDatabaseInfo dbInfo) { + JdbcClientBuilder builder = JdbcClientBuilder.newBuilder()// + .dbDriver(dbInfo.getDriver())// + .dbUri(dbInfo.getConnectionUrl())// + .dbUsername(dbInfo.getDatabaseLoginName())// + .production(dbInfo.isProduction()); + + Properties properties = dbInfo.getConnectionProperties(); + if (properties != null && !properties.isEmpty()) { + for (Entry<Object, Object> entry : properties.entrySet()) { + builder.dbParam((String) entry.getKey(), (String) entry.getValue()); + } + } + return builder.build(); + } + + @Override + public String getId() { + return id; + } + + @Override + public JdbcClient getClient() { + return clientProxy; + } + + @Override + public Set<String> getBindings() { + return bindings; + } + + @Override + public boolean hasServer() { + return false; + } + + @Override + public JdbcServerConfig getServerConfig() { + return null; + } + + @Override + public boolean isServerAlive(long waitTime) { + return false; + } + + private JdbcClient createClientProxy() { + InvocationHandler handler = new JdbcClientInvocationHandler(); + Class<?>[] types = new Class<?>[] {JdbcClient.class}; + return (JdbcClient) Proxy.newProxyInstance(this.getClass().getClassLoader(), types, handler); + } + + private final class JdbcClientInvocationHandler implements InvocationHandler { + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + try { + JdbcClient client = clientRef.get(); + return method.invoke(client, args); + } catch (Throwable ex) { + Throwable cause = ex.getCause(); + if (cause == null) { + cause = ex; + } + throw cause; + } + } + + } + +}
\ No newline at end of file |