View Javadoc

1   package com.ontotext.ordi.mapper.rdbms;
2   
3   import java.util.HashSet;
4   import java.util.Set;
5   
6   import org.openrdf.model.URI;
7   
8   import com.ontotext.ordi.exception.ORDIRuntimeException;
9   import com.ontotext.ordi.mapper.model.DataSource;
10  
11  public class RDBMSDataSource implements DataSource {
12  
13      private URI name;
14      private String connectionString;
15      private static Set<String> drivers = new HashSet<String>();
16  
17      public RDBMSDataSource(URI name, String driverName, String connectionString) {
18          if (name == null || connectionString == null || driverName == null) {
19              throw new IllegalArgumentException();
20          }
21          this.name = name;
22          this.connectionString = connectionString;
23  
24          synchronized (drivers) {
25              if (drivers.contains(driverName) == false) {
26                  try {
27                      Class.forName(driverName);
28                      drivers.add(driverName);
29                  } catch (ClassNotFoundException ce) {
30                      throw new ORDIRuntimeException(String.format(
31                              "The database driver %s could not be loaded!",
32                              driverName));
33                  }
34              }
35          }
36      }
37  
38      public URI getName() {
39          return name;
40      }
41  
42      public String getConnectionString() {
43          return connectionString;
44      }
45  
46  }