From ce2ae76e2f2be42bbc651a58f23397b093718d2b Mon Sep 17 00:00:00 2001
From: Glenn Van Lint <glenn.vanlint@is4u.be>
Date: Tue, 19 Feb 2013 10:15:31 +0000
Subject: [PATCH] Create JDBCConnectionFactory class with connection test case. 

---
 opendj3/opendj-virtual/.project                                                                                   |   23 +++++
 opendj3/opendj-virtual/target/classes/org/forgerock/opendj/virtual/package-info.class                             |    0 
 opendj3/opendj-virtual/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst         |    1 
 opendj3/opendj-virtual/.classpath                                                                                 |    8 ++
 opendj3/opendj-virtual/target/maven-archiver/pom.properties                                                       |    5 +
 opendj3/opendj-virtual/.settings/org.eclipse.jdt.core.prefs                                                       |    5 +
 opendj3/opendj-virtual/.settings/org.maven.ide.eclipse.prefs                                                      |    7 +
 opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JDBCConnectionFactory.java                      |   96 ++++++++++++++++++++++++
 opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JoinConnectionFactory.java                      |   29 +++++++
 opendj3/opendj-virtual/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst |    0 
 opendj3/opendj-virtual/target/opendj-virtual-3.0.0-SNAPSHOT.jar                                                   |    0 
 opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/package-info.java                               |   20 +++++
 opendj3/opendj-virtual/src/test/java/org/forgerock/opendj/virtual/Example.java                                    |   30 +++++++
 opendj3/opendj-virtual/target/classes/org/forgerock/opendj/virtual/JDBCConnectionFactory.class                    |    0 
 opendj3/opendj-virtual/target/test-classes/org/forgerock/opendj/virtual/Example.class                             |    0 
 opendj3/opendj-virtual/pom.xml                                                                                    |    5 +
 16 files changed, 229 insertions(+), 0 deletions(-)

diff --git a/opendj3/opendj-virtual/.classpath b/opendj3/opendj-virtual/.classpath
new file mode 100644
index 0000000..cec251a
--- /dev/null
+++ b/opendj3/opendj-virtual/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/opendj3/opendj-virtual/.project b/opendj3/opendj-virtual/.project
new file mode 100644
index 0000000..835c260
--- /dev/null
+++ b/opendj3/opendj-virtual/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>opendj-virtual</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>
diff --git a/opendj3/opendj-virtual/.settings/org.eclipse.jdt.core.prefs b/opendj3/opendj-virtual/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..14f521d
--- /dev/null
+++ b/opendj3/opendj-virtual/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/opendj3/opendj-virtual/.settings/org.maven.ide.eclipse.prefs b/opendj3/opendj-virtual/.settings/org.maven.ide.eclipse.prefs
new file mode 100644
index 0000000..3c757a2
--- /dev/null
+++ b/opendj3/opendj-virtual/.settings/org.maven.ide.eclipse.prefs
@@ -0,0 +1,7 @@
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
diff --git a/opendj3/opendj-virtual/pom.xml b/opendj3/opendj-virtual/pom.xml
index 68c986b..300d988 100644
--- a/opendj3/opendj-virtual/pom.xml
+++ b/opendj3/opendj-virtual/pom.xml
@@ -72,6 +72,11 @@
             <version>3.0.1</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.1</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>
diff --git a/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JDBCConnectionFactory.java b/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JDBCConnectionFactory.java
new file mode 100644
index 0000000..313964d
--- /dev/null
+++ b/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JDBCConnectionFactory.java
@@ -0,0 +1,96 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
+ * or http://forgerock.org/license/CDDLv1.0.html.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at legal-notices/CDDLv1_0.txt.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Copyright 2009-2010 Sun Microsystems, Inc.
+ *      Portions copyright 2011-2012 ForgeRock AS.
+ */
+
+package org.forgerock.opendj.virtual;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+/**
+ * Create a JDBC driver instance which contains all the methods for 
+ * connection and commands to the database.
+ */
+
+public class JDBCConnectionFactory {
+    String driverName = "com.mysql.jdbc.Driver";
+	Connection con = null;
+    
+    public JDBCConnectionFactory() {
+            try {
+                    Class.forName(driverName);
+            } catch (ClassNotFoundException e) {
+                    System.out.println(e.toString());
+            }
+    }
+    
+    /**
+     * Set up a JDBC connection using the defined parameters.
+     *
+     * @param host
+     *            The host address of the database. 
+     * @param port
+     *            The port used to connect to the database.
+     * @param databaseName
+     *            The name of the database to connect with.
+     * @param userName
+     *            The username required for authentication to the database.
+     * @param userPass
+     * 			  The password required for authentication to the database.
+     * @return The created connection.
+     */
+    public Connection createConnection(String host, String port, String databaseName, String userName, String userPass) {
+            try {
+                    String connectionUrl="jdbc:mysql://"
+		                    		.concat(host+":")
+		                    		.concat(port+"/")
+		                    		.concat(databaseName);
+                    con = DriverManager
+                                    .getConnection(connectionUrl,userName,userPass);
+                    System.out.println("Connection created.");
+                    } catch (SQLException e) {
+                    System.out.println(e.toString());
+            }
+            return con;
+    }
+    
+    /**
+     * Close the open connection to the database.
+     */
+    public void closeConnection(){
+            try{
+                    this.con.close();
+            System.out.println("Connection terminated.");
+            }catch(Exception e){
+                    System.out.println(e.toString());
+            }
+    }
+}
+
+
+
diff --git a/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JoinConnectionFactory.java b/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JoinConnectionFactory.java
new file mode 100644
index 0000000..1846093
--- /dev/null
+++ b/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JoinConnectionFactory.java
@@ -0,0 +1,29 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
+ * or http://forgerock.org/license/CDDLv1.0.html.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at legal-notices/CDDLv1_0.txt.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Copyright 2009-2010 Sun Microsystems, Inc.
+ *      Portions copyright 2011-2012 ForgeRock AS.
+ */
+
+package org.forgerock.opendj.virtual;
+
diff --git a/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/package-info.java b/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/package-info.java
new file mode 100644
index 0000000..1db04ab
--- /dev/null
+++ b/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * The contents of this file are subject to the terms of the Common Development and
+ * Distribution License (the License). You may not use this file except in compliance with the
+ * License.
+ *
+ * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
+ * specific language governing permission and limitations under the License.
+ *
+ * When distributing Covered Software, include this CDDL Header Notice in each file and include
+ * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
+ * Header, with the fields enclosed by brackets [] replaced by your own identifying
+ * information: "Portions Copyright [year] [name of copyright owner]".
+ *
+ * Copyright 2012 ForgeRock AS.
+ */
+
+/**
+ * APIs for the virtual directory.
+ */
+package org.forgerock.opendj.virtual;
\ No newline at end of file
diff --git a/opendj3/opendj-virtual/src/test/java/org/forgerock/opendj/virtual/Example.java b/opendj3/opendj-virtual/src/test/java/org/forgerock/opendj/virtual/Example.java
new file mode 100644
index 0000000..b7792aa
--- /dev/null
+++ b/opendj3/opendj-virtual/src/test/java/org/forgerock/opendj/virtual/Example.java
@@ -0,0 +1,30 @@
+/*
+ * The contents of this file are subject to the terms of the Common Development and
+ * Distribution License (the License). You may not use this file except in compliance with the
+ * License.
+ *
+ * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
+ * specific language governing permission and limitations under the License.
+ *
+ * When distributing Covered Software, include this CDDL Header Notice in each file and include
+ * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
+ * Header, with the fields enclosed by brackets [] replaced by your own identifying
+ * information: "Portions Copyright [year] [name of copyright owner]".
+ *
+ * Copyright 2012-2013 ForgeRock AS.
+ */
+
+package org.forgerock.opendj.virtual;
+
+import org.forgerock.opendj.virtual.JDBCConnectionFactory;
+
+/**
+ * Example.
+ */
+public class Example {
+	 public static void main(String args[])throws Exception {
+	    	final JDBCConnectionFactory JDBC =new JDBCConnectionFactory();
+	    	JDBC.createConnection("localhost", "3306", "opendj_db","root", "");
+	    	JDBC.closeConnection();
+	    }
+}
\ No newline at end of file
diff --git a/opendj3/opendj-virtual/target/classes/org/forgerock/opendj/virtual/JDBCConnectionFactory.class b/opendj3/opendj-virtual/target/classes/org/forgerock/opendj/virtual/JDBCConnectionFactory.class
new file mode 100644
index 0000000..19c59d0
--- /dev/null
+++ b/opendj3/opendj-virtual/target/classes/org/forgerock/opendj/virtual/JDBCConnectionFactory.class
Binary files differ
diff --git a/opendj3/opendj-virtual/target/classes/org/forgerock/opendj/virtual/package-info.class b/opendj3/opendj-virtual/target/classes/org/forgerock/opendj/virtual/package-info.class
new file mode 100644
index 0000000..652d1fe
--- /dev/null
+++ b/opendj3/opendj-virtual/target/classes/org/forgerock/opendj/virtual/package-info.class
Binary files differ
diff --git a/opendj3/opendj-virtual/target/maven-archiver/pom.properties b/opendj3/opendj-virtual/target/maven-archiver/pom.properties
new file mode 100644
index 0000000..fe60407
--- /dev/null
+++ b/opendj3/opendj-virtual/target/maven-archiver/pom.properties
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Mon Feb 18 15:53:05 CET 2013
+version=3.0.0-SNAPSHOT
+groupId=org.forgerock.opendj
+artifactId=opendj-virtual
diff --git a/opendj3/opendj-virtual/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/opendj3/opendj-virtual/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
new file mode 100644
index 0000000..23c46fc
--- /dev/null
+++ b/opendj3/opendj-virtual/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
@@ -0,0 +1 @@
+org\forgerock\opendj\virtual\JDBCConnectionFactory.class
diff --git a/opendj3/opendj-virtual/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/opendj3/opendj-virtual/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/opendj3/opendj-virtual/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
diff --git a/opendj3/opendj-virtual/target/opendj-virtual-3.0.0-SNAPSHOT.jar b/opendj3/opendj-virtual/target/opendj-virtual-3.0.0-SNAPSHOT.jar
new file mode 100644
index 0000000..bfb6f3d
--- /dev/null
+++ b/opendj3/opendj-virtual/target/opendj-virtual-3.0.0-SNAPSHOT.jar
Binary files differ
diff --git a/opendj3/opendj-virtual/target/test-classes/org/forgerock/opendj/virtual/Example.class b/opendj3/opendj-virtual/target/test-classes/org/forgerock/opendj/virtual/Example.class
new file mode 100644
index 0000000..a4c17ce
--- /dev/null
+++ b/opendj3/opendj-virtual/target/test-classes/org/forgerock/opendj/virtual/Example.class
Binary files differ

--
Gitblit v1.10.0