Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2014-12-09 19:22:16 -0500
committerAngel Avila2014-12-09 19:22:16 -0500
commit32591a5994b1928d1631767ec615ba5377fc3f39 (patch)
treecae753cda7a1098b848bf616c326d61df5e8bec7 /plugins
parentc70a4475ee01da357750842ca7fa52728cce64cb (diff)
downloadorg.eclipse.osee-32591a5994b1928d1631767ec615ba5377fc3f39.tar.gz
org.eclipse.osee-32591a5994b1928d1631767ec615ba5377fc3f39.tar.xz
org.eclipse.osee-32591a5994b1928d1631767ec615ba5377fc3f39.zip
feature[ats_ATS144309]: Add ClientJdbcService
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.osee.framework.core.client/OSGI-INF/client.jdbc.service.xml11
-rw-r--r--plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ClientJdbcServiceImpl.java149
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 057ddc0a4d..a217caff6f 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 0000000000..d6528daea9
--- /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 0000000000..fbb9f4dcef
--- /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

Back to the top