mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Glenn Van Lint
15.13.2013 a031489dbe4d200f674bc8980db9b0975071b5ff
opendj-sdk/opendj3/opendj-virtual/MappingConfig.properties
New file
@@ -0,0 +1,20 @@
#Mon Mar 25 13:43:32 CET 2013
employees\:postalCode=People\:postalCode
customers\:customerName=People\:sn
employees\:employeeName=People\:cn
employees\:addressLine=People\:street
employees\:city=People\:l
customers\:country=People\:description
employees\:contactPhone=People\:homePhone
customers\:city=People\:l
customers\:contactPhone=People\:telephoneNumber
customers\:customerId=People\:uid
employees\:jobTitle=People\:initials
employees\:country=People\:description
customers\:postalCode=People\:postalCode
employees\:employeeFirstName=People\:givenName
customers\:customerFirstName=People\:givenName
customers\:addressLine=People\:street
employees\:employeeId=People\:employeeNumber
employees\:contactEmail=People\:mail
employees\:officeId=People\:employeeNumber
opendj-sdk/opendj3/opendj-virtual/hs_err_pid7620.log
New file
@@ -0,0 +1,221 @@
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006b698f09, pid=7620, tid=3708
#
# JRE version: 7.0_13-b20
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.7-b01 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# V  [jvm.dll+0x38f09]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#
---------------  T H R E A D  ---------------
Current thread (0x000000000ad18800):  JavaThread "JDWP Transport Listener: dt_socket" daemon [_thread_in_vm, id=3708, stack(0x000000000c6d0000,0x000000000c7d0000)]
siginfo: ExceptionCode=0xc0000005, reading address 0x000000000000000c
Registers:
RAX=0x000000000000000c, RBX=0x000000000ad18800, RCX=0x0000000000000000, RDX=0x0000000000000000
RSP=0x000000000c7cf700, RBP=0x000000000000000c, RSI=0x0000000000000000, RDI=0x0000000000000010
R8 =0x00000000d713c0a0, R9 =0x0000000000000000, R10=0x0000000000000000, R11=0x0000000000000001
R12=0x0000000000000000, R13=0x0000000000000000, R14=0x0000000000000000, R15=0x0000000000000000
RIP=0x000000006b698f09, EFLAGS=0x0000000000010246
Top of Stack: (sp=0x000000000c7cf700)
0x000000000c7cf700:   000000000ad18800 0000000000000000
0x000000000c7cf710:   0000000000000000 000000000ad18800
0x000000000c7cf720:   0000000000000000 000000006b7575d4
0x000000000c7cf730:   00000000d713c0a0 000000000c7cf850
0x000000000c7cf740:   000000000ad1a110 000000000c7cf820
0x000000000c7cf750:   000000000ad18800 0000000000000000
0x000000000c7cf760:   000000000ad1a110 000000000c7cf850
0x000000000c7cf770:   0000000000000000 0000000000000000
0x000000000c7cf780:   000000000ad189d8 000000006b2e7d15
0x000000000c7cf790:   000000000c7cf820 000000000c7cf850
0x000000000c7cf7a0:   000000000ad1a110 000000000ad189d8
0x000000000c7cf7b0:   000000000adb0f0a 000000006b2ef09c
0x000000000c7cf7c0:   000000006b010a01 000000000c7cf8c0
0x000000000c7cf7d0:   000000000ad11001 000000000adc8f30
0x000000000c7cf7e0:   000009be00000013 000000006b010a00
0x000000000c7cf7f0:   000000000ad34090 000000000ad1f1e0
Instructions: (pc=0x000000006b698f09)
0x000000006b698ee9:   d2 48 8b c5 eb 18 48 8b d0 48 8b c5 48 d3 e2 48
0x000000006b698ef9:   03 15 11 16 62 00 eb 06 48 8b 12 48 8b c7 48 98
0x000000006b698f09:   8b 14 10 85 d2 74 2a 45 84 db 4c 63 c6 48 0f 45
0x000000006b698f19:   fd 8d 47 0b 48 63 c8 48 83 e1 f8 48 c1 e9 03 8d
Register to memory mapping:
RAX=0x000000000000000c is an unknown value
RBX=0x000000000ad18800 is a thread
RCX=0x0000000000000000 is an unknown value
RDX=0x0000000000000000 is an unknown value
RSP=0x000000000c7cf700 is pointing into the stack for thread: 0x000000000ad18800
RBP=0x000000000000000c is an unknown value
RSI=0x0000000000000000 is an unknown value
RDI=0x0000000000000010 is an unknown value
R8 =0x00000000d713c0a0 is an oop
java.lang.String
 - klass: 'java/lang/String'
R9 =0x0000000000000000 is an unknown value
R10=0x0000000000000000 is an unknown value
R11=0x0000000000000001 is an unknown value
R12=0x0000000000000000 is an unknown value
R13=0x0000000000000000 is an unknown value
R14=0x0000000000000000 is an unknown value
R15=0x0000000000000000 is an unknown value
Stack: [0x000000000c6d0000,0x000000000c7d0000],  sp=0x000000000c7cf700,  free space=1021k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [jvm.dll+0x38f09]
---------------  P R O C E S S  ---------------
Java Threads: ( => current thread )
  0x000000000ad40800 JavaThread "Service Thread" daemon [_thread_blocked, id=9440, stack(0x000000000cbd0000,0x000000000ccd0000)]
  0x000000000ad3a000 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=1088, stack(0x000000000cad0000,0x000000000cbd0000)]
  0x000000000ad34800 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=6732, stack(0x000000000c9d0000,0x000000000cad0000)]
  0x000000000ad25800 JavaThread "JDWP Command Reader" daemon [_thread_in_native, id=8884, stack(0x000000000c8d0000,0x000000000c9d0000)]
  0x000000000ad24000 JavaThread "JDWP Event Helper Thread" daemon [_thread_blocked, id=3736, stack(0x000000000c7d0000,0x000000000c8d0000)]
=>0x000000000ad18800 JavaThread "JDWP Transport Listener: dt_socket" daemon [_thread_in_vm, id=3708, stack(0x000000000c6d0000,0x000000000c7d0000)]
  0x000000000ad12000 JavaThread "Attach Listener" daemon [_thread_blocked, id=6104, stack(0x000000000c1f0000,0x000000000c2f0000)]
  0x000000000ad0e800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=7288, stack(0x000000000c0f0000,0x000000000c1f0000)]
  0x000000000aca9800 JavaThread "Finalizer" daemon [_thread_blocked, id=7420, stack(0x000000000bff0000,0x000000000c0f0000)]
  0x000000000aca2800 JavaThread "Reference Handler" daemon [_thread_blocked, id=12004, stack(0x000000000bef0000,0x000000000bff0000)]
  0x0000000002032800 JavaThread "main" [_thread_blocked, id=6728, stack(0x0000000001f30000,0x0000000002030000)]
Other Threads:
  0x000000000abf4000 VMThread [stack: 0x000000000bdf0000,0x000000000bef0000] [id=10404]
  0x000000000ad35000 WatcherThread [stack: 0x000000000ccd0000,0x000000000cdd0000] [id=9800]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap
 PSYoungGen      total 36736K, used 1262K [0x00000000d70b0000, 0x00000000d99a0000, 0x0000000100000000)
  eden space 31552K, 4% used [0x00000000d70b0000,0x00000000d71eb8d8,0x00000000d8f80000)
  from space 5184K, 0% used [0x00000000d9490000,0x00000000d9490000,0x00000000d99a0000)
  to   space 5184K, 0% used [0x00000000d8f80000,0x00000000d8f80000,0x00000000d9490000)
 ParOldGen       total 83904K, used 0K [0x0000000085200000, 0x000000008a3f0000, 0x00000000d70b0000)
  object space 83904K, 0% used [0x0000000085200000,0x0000000085200000,0x000000008a3f0000)
 PSPermGen       total 21248K, used 2521K [0x0000000080000000, 0x00000000814c0000, 0x0000000085200000)
  object space 21248K, 11% used [0x0000000080000000,0x00000000802765a8,0x00000000814c0000)
Card table byte_map: [0x0000000005130000,0x0000000005540000] byte_map_base: 0x0000000004d30000
Polling page: 0x00000000005e0000
Code Cache  [0x0000000002130000, 0x00000000023a0000, 0x0000000005130000)
 total_blobs=172 nmethods=2 adapters=130 free_code_cache=48772Kb largest_free_block=49924352
Compilation events (4 events):
Event: 0.231 Thread 0x000000000ad34800    1             java.lang.String::charAt (29 bytes)
Event: 0.236 Thread 0x000000000ad34800 nmethod 1 0x000000000218e110 code [0x000000000218e260, 0x000000000218e338]
Event: 0.249 Thread 0x000000000ad3a000    2             java.lang.String::indexOf (166 bytes)
Event: 0.256 Thread 0x000000000ad3a000 nmethod 2 0x000000000218d850 code [0x000000000218d9a0, 0x000000000218de58]
GC Heap History (0 events):
No events
Deoptimization events (0 events):
No events
Internal exceptions (6 events):
Event: 0.034 Thread 0x0000000002032800 Threw 0x00000000d70b61a8 at C:\jdk7u2_64p\jdk7u13\hotspot\src\share\vm\prims\jni.cpp:3994
Event: 0.232 Thread 0x0000000002032800 Threw 0x00000000d7114a50 at C:\jdk7u2_64p\jdk7u13\hotspot\src\share\vm\prims\jvm.cpp:1166
Event: 0.245 Thread 0x0000000002032800 Threw 0x00000000d711b8e8 at C:\jdk7u2_64p\jdk7u13\hotspot\src\share\vm\prims\jvm.cpp:1166
Event: 0.247 Thread 0x0000000002032800 Threw 0x00000000d71202c0 at C:\jdk7u2_64p\jdk7u13\hotspot\src\share\vm\prims\jvm.cpp:1166
Event: 0.249 Thread 0x0000000002032800 Threw 0x00000000d71253f0 at C:\jdk7u2_64p\jdk7u13\hotspot\src\share\vm\prims\jvm.cpp:1166
Event: 0.250 Thread 0x0000000002032800 Threw 0x00000000d712e3a8 at C:\jdk7u2_64p\jdk7u13\hotspot\src\share\vm\prims\jvm.cpp:1166
Events (10 events):
Event: 17.404 Executing VM operation: GetCurrentLocation
Event: 17.404 Executing VM operation: GetCurrentLocation done
Event: 17.404 Executing VM operation: ChangeSingleStep
Event: 17.404 Executing VM operation: ChangeSingleStep done
Event: 17.407 Executing VM operation: ChangeSingleStep
Event: 17.407 Executing VM operation: ChangeSingleStep done
Event: 17.424 Executing VM operation: GetOrSetLocal
Event: 17.424 Executing VM operation: GetOrSetLocal done
Event: 17.432 Executing VM operation: GetOrSetLocal
Event: 17.432 Executing VM operation: GetOrSetLocal done
Dynamic libraries:
0x000007f635990000 - 0x000007f6359c3000   C:\Program Files\Java\jdk1.7.0_13\bin\javaw.exe
0x000007f8dc270000 - 0x000007f8dc42e000   C:\WINDOWS\SYSTEM32\ntdll.dll
0x000007f8da1d0000 - 0x000007f8da306000   C:\WINDOWS\system32\KERNEL32.DLL
0x000007f8d88c0000 - 0x000007f8d89b3000   C:\WINDOWS\system32\KERNELBASE.dll
0x000007f8daa00000 - 0x000007f8daade000   C:\WINDOWS\system32\ADVAPI32.dll
0x000007f8da650000 - 0x000007f8da79c000   C:\WINDOWS\system32\USER32.dll
0x000007f8d5bb0000 - 0x000007f8d5e19000   C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.9200.16384_none_418c2a697189c07f\COMCTL32.dll
0x000007f8da5a0000 - 0x000007f8da645000   C:\WINDOWS\system32\msvcrt.dll
0x000007f8d9de0000 - 0x000007f8d9e28000   C:\WINDOWS\SYSTEM32\sechost.dll
0x000007f8da8c0000 - 0x000007f8daa00000   C:\WINDOWS\system32\RPCRT4.dll
0x000007f8db450000 - 0x000007f8db590000   C:\WINDOWS\system32\GDI32.dll
0x000007f8dad10000 - 0x000007f8dad49000   C:\WINDOWS\system32\IMM32.DLL
0x000007f8da7a0000 - 0x000007f8da8b5000   C:\WINDOWS\system32\MSCTF.dll
0x000007f8d84e0000 - 0x000007f8d8520000   C:\WINDOWS\system32\nvinitx.dll
0x000000006b320000 - 0x000000006b3f1000   C:\Program Files\Java\jdk1.7.0_13\jre\bin\msvcr100.dll
0x000000006b660000 - 0x000000006bd7f000   C:\Program Files\Java\jdk1.7.0_13\jre\bin\server\jvm.dll
0x000007f8cc650000 - 0x000007f8cc659000   C:\WINDOWS\SYSTEM32\WSOCK32.dll
0x000007f8d4b40000 - 0x000007f8d4b60000   C:\WINDOWS\SYSTEM32\WINMM.dll
0x000007f8db120000 - 0x000007f8db127000   C:\WINDOWS\system32\PSAPI.DLL
0x000007f8da530000 - 0x000007f8da588000   C:\WINDOWS\system32\WS2_32.dll
0x000007f8d4af0000 - 0x000007f8d4b22000   C:\WINDOWS\SYSTEM32\WINMMBASE.dll
0x000007f8da590000 - 0x000007f8da599000   C:\WINDOWS\system32\NSI.dll
0x000000006cdc0000 - 0x000000006cdcf000   C:\Program Files\Java\jdk1.7.0_13\jre\bin\verify.dll
0x000000006cd90000 - 0x000000006cdb8000   C:\Program Files\Java\jdk1.7.0_13\jre\bin\java.dll
0x000000006b2e0000 - 0x000000006b315000   C:\Program Files\Java\jdk1.7.0_13\jre\bin\jdwp.dll
0x000000006b2d0000 - 0x000000006b2d8000   C:\Program Files\Java\jdk1.7.0_13\jre\bin\npt.dll
0x000000006cd70000 - 0x000000006cd85000   C:\Program Files\Java\jdk1.7.0_13\jre\bin\zip.dll
0x000000006b2c0000 - 0x000000006b2c9000   C:\Program Files\Java\jdk1.7.0_13\jre\bin\dt_socket.dll
0x000007f8d0fb0000 - 0x000007f8d0fc4000   C:\WINDOWS\system32\napinsp.dll
0x000007f8d0fd0000 - 0x000007f8d0fe8000   C:\WINDOWS\system32\pnrpnsp.dll
0x000007f8d6ec0000 - 0x000007f8d6ed6000   C:\WINDOWS\system32\NLAapi.dll
0x000007f8d7d40000 - 0x000007f8d7d9c000   C:\WINDOWS\System32\mswsock.dll
0x000007f8d7b80000 - 0x000007f8d7c18000   C:\WINDOWS\SYSTEM32\DNSAPI.dll
0x000007f8d0ff0000 - 0x000007f8d1002000   C:\WINDOWS\System32\winrnr.dll
0x000007f8d1010000 - 0x000007f8d1024000   C:\WINDOWS\system32\wshbth.dll
0x000007f8d3400000 - 0x000007f8d345f000   C:\WINDOWS\System32\fwpuclnt.dll
0x000007f8d1400000 - 0x000007f8d1408000   C:\Windows\System32\rasadhlp.dll
0x000007f8d66b0000 - 0x000007f8d6813000   C:\WINDOWS\SYSTEM32\dbghelp.dll
VM Arguments:
jvm_args: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:10257 -Dfile.encoding=Cp1252 -Xbootclasspath:C:\Program Files\Java\jdk1.7.0_13\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\jfr.jar;C:\Program Files (x86)\Java\jre7\lib\ext\mysql-connector-java-5.1.23-bin.jar
java_command: org.forgerock.opendj.virtual.JDBCConnectionTestCase
Launcher Type: SUN_STANDARD
Environment Variables:
JAVA_HOME=C:\Progra~2\Java\jdk1.7.0
PATH=C:\Program Files\Java\jdk1.7.0_13\jre\bin;C:/Program Files/Java/jdk1.7.0_13/bin/../jre/bin/server;C:/Program Files/Java/jdk1.7.0_13/bin/../jre/bin;C:/Program Files/Java/jdk1.7.0_13/bin/../jre/lib/amd64;C:\Program Files\Java\jdk1.7.0_13\bin;C:\Program Files\apache-maven-3.0.4\bin;C:\Program Files (x86)\eclipse;
USERNAME=Glenn
OS=Windows_NT
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 37 Stepping 5, GenuineIntel
---------------  S Y S T E M  ---------------
OS: Windows 8 , 64 bit Build 9200
CPU:total 4 (2 cores per cpu, 2 threads per core) family 6 model 37 stepping 5, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, ht, tsc, tscinvbit
Memory: 4k page, physical 8049516k(3879296k free), swap 10670956k(5031828k free)
vm_info: Java HotSpot(TM) 64-Bit Server VM (23.7-b01) for windows-amd64 JRE (1.7.0_13-b20), built on Jan 30 2013 10:10:00 by "java_re" with unknown MS VC++:1600
time: Mon Mar 18 10:29:34 2013
elapsed time: 17 seconds
opendj-sdk/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JDBCConnection.java
New file
@@ -0,0 +1,478 @@
package org.forgerock.opendj.virtual;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.forgerock.opendj.ldap.Attribute;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.ConnectionEventListener;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.Entry;
import org.forgerock.opendj.ldap.ErrorResultException;
import org.forgerock.opendj.ldap.ErrorResultIOException;
import org.forgerock.opendj.ldap.FutureResult;
import org.forgerock.opendj.ldap.IntermediateResponseHandler;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ResultHandler;
import org.forgerock.opendj.ldap.SearchResultHandler;
import org.forgerock.opendj.ldap.SearchResultReferenceIOException;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.requests.AbandonRequest;
import org.forgerock.opendj.ldap.requests.AddRequest;
import org.forgerock.opendj.ldap.requests.BindRequest;
import org.forgerock.opendj.ldap.requests.CompareRequest;
import org.forgerock.opendj.ldap.requests.DeleteRequest;
import org.forgerock.opendj.ldap.requests.ExtendedRequest;
import org.forgerock.opendj.ldap.requests.ModifyDNRequest;
import org.forgerock.opendj.ldap.requests.ModifyRequest;
import org.forgerock.opendj.ldap.requests.Requests;
import org.forgerock.opendj.ldap.requests.SearchRequest;
import org.forgerock.opendj.ldap.requests.UnbindRequest;
import org.forgerock.opendj.ldap.responses.BindResult;
import org.forgerock.opendj.ldap.responses.CompareResult;
import org.forgerock.opendj.ldap.responses.ExtendedResult;
import org.forgerock.opendj.ldap.responses.GenericExtendedResult;
import org.forgerock.opendj.ldap.responses.Responses;
import org.forgerock.opendj.ldap.responses.Result;
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
import org.forgerock.opendj.ldap.responses.SearchResultReference;
import org.forgerock.opendj.ldif.ChangeRecord;
import org.forgerock.opendj.ldif.ConnectionEntryReader;
public final class JDBCConnection implements Connection {
    private final String driverName = "com.mysql.jdbc.Driver";
   private java.sql.Connection connection;
   private String connectionUrl;
   private String userName;
   private String userPass;
   private JDBCMapper jdbcm;
   private MappingConfigurationManager mcm;
   /**
     * Creates a new JDBC connection.
     *
     * @param connection
     *            The SQL Connection using JDBC Driver.
     */
    JDBCConnection(final String connectionURL) {
      this.connectionUrl = connectionURL;
    }
    public void initializeMapper(JDBCMapper jdbcmapper) throws SQLException, ErrorResultException, ErrorResultIOException, SearchResultReferenceIOException{
      jdbcm = jdbcmapper;
      jdbcm.fillMaps();
      mcm = new MappingConfigurationManager(jdbcm);
      jdbcm.loadMappingConfig(mcm.loadMapping());
    }
    public java.sql.Connection getSqlConnection(){
      return connection;
    }
   @Override
   public FutureResult<Void> abandonAsync(AbandonRequest request) {
      // TODO Auto-generated method stub
      return null;
   }
   private Map<String, Object> getValuesMap(AddRequest request, String tableName, String OUName){
      Iterable<Attribute> attributesCollection = request.getAllAttributes();
      Iterator<Attribute> attributeIter = attributesCollection.iterator();
      Map<String, Object> map = new HashMap<String, Object>();
      while(attributeIter.hasNext()){
         Attribute att = attributeIter.next();
         Iterator<ByteString> valueIter = att.iterator();
         String attributeName = att.getAttributeDescriptionAsString();
         String columnName = jdbcm.getColumnNameFromMapping(tableName, OUName, attributeName);
         String columnValue = "";
         if (columnName == null) continue;
         while(valueIter.hasNext()){
            columnValue = columnValue.concat(valueIter.next().toString());
         }
         map.put(columnName, columnValue);
      }
      return map;
   }
   private ArrayList<String> getSQLVariablesStrings(String tableName, Map columnValuesMap){
      ArrayList<String>columnList = null;
      try {
         columnList = jdbcm.getTableColumns(tableName);
      } catch (SQLException e1) {
         e1.printStackTrace();
      }
      String columnNamesString = " (";
      String columnValuesString = " (";
      for(int i = 0; i < columnList.size(); i++){
         if (i > 0){
            columnNamesString = columnNamesString.concat(", ");
            columnValuesString = columnValuesString.concat(", ");
         }
         String columnName = columnList.get(i);
         Object columnValue = columnValuesMap.get(columnName);
         Object dataType = jdbcm.getTableColumnDataType(tableName, columnName);
         if(columnValue == null){
            if(dataType.equals(Integer.class)) columnValue = "0";
            else columnValue = "Default Value";
         }
         if(dataType.equals(Integer.class)) columnValue = Integer.parseInt(columnValue.toString());
         columnNamesString = columnNamesString.concat(columnName);
         columnValuesString = columnValuesString.concat("'" + columnValue + "'");
      }
      columnNamesString = columnNamesString.concat(")");
      columnValuesString = columnValuesString.concat(")");
      ArrayList<String> newlist = new ArrayList<String>();
      newlist.add(columnNamesString);
      newlist.add(columnValuesString);
      return newlist;
   }
   private Result addOperation(AddRequest request){
      Result r;
      try {
         final String DN = request.getName().toString();
         String[] stringSplitter = DN.split("ou=");
         stringSplitter = stringSplitter[1].split(",");
         final String organizationalUnitName = stringSplitter[0];
         final String tableName = jdbcm.getTableNameFromMapping(organizationalUnitName);
         final Map<String, Object> columnValuesMap = getValuesMap(request, tableName, organizationalUnitName);
         final ArrayList<String> SQLStringList = getSQLVariablesStrings(tableName, columnValuesMap);
         String columnNamesString = SQLStringList.get(0), columnValuesString = SQLStringList.get(1);
         Statement st = connection.createStatement();
         String sql = "INSERT INTO " + tableName + columnNamesString + " VALUES" + columnValuesString;
         st.executeUpdate(sql);
         r = Responses.newResult(ResultCode.SUCCESS);
      } catch (SQLException e) {
         System.out.println(e.toString());
         r = Responses.newResult(ResultCode.UNWILLING_TO_PERFORM);
      }
      return r;
   }
   @Override
   public Result add(AddRequest request) throws ErrorResultException {
      return addOperation(request);
   }
   @Override
   public Result add(Entry entry) throws ErrorResultException {
      AddRequest addRequest = Requests.newAddRequest(entry);
      return addOperation(addRequest);
   }
   @Override
   public Result add(String... ldifLines) throws ErrorResultException {
      AddRequest addRequest = Requests.newAddRequest(ldifLines);
      return addOperation(addRequest);
   }
   @Override
   public FutureResult<Result> addAsync(AddRequest request,
         IntermediateResponseHandler intermediateResponseHandler,
         ResultHandler<? super Result> resultHandler) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public void addConnectionEventListener(ConnectionEventListener listener) {
      // TODO Auto-generated method stub
   }
   @Override
   public Result applyChange(ChangeRecord request) throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public FutureResult<Result> applyChangeAsync(ChangeRecord request,
         IntermediateResponseHandler intermediateResponseHandler,
         ResultHandler<? super Result> resultHandler) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public BindResult bind(BindRequest request) throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public BindResult bind(String name, char[] password)
         throws ErrorResultException {
      BindResult r;
      this.userName = name;
      this.userPass = new String(password);
      try {
         Class.forName(driverName);
         this.connection = DriverManager
                 .getConnection(this.connectionUrl,this.userName,this.userPass);
         } catch (ClassNotFoundException e) {
         System.out.println(e.toString());
         r = Responses.newBindResult(ResultCode.OTHER);
         return r;
        } catch (SQLException e) {
         System.out.println(e.toString());
         r = Responses.newBindResult(ResultCode.CLIENT_SIDE_CONNECT_ERROR);
         return r;
      }
      r = Responses.newBindResult(ResultCode.SUCCESS);
      return r;
   }
   @Override
   public FutureResult<BindResult> bindAsync(BindRequest request,
         IntermediateResponseHandler intermediateResponseHandler,
         ResultHandler<? super BindResult> resultHandler) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public void close() {
      // TODO Auto-generated method stub
   }
   @Override
   public void close(UnbindRequest request, String reason) {
      // TODO Auto-generated method stub
   }
   @Override
   public CompareResult compare(CompareRequest request)
         throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public CompareResult compare(String name, String attributeDescription,
         String assertionValue) throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public FutureResult<CompareResult> compareAsync(CompareRequest request,
         IntermediateResponseHandler intermediateResponseHandler,
         ResultHandler<? super CompareResult> resultHandler) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public Result delete(DeleteRequest request) throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public Result delete(String name) throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public FutureResult<Result> deleteAsync(DeleteRequest request,
         IntermediateResponseHandler intermediateResponseHandler,
         ResultHandler<? super Result> resultHandler) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public <R extends ExtendedResult> R extendedRequest(
         ExtendedRequest<R> request) throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public <R extends ExtendedResult> R extendedRequest(
         ExtendedRequest<R> request, IntermediateResponseHandler handler)
         throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public GenericExtendedResult extendedRequest(String requestName,
         ByteString requestValue) throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public <R extends ExtendedResult> FutureResult<R> extendedRequestAsync(
         ExtendedRequest<R> request,
         IntermediateResponseHandler intermediateResponseHandler,
         ResultHandler<? super R> resultHandler) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public boolean isClosed() {
      // TODO Auto-generated method stub
      return false;
   }
   @Override
   public boolean isValid() {
      // TODO Auto-generated method stub
      return false;
   }
   @Override
   public Result modify(ModifyRequest request) throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public Result modify(String... ldifLines) throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public FutureResult<Result> modifyAsync(ModifyRequest request,
         IntermediateResponseHandler intermediateResponseHandler,
         ResultHandler<? super Result> resultHandler) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public Result modifyDN(ModifyDNRequest request) throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public Result modifyDN(String name, String newRDN)
         throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public FutureResult<Result> modifyDNAsync(ModifyDNRequest request,
         IntermediateResponseHandler intermediateResponseHandler,
         ResultHandler<? super Result> resultHandler) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public SearchResultEntry readEntry(DN name, String... attributeDescriptions)
         throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public SearchResultEntry readEntry(String name,
         String... attributeDescriptions) throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public FutureResult<SearchResultEntry> readEntryAsync(DN name,
         Collection<String> attributeDescriptions,
         ResultHandler<? super SearchResultEntry> handler) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public void removeConnectionEventListener(ConnectionEventListener listener) {
      // TODO Auto-generated method stub
   }
   @Override
   public ConnectionEntryReader search(SearchRequest request) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public Result search(SearchRequest request,
         Collection<? super SearchResultEntry> entries)
         throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public Result search(SearchRequest request,
         Collection<? super SearchResultEntry> entries,
         Collection<? super SearchResultReference> references)
         throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public Result search(SearchRequest request, SearchResultHandler handler)
         throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public ConnectionEntryReader search(String baseObject, SearchScope scope,
         String filter, String... attributeDescriptions) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public FutureResult<Result> searchAsync(SearchRequest request,
         IntermediateResponseHandler intermediateResponseHandler,
         SearchResultHandler resultHandler) {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public SearchResultEntry searchSingleEntry(SearchRequest request)
         throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public SearchResultEntry searchSingleEntry(String baseObject,
         SearchScope scope, String filter, String... attributeDescriptions)
         throws ErrorResultException {
      // TODO Auto-generated method stub
      return null;
   }
   @Override
   public FutureResult<SearchResultEntry> searchSingleEntryAsync(
         SearchRequest request,
         ResultHandler<? super SearchResultEntry> handler) {
      // TODO Auto-generated method stub
      return null;
   }
}
opendj-sdk/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JDBCConnectionFactory.java
@@ -22,72 +22,73 @@
 *
 *
 *      Copyright 2009-2010 Sun Microsystems, Inc.
 *      Portions copyright 2011-2013 ForgeRock AS.
 *      Portions copyright 2011-2012 ForgeRock AS.
 */
package org.forgerock.opendj.virtual;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.ConnectionFactory;
import org.forgerock.opendj.ldap.ErrorResultException;
import org.forgerock.opendj.ldap.FutureResult;
import org.forgerock.opendj.ldap.ResultHandler;
/**
 * Create a JDBC driver instance which contains all the methods for
 * connection and commands to the database.
 * Create a JDBC driver instance which contains all the methods for
 * connection to the database.
 */
public class JDBCConnectionFactory {
    private String driverName = "com.mysql.jdbc.Driver";
    private 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.
public final class JDBCConnectionFactory implements ConnectionFactory {
   private String ConnectionUrl = "";
   private final String Host;
   private final int Port;
   private final String DbName;
    private JDBCConnection jdbc;
   /**
     * Set up a JDBC connection configuration.
     *
     * @param host
     *            The host address of the database.
     *            The hostname of the database to connect.
     * @param port
     *            The port used to connect to the database.
     * @param databaseName
     *            The name of the database to connect with.
     *           The port used to connect to the database.
     * @param dbName
     *            The name of the database.
     * @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;
    public JDBCConnectionFactory(final String host, final int port, final String dbName) {
        this.Host = host;
        this.Port = port;
        this.DbName = dbName;
        this.ConnectionUrl="jdbc:mysql://"
            .concat(this.Host+":")
            .concat(this.Port+"/")
            .concat(this.DbName);
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public Connection getConnection() throws ErrorResultException {
      if (this.jdbc == null){
         this.jdbc = new JDBCConnection(this.ConnectionUrl);
      }
         return this.jdbc;
    }
    /**
     * 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());
            }
    }
   @Override
   public FutureResult<Connection> getConnectionAsync(
         ResultHandler<? super Connection> handler) {
      //TODO
      return null;
   }
}
opendj-sdk/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JDBCMapper.java
New file
@@ -0,0 +1,231 @@
/*
 * 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 2010 Sun Microsystems, Inc.
 *      Portions copyright 2011 ForgeRock AS
 */
package org.forgerock.opendj.virtual;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.forgerock.opendj.ldap.Attribute;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.ErrorResultException;
import org.forgerock.opendj.ldap.ErrorResultIOException;
import org.forgerock.opendj.ldap.SearchResultReferenceIOException;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
import org.forgerock.opendj.ldif.ConnectionEntryReader;
public final class JDBCMapper {
   final private java.sql.Connection jdbcConnection;
   final private Connection ldapConnection;
   final private ArrayList<String> tables = new ArrayList<String>();
   final private Map<String, ArrayList<String>> tableColumnsMap = new HashMap<String, ArrayList<String>>();
   final private Map<String, String> tableColumnNullableMap = new HashMap<String, String>();
   final private Map<String, String> tableColumnDataTypeMap = new HashMap<String, String>();
   final private ArrayList <String> organizationalUnits = new ArrayList<String>();
   final private Map<String, ArrayList<String>> organizationalUnitAttributesMap = new HashMap<String, ArrayList<String>>();
   private Map<String, String> SQLToLDAPMap = new HashMap<String, String>();
   JDBCMapper(final Connection jdbcconnection, final Connection ldapconnection) {
        this.jdbcConnection = ((JDBCConnection) jdbcconnection).getSqlConnection();
        this.ldapConnection = ldapconnection;
    }
   public void closeConnections() throws SQLException{
      this.jdbcConnection.close();
      this.ldapConnection.close();
   }
   public void fillMaps() throws ErrorResultException, ErrorResultIOException, SearchResultReferenceIOException, SQLException{
      fillTablesList();
      fillTableColumnsMap();
      fillOrganizationalUnitsList();
      fillOrganizationalUnitAttributesMap();
   }
    private void fillTablesList() throws SQLException{
      final String sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE " +
            "TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA='opendj_db'";
      final Statement st = jdbcConnection.createStatement();
      final ResultSet rs = st.executeQuery(sql);
      while(rs.next()){
         tables.add(rs.getString(1));
       }
    }
    private void fillTableColumnsMap() throws SQLException, ErrorResultIOException, SearchResultReferenceIOException{
      for(int i =0; i < tables.size(); i++){
         final String tableName = tables.get(i);
         final String sql = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + tableName + "'";
         final Statement st = jdbcConnection.createStatement();
         final ResultSet rs = st.executeQuery(sql);
         final ArrayList<String> columnsList = new ArrayList<String>();
         String columnName = "", columnNullable = "", columnDataType = "";
         while(rs.next()){
            columnName = rs.getString(4);
            columnNullable = rs.getString(7);
            columnDataType = rs.getString(8);
            columnsList.add(columnName);
            tableColumnNullableMap.put(tableName + ":" + columnName, columnNullable);
            tableColumnDataTypeMap.put(tableName + ":" + columnName, columnDataType);
         }
         tableColumnsMap.put(tableName, columnsList);
      }
    }
   public ArrayList<String> getTables() throws SQLException{
      return tables;
    }
    public ArrayList<String> getTableColumns(String tableName) throws SQLException{
      final ArrayList<String> tableColumnsList = tableColumnsMap.get(tableName);
      return tableColumnsList;
    }
    public boolean getTableColumnNullable(String tableName, String columnName){
      String mappingKey = tableName + ":" + columnName;
      String nullable = tableColumnNullableMap.get(mappingKey);
      if(nullable.equals("NO")) return false;
      else return true;
    }
    public Object getTableColumnDataType(String tableName, String columnName){
      String mappingKey = tableName + ":" + columnName;
      String mappingValue = tableColumnDataTypeMap.get(mappingKey);
      if(mappingValue.equals("int")) return Integer.class;
      return String.class;
    }
    public ArrayList<String> getOrganizationalUnits(){
      return organizationalUnits;
    }
    public ArrayList<String> getOrganizationalUnitAttributes(String organizationalUnitName){
      final ArrayList<String> organizationalUnitAttributesList = organizationalUnitAttributesMap.get(organizationalUnitName);
      return organizationalUnitAttributesList;
    }
    private void fillOrganizationalUnitsList() throws ErrorResultException, ErrorResultIOException, SearchResultReferenceIOException{
        ConnectionEntryReader reader = ldapConnection.search("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "ou=*");
        while (reader.hasNext()) {
         final SearchResultEntry entry = reader.readEntry();
            final Iterator<Attribute> it = entry.getAllAttributes().iterator();
            organizationalUnits.add(it.next().firstValueAsString());
        }
    }
    private void fillOrganizationalUnitAttributesMap() throws ErrorResultIOException, SearchResultReferenceIOException{
      for(int i=0; i < organizationalUnits.size(); i++){
         final String organizationalUnitName = organizationalUnits.get(i);
         final ConnectionEntryReader reader = ldapConnection.search("ou=" + organizationalUnitName + ",dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "uid=*");
         if(reader.hasNext()){
            final Iterator<Attribute> it = reader.readEntry().getAllAttributes().iterator();
            final ArrayList <String> attributesList = new ArrayList <String>();
               while(it.hasNext()){
                  final Attribute att = it.next();
                  attributesList.add(att.getAttributeDescriptionAsString());
               }
               organizationalUnitAttributesMap.put(organizationalUnitName, attributesList);
         }
        }
    }
    public void addCurrentMapToMapping(String tableName, String[] columnNames, String OUName, String[] attributeNames){
      String mappingKey, mappingValue;
      for(int i = 0; i < columnNames.length; i++){
         mappingKey = tableName + ":" + columnNames[i];
         mappingValue = OUName + ":" + attributeNames[i];
         SQLToLDAPMap.put(mappingKey, mappingValue);
      }
    }
    public Map<String, String> getMapping(){
      return SQLToLDAPMap;
    }
   public Map<String, String> loadCurrentMapFromMapping(String tableName) {
      String mappingKey, mappingValue;
      final ArrayList<String> tableColumnsList = tableColumnsMap.get(tableName);
      Map<String, String> currentMap = new HashMap<String, String>();
      for(int i = 0; i < tableColumnsList.size(); i++){
         mappingKey = tableName + ":" + tableColumnsList.get(i);
         if(!SQLToLDAPMap.containsKey(mappingKey)) continue;
         mappingValue = SQLToLDAPMap.get(mappingKey);
         currentMap.put(mappingKey, mappingValue);
      }
      return currentMap;
   }
   public void loadMappingConfig(Map<String, String> m){
      this.SQLToLDAPMap = m;
   }
   public String getTableNameFromMapping(String organizationalUnit) {
      for (Entry<String, String> entry : SQLToLDAPMap.entrySet()) {
         String mappingValue = entry.getValue();
           if (mappingValue.contains(organizationalUnit)) {
            String mappingKey = entry.getKey();
            String stringSplitter[] = mappingKey.split(":");
            String tableName = stringSplitter[0];
               return tableName;
           }
       }
      return null;
   }
   public String getColumnNameFromMapping(String tableName, String organizationalUnitName, String attributeName) {
      for (Entry<String, String> entry : SQLToLDAPMap.entrySet()) {
         String mappingValue = entry.getValue();
           if (mappingValue.equals(organizationalUnitName + ":" + attributeName)) {
            String mappingKey = entry.getKey();
            if(mappingKey.contains(tableName)){
               String stringSplitter[] = mappingKey.split(":");
               String columnName = stringSplitter[1];
                  return columnName;
            }
           }
       }
      return null;
   }
}
opendj-sdk/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/MappingConfigurationManager.java
New file
@@ -0,0 +1,92 @@
/*
 * 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 2010 Sun Microsystems, Inc.
 *      Portions copyright 2011 ForgeRock AS
 */
package org.forgerock.opendj.virtual;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class MappingConfigurationManager
{
   private JDBCMapper JDBCM;
   private Properties prop;
   public MappingConfigurationManager(JDBCMapper jdbcm){
      prop = new Properties();
      JDBCM = jdbcm;
   }
   public void saveMapping(Map<String, String> mapper){
      String mappingKey, mappingValue;
      Set<String> mapperKeySet = mapper.keySet();
      try {
         for(Iterator<String> i = mapperKeySet.iterator(); i.hasNext(); ){
            mappingKey = i.next();
            mappingValue = mapper.get(mappingKey);
            prop.setProperty(mappingKey, mappingValue);
         }
         prop.store(new FileOutputStream("MappingConfig.properties"), null);
         System.out.println("Save succesful!");
      } catch (IOException ex) {
         ex.printStackTrace();
      }
    }
   public Map<String, String> loadMapping() throws SQLException{
      try {
         prop.load(new FileInputStream("MappingConfig.properties"));
         ArrayList<String> tableNames = JDBCM.getTables();
         Map<String, String> mapper = new HashMap<String, String>();
         for(int i = 0; i < tableNames.size(); i++){
            String columnName, mappingKey, mappingValue, tableName = tableNames.get(i);
            ArrayList<String> columnNames = JDBCM.getTableColumns(tableName);
            for(Iterator<String> j = columnNames.iterator(); j.hasNext(); ) {
              columnName = j.next();
              mappingKey = tableName + ":" + columnName;
              mappingValue = prop.getProperty(tableName + ":" + columnName);
              if(mappingValue != null)mapper.put(mappingKey, mappingValue);
            }
         }
         return mapper;
      } catch (IOException ex) {
         ex.printStackTrace();
         return null;
        }
   }
}
opendj-sdk/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/TestUpdate.class
Binary files differ
opendj-sdk/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/package-info.java
File was deleted
opendj-sdk/opendj3/opendj-virtual/src/test/java/org/forgerock/opendj/virtual/AddRequestTestCase.java
New file
@@ -0,0 +1,71 @@
/*
 * 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 2010 Sun Microsystems, Inc.
 *      Portions copyright 2011 ForgeRock AS
 */
package org.forgerock.opendj.virtual;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.LDAPConnectionFactory;
import org.forgerock.opendj.ldap.requests.AddRequest;
import org.forgerock.opendj.ldap.requests.Requests;
public class AddRequestTestCase {
   public static void main(String args[])throws Exception {
       final JDBCConnectionFactory JDBC = new JDBCConnectionFactory("localhost", 3306, "opendj_db");
       JDBCConnection jdbcconnection = (JDBCConnection) JDBC.getConnection();
       jdbcconnection.bind("root", "".toCharArray());
       final LDAPConnectionFactory LDAP = new LDAPConnectionFactory("localhost", 389);
        final Connection ldapconnection = LDAP.getConnection();
        ldapconnection.bind("cn=Directory Manager", "opendj".toCharArray());
       final JDBCMapper JDBCM = new JDBCMapper(jdbcconnection, ldapconnection);
       jdbcconnection.initializeMapper(JDBCM);
       AddRequest testRequest1 = Requests.newAddRequest("dn: uid=user.1,ou=People,dc=example,dc=com",
            "objectClass: top",
            "objectClass: person",
            "objectClass: inetOrgPerson",
            "givenName: Glenn",
            "sn: Van Lint",
            "cn: Glenn Van Lint",
            "employeeNumber: 1");
      jdbcconnection.add(testRequest1);
      String[] ldifLines = {"dn: uid=user.2,ou=People,dc=example,dc=com",
            "objectClass: top",
            "objectClass: person",
            "objectClass: inetOrgPerson",
            "givenName: Jochen",
            "sn: Raymaekers",
            "cn: Jochen Raymaekers",
            "employeeNumber: 2"};
      jdbcconnection.add(ldifLines);
    }
}
opendj-sdk/opendj3/opendj-virtual/src/test/java/org/forgerock/opendj/virtual/Example.java
File was deleted
opendj-sdk/opendj3/opendj-virtual/src/test/java/org/forgerock/opendj/virtual/GUI.java
New file
@@ -0,0 +1,306 @@
/*
 * 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 2010 Sun Microsystems, Inc.
 *      Portions copyright 2011 ForgeRock AS
 */
package org.forgerock.opendj.virtual;
import java.awt.event.*;
import java.sql.SQLException;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.ErrorResultException;
import org.forgerock.opendj.ldap.ErrorResultIOException;
import org.forgerock.opendj.ldap.LDAPConnectionFactory;
import org.forgerock.opendj.ldap.SearchResultReferenceIOException;
public class GUI implements ActionListener{
  //Definition of global values and items that are part of the GUI.
  static JFrame frame = new JFrame("Login Screen");
  private JPanel totalGUI;
  private JLabel label, label_1, label_2, label_3, label_4,label_5, label_6, lblBasedn, label_8, label_9;
  private JPanel buttonPane;
  private JButton btnLogin, btnCancel;
  //login pane Normal
  private JPanel loginPane;
  private JTextField txtHost, txtPort, txtDatabaseName, txtUsername;
  private JPasswordField txtPassword;
  //login pane Ldap
  private JPanel loginPaneLdap;
  private JTextField txtHostLdap, txtPortLdap,txtBaseDN,txtUsernameLdap;
  private JPasswordField txtPasswordLdap;
  public JPanel createContentPane (){
    totalGUI = new JPanel();
    totalGUI.setLayout(null);
    buttonPane = new JPanel();
    buttonPane.setLayout(null);
    buttonPane.setBounds(143, 143, 291, 30);
    totalGUI.add(buttonPane);
    btnLogin = new JButton("Login");
    btnLogin.setBounds(0, 0, 145, 30);
    btnLogin.addActionListener(this);
    buttonPane.add(btnLogin);
    btnCancel = new JButton("Cancel");
    btnCancel.setBounds(145, 1, 147, 29);
    btnCancel.addActionListener(this);
    buttonPane.add(btnCancel);
    loginPane = new JPanel();
    loginPane.setLayout(null);
    loginPane.setBounds(6, 6, 274, 125);
    totalGUI.add(loginPane);
    label = new JLabel("Host");
    label.setHorizontalAlignment(SwingConstants.TRAILING);
    label.setBounds(0, 2, 112, 23);
    loginPane.add(label);
    txtHost = new JTextField();
    txtHost.setColumns(10);
    txtHost.setBounds(124, 2, 146, 23);
    loginPane.add(txtHost);
    label_1 = new JLabel("Port");
    label_1.setHorizontalAlignment(SwingConstants.TRAILING);
    label_1.setBounds(0, 25, 112, 23);
    loginPane.add(label_1);
    txtPort = new JTextField();
    txtPort.setColumns(10);
    txtPort.setBounds(124, 25, 146, 23);
    loginPane.add(txtPort);
    label_2 = new JLabel("DatabaseName");
    label_2.setHorizontalAlignment(SwingConstants.TRAILING);
    label_2.setBounds(0, 48, 112, 23);
    loginPane.add(label_2);
    txtDatabaseName = new JTextField();
    txtDatabaseName.setColumns(10);
    txtDatabaseName.setBounds(124, 48, 146, 23);
    loginPane.add(txtDatabaseName);
    label_3 = new JLabel("Username");
    label_3.setHorizontalAlignment(SwingConstants.TRAILING);
    label_3.setBounds(0, 71, 112, 23);
    loginPane.add(label_3);
    txtUsername = new JTextField();
    txtUsername.setColumns(10);
    txtUsername.setBounds(124, 71, 146, 23);
    loginPane.add(txtUsername);
    label_4 = new JLabel("Password");
    label_4.setHorizontalAlignment(SwingConstants.TRAILING);
    label_4.setBounds(0, 94, 112, 23);
    loginPane.add(label_4);
    txtPassword = new JPasswordField();
    txtPassword.setBounds(124, 94, 146, 23);
    loginPane.add(txtPassword);
    loginPaneLdap = new JPanel();
    loginPaneLdap.setLayout(null);
    loginPaneLdap.setBounds(292, 6, 274, 125);
    totalGUI.add(loginPaneLdap);
    label_5 = new JLabel("Host");
    label_5.setHorizontalAlignment(SwingConstants.TRAILING);
    label_5.setBounds(0, 2, 112, 23);
    loginPaneLdap.add(label_5);
    txtHostLdap = new JTextField();
    txtHostLdap.setColumns(10);
    txtHostLdap.setBounds(124, 2, 146, 23);
    loginPaneLdap.add(txtHostLdap);
    label_6 = new JLabel("Port");
    label_6.setHorizontalAlignment(SwingConstants.TRAILING);
    label_6.setBounds(0, 25, 112, 23);
    loginPaneLdap.add(label_6);
    txtPortLdap = new JTextField();
    txtPortLdap.setColumns(10);
    txtPortLdap.setBounds(124, 25, 146, 23);
    loginPaneLdap.add(txtPortLdap);
    lblBasedn = new JLabel("BaseDN");
    lblBasedn.setHorizontalAlignment(SwingConstants.TRAILING);
    lblBasedn.setBounds(0, 48, 112, 23);
    loginPaneLdap.add(lblBasedn);
    txtBaseDN = new JTextField();
    txtBaseDN.setColumns(10);
    txtBaseDN.setBounds(124, 48, 146, 23);
    loginPaneLdap.add(txtBaseDN);
    label_8 = new JLabel("Username");
    label_8.setHorizontalAlignment(SwingConstants.TRAILING);
    label_8.setBounds(0, 71, 112, 23);
    loginPaneLdap.add(label_8);
    txtUsernameLdap = new JTextField();
    txtUsernameLdap.setColumns(10);
    txtUsernameLdap.setBounds(124, 71, 146, 23);
    loginPaneLdap.add(txtUsernameLdap);
    label_9 = new JLabel("Password");
    label_9.setHorizontalAlignment(SwingConstants.TRAILING);
    label_9.setBounds(0, 94, 112, 23);
    loginPaneLdap.add(label_9);
    txtPasswordLdap = new JPasswordField();
    txtPasswordLdap.setBounds(124, 94, 146, 23);
    loginPaneLdap.add(txtPasswordLdap);
    txtHost.setText("localhost");
    txtPort.setText("3306");
    txtUsername.setText("root");
    txtDatabaseName.setText("opendj_db");
    txtHostLdap.setText("localhost");
    txtPortLdap.setText("389");
    txtBaseDN.setText("dc=example,dc=com");
    txtUsernameLdap.setText("cn=Directory Manager");
    return totalGUI;
  }
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    JDBCConnectionFactory JDBC = null;
    LDAPConnectionFactory LDAP = null;
    if((source == btnLogin))
    {
      String aHost = txtHost.getText(); //read aHost from the screen as a string
      String lHost = txtHostLdap.getText();
      String aPort = txtPort.getText();
      String lPort = txtPortLdap.getText();
      Integer intaPort = null;
      Integer intlPort = null;
      String aDatabase = txtDatabaseName.getText();
      String lBaseDN = txtBaseDN.getText();
      String aUsername = txtUsername.getText();
      String lUsername = txtUsernameLdap.getText();
      try {
        // aHost = txtHost.getText();
        if  ((aHost.isEmpty()) || (lHost.isEmpty()))
          //if entry is made then throw error
          throw new IllegalArgumentException("Enter Host address");
        else if ((aPort.isEmpty()) || (lPort.isEmpty()))
        {
          throw new IllegalArgumentException("Enter port number");
        }
        else if ((aDatabase.isEmpty()) || (lBaseDN.isEmpty()))
        {
          throw new IllegalArgumentException("Enter database name");
        }
        else if ((aUsername.isEmpty()) || lUsername.isEmpty())
        {
          throw new IllegalArgumentException("Enter username number");
        }
        //otherwise setup connection
        else
        {
          try{
            intaPort = Integer.parseInt(aPort);
            intlPort = Integer.parseInt(lPort);
            JDBC = new JDBCConnectionFactory(aHost, intaPort, aDatabase);
            final Connection jdbcconnection = JDBC.getConnection();
          jdbcconnection.bind(aUsername, txtPassword.getPassword());
          LDAP = new LDAPConnectionFactory(lHost, intlPort);
           final Connection ldapconnection = LDAP.getConnection();
           ldapconnection.bind(lUsername, txtPasswordLdap.getPassword());
            //TODO aanpassen connection failed
            frame.dispose();
            new GUIMap(JDBC, LDAP);
          } catch (NumberFormatException ex){
            JOptionPane.showMessageDialog(frame, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
          } catch (ErrorResultException e1) {
         e1.printStackTrace();
      } catch (ErrorResultIOException e1) {
         e1.printStackTrace();
      } catch (SearchResultReferenceIOException e1) {
         e1.printStackTrace();
      } catch (SQLException e1) {
         e1.printStackTrace();
      }
        }
      }
      catch (IllegalArgumentException x)   {   // catch the error
        JOptionPane.showMessageDialog(frame, x.getMessage(), "Warning", JOptionPane.ERROR_MESSAGE);
      }
    }
    else if(source == btnCancel)
    {
      System.exit(0);
    }
  }
  private static void createAndShowGUI() {
    // JFrame.setDefaultLookAndFeelDecorated(true);
    try {
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        //System.out.println(info.getName());
        if ("Nimbus".equals(info.getName())) {
          UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (Exception e) {
      // If Nimbus is not available, you can set the GUI to another look and feel.
    }
    //Create and set up the content pane.
    GUI gui = new GUI();
    frame.setContentPane(gui.createContentPane());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(600, 225);
    frame.setVisible(true);
    frame.setResizable(false);
    frame.setEnabled(true);
    frame.setLocationRelativeTo(null);
  }
  public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        createAndShowGUI();
      }
    });
  }
}
opendj-sdk/opendj3/opendj-virtual/src/test/java/org/forgerock/opendj/virtual/GUIMap.java
New file
@@ -0,0 +1,330 @@
/*
 * 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 2010 Sun Microsystems, Inc.
 *      Portions copyright 2011 ForgeRock AS
 */
package org.forgerock.opendj.virtual;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.table.*;
import org.forgerock.opendj.ldap.ErrorResultException;
import org.forgerock.opendj.ldap.ErrorResultIOException;
import org.forgerock.opendj.ldap.LDAPConnectionFactory;
import org.forgerock.opendj.ldap.SearchResultReferenceIOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@SuppressWarnings("serial")
class MyTable extends AbstractTableModel {
   public MyTable(){}
     private String[] columnNames = {"Columns",
       "Attributes"
     };
     public Object[][] data = {};
     public int getColumnCount() {
       return columnNames.length;
     }
     public int getRowCount() {
       return data.length;
     }
     public String getColumnName(int col) {
       return columnNames[col];
     }
     public Object getValueAt(int row, int col) {
       return data[row][col];
     }
     public boolean isCellEditable(int row, int col) {
       if (col == 1) {
         return true;
       } else {
         return false;
       }
     }
     public void setValueAt(Object value, int row, int col) {
       data[row][col] = value;
       fireTableCellUpdated(row, col);
     }
}
@SuppressWarnings("serial")
public class GUIMap extends JPanel implements ActionListener {
  //Definition of global values and items that are part of the GUI.
  static JFrame frame = new JFrame("Mapping configuration");
  private JPanel totalGUI, inputPane, dataPane,btnPane;
  private JComboBox<Object> tableList, directoryOUList;
  private JButton btnSetMap, btnResetMap, btnSave, btnQuitConnection;
  private JLabel lblDatabaseTables, lblSelectOu;
  private JDBCMapper JDBCM;
  private JTable table;
  private JScrollPane scrollPane;
  private MappingConfigurationManager mcm;
  static DefaultTableModel model;
  static String[] tableNameList;
  static String[] OUNameList;
  public GUIMap(JDBCConnectionFactory jdbc, LDAPConnectionFactory ldap) throws ErrorResultException, ErrorResultIOException, SearchResultReferenceIOException, SQLException
  {
   JDBCM = new JDBCMapper(jdbc.getConnection(), ldap.getConnection());
   JDBCM.fillMaps();
   List<String> tableStringList = JDBCM.getTables();
   List<String> OUStringList = JDBCM.getOrganizationalUnits();
   tableNameList = new String[tableStringList.size()];
   OUNameList = new String[OUStringList.size()];
   mcm = new MappingConfigurationManager(JDBCM);
   JDBCM.loadMappingConfig(mcm.loadMapping());
   for (int i = 0; i < tableStringList.size(); i++){
      tableNameList[i] = tableStringList.get(i);
   }
   for (int i = 0; i < OUStringList.size(); i++){
      OUNameList[i] = OUStringList.get(i);
   }
    try{
      //JFrame.setDefaultLookAndFeelDecorated(true);
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        //System.out.println(info.getName());
        if ("Nimbus".equals(info.getName())) {
          UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (Exception e) {
      // If Nimbus is not available, you can set the GUI to another look and feel.
    }
    frame.setResizable(false);
    frame.setContentPane(createContentPane());
    frame.setEnabled(true);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(523, 487);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
  /**
   * @return
 * @throws SQLException
   */
  public JPanel createContentPane () throws SQLException{
    totalGUI = new JPanel();
    totalGUI.setLayout(null);
    inputPane = new JPanel();
    inputPane.setBounds(6, 5, 507, 61);
    totalGUI.add(inputPane);
    inputPane.setLayout(null);
    tableList = new JComboBox<Object>(tableNameList);
    tableList.setToolTipText("Click to change table");
    tableList.setMaximumRowCount(4);
    tableList.setBounds(6,35,230,27);
    tableList.addActionListener(this);
    inputPane.add(tableList);
    directoryOUList = new JComboBox<Object>(OUNameList);
    directoryOUList.setToolTipText("Click to change OU");
    directoryOUList.setMaximumRowCount(4);
    directoryOUList.setBounds(271, 35, 230, 27);
    inputPane.add(directoryOUList);
    lblDatabaseTables = new JLabel("Select table");
    lblDatabaseTables.setBounds(75, 15, 128, 16);
    inputPane.add(lblDatabaseTables);
    lblSelectOu = new JLabel("Select OU\n");
    lblSelectOu.setBounds(350, 15, 128, 16);
    inputPane.add(lblSelectOu);
    directoryOUList.addActionListener(this);
    dataPane = new JPanel();
    dataPane.setBounds(6, 75, 511, 308);
    totalGUI.add(dataPane);
    dataPane.setLayout(new GridLayout(0, 1, 0, 0));
    //Create the scroll pane and add the table to it.
    scrollPane = new JScrollPane();
    fillTable();
    UpdateTable();
    dataPane.add(scrollPane);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);
    table.getTableHeader().setReorderingAllowed(false);
    table.getTableHeader().setResizingAllowed(false);
    btnPane = new JPanel();
    btnPane.setLayout(null);
    btnPane.setBounds(100, 390, 500, 60);
    totalGUI.add(btnPane);
    btnSetMap = new JButton("Save current mapping");
    btnSetMap.setBounds(0, 0, 175, 30);
    btnSetMap.addActionListener(this);
    btnPane.add(btnSetMap);
    btnResetMap = new JButton("Reset current mapping");
    btnResetMap.setBounds(180, 0, 175, 30);
    btnResetMap.addActionListener(this);
    btnPane.add(btnResetMap);
    btnSave = new JButton("Save to file");
    btnSave.setBounds(30, 30, 145, 30);
    btnSave.addActionListener(this);
    btnPane.add(btnSave);
    btnQuitConnection = new JButton("Close");
    btnQuitConnection.setBounds(180, 30, 145, 30);
    btnQuitConnection.addActionListener(this);
    btnPane.add(btnQuitConnection);
    return totalGUI;
  }
  private void fillTable() throws SQLException {
     String tableName = tableList.getSelectedItem().toString();
     ArrayList<String> columnsList = JDBCM.getTableColumns(tableName);
      Object[][] rowData = new Object[columnsList.size()][2];
     for(int i = 0; i < columnsList.size(); i++){
        String columnName = columnsList.get(i);
        if(!JDBCM.getTableColumnNullable(tableName, columnName)){
           columnName = columnName.concat("(*)");
        }
        rowData[i][0] = columnName;
        rowData[i][1] = "----";
      }
     MyTable myTable = new MyTable();
     myTable.data = rowData;
     table = new JTable(myTable);
     scrollPane.setViewportView(table);
      createTableComboBoxList();
}
  private void createTableComboBoxList(){
     JComboBox<String> comboBox = new JComboBox<String>();
     ArrayList<String> attributesList = JDBCM.getOrganizationalUnitAttributes(directoryOUList.getSelectedItem().toString());
     for(int i = 0; i < attributesList.size(); i++){
        comboBox.addItem(attributesList.get(i));
     }
     TableColumn directoryColumn = table.getColumnModel().getColumn(1);
     directoryColumn.setCellEditor(new DefaultCellEditor(comboBox));
     DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
     directoryColumn.setCellRenderer(renderer);
  }
  public void UpdateTable(){
       String tableName = tableList.getSelectedItem().toString();
      Map<String, String> currentMap = JDBCM.loadCurrentMapFromMapping(tableName);
      if(!currentMap.isEmpty()){
         String mappingKey, mappingValue;
         MyTable mt = (MyTable) table.getModel();
         for(int i = 0; i < mt.data.length; i++){
            mappingKey = tableName + ":" + mt.data[i][0].toString();
            mappingKey = mappingKey.replace("(*)", "");
            mappingValue = currentMap.get(mappingKey);
            String[] stringSplitter = mappingValue.split((":"));
            mt.data[i][1] = stringSplitter[1];
         }
      }
  }
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if((source == tableList) || (source == directoryOUList))
    {
      try {
         fillTable();
         createTableComboBoxList();
         if(source == tableList){
            UpdateTable();
         }
      } catch (SQLException e1) {
         e1.printStackTrace();
      }
    }
    else if(source == btnSetMap){
      MyTable mt = (MyTable) table.getModel();
      String tableName = tableList.getSelectedItem().toString();
      String OUName = directoryOUList.getSelectedItem().toString();
      String [] columnStrings = new String[mt.data.length], attributeStrings = new String[mt.data.length];
      boolean success = true;
      String columnName, attributeName;
      for(int i = 0; i < mt.data.length; i++){
         columnName = mt.data[i][0].toString();
         attributeName = mt.data[i][1].toString();
         if(columnName.contains("(*)") && attributeName.equals("----")){
            success = false;
            JOptionPane.showMessageDialog(frame, "Map all the required fields!", "Error", JOptionPane.ERROR_MESSAGE);
            break;
         }
         columnStrings[i] = columnName.replace("(*)", "");
         attributeStrings[i] = attributeName;
      }
      if(success) JDBCM.addCurrentMapToMapping(tableName, columnStrings, OUName, attributeStrings);
    }
    else if(source == btnSave){
      mcm.saveMapping(JDBCM.getMapping());
    }
    else if(source == btnResetMap){
      try {
         fillTable();
      } catch (SQLException e1) {
         e1.printStackTrace();
      }
    }
    else if(source == btnQuitConnection){
      try {
         JDBCM.closeConnections();
      } catch (SQLException e1) {
         e1.printStackTrace();
      }
      System.exit(0);
    }
  }
}
opendj-sdk/opendj3/opendj-virtual/src/test/java/org/forgerock/opendj/virtual/JDBCConnectionTestCase.java
File was renamed from opendj-sdk/opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/JoinConnectionFactory.java
@@ -21,9 +21,22 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2009-2010 Sun Microsystems, Inc.
 *      Portions copyright 2011-2012 ForgeRock AS.
 *      Copyright 2010 Sun Microsystems, Inc.
 *      Portions copyright 2011 ForgeRock AS
 */
package org.forgerock.opendj.virtual;
import org.forgerock.opendj.ldap.Connection;
/**
 * This class provides tests the JDBCConnection.
 */
public class JDBCConnectionTestCase {
    public static void main(String args[])throws Exception {
          final JDBCConnectionFactory JDBC = new JDBCConnectionFactory("localhost", 3306, "opendj_db");
          Connection con = JDBC.getConnection();
          con.bind("root", "".toCharArray());
       }
}
opendj-sdk/opendj3/opendj-virtual/src/test/java/org/forgerock/opendj/virtual/JDBCMapperTestCase.java
New file
@@ -0,0 +1,81 @@
/*
 * 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 2010 Sun Microsystems, Inc.
 *      Portions copyright 2011 ForgeRock AS
 */
package org.forgerock.opendj.virtual;
import java.util.ArrayList;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.LDAPConnectionFactory;
public class JDBCMapperTestCase {
    public static void main(String args[])throws Exception {
          final JDBCConnectionFactory JDBC = new JDBCConnectionFactory("localhost", 3306, "opendj_db");
          final Connection jdbcconnection = JDBC.getConnection();
          jdbcconnection.bind("root", "".toCharArray());
          final LDAPConnectionFactory LDAP = new LDAPConnectionFactory("localhost", 389);
           final Connection ldapconnection = LDAP.getConnection();
           ldapconnection.bind("cn=Directory Manager", "opendj".toCharArray());
          final JDBCMapper JDBCM = new JDBCMapper(jdbcconnection, ldapconnection);
          JDBCM.fillMaps();
          final ArrayList<String> tablesList = JDBCM.getTables();
          final ArrayList<String> organizationalUnitsList = JDBCM.getOrganizationalUnits();
          for(int i = 0; i < tablesList.size(); i++){
            final String tableName = tablesList.get(i);
            System.out.println("Table: " + tableName);
            final ArrayList<String> columnsList = JDBCM.getTableColumns(tableName);
            if(columnsList != null){
               for(int j = 0; j < columnsList.size(); j++){
                  System.out.println(columnsList.get(j));
                }
               System.out.println();
            }
          }
          for(int i = 0; i < organizationalUnitsList.size(); i++){
            final String organizationalUnitName = organizationalUnitsList.get(i);
            System.out.println("OU: " + organizationalUnitName);
            final ArrayList<String> attributesList = JDBCM.getOrganizationalUnitAttributes(organizationalUnitName);
            if(attributesList != null){
               for(int j = 0; j < attributesList.size(); j++){
                  System.out.println(attributesList.get(j));
                }
               System.out.println();
            }
          }
    }
}