Skip to content

Commit 4f2c68a

Browse files
authored
Merge pull request #1 from eduramiba/OracleDriver
Style and logging fixes. Add long HTML description for plugins site.
2 parents d5ca06e + e16b207 commit 4f2c68a

File tree

5 files changed

+195
-275
lines changed

5 files changed

+195
-275
lines changed

modules/OracleDriver/pom.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>gephi-plugin-parent</artifactId>
66
<groupId>org.gephi</groupId>
7-
<version>0.9.0</version>
7+
<version>0.9.1</version>
88
</parent>
99

1010
<groupId>oracle-troubadour.co.uk</groupId>
@@ -15,11 +15,10 @@
1515
<name>Oracle Driver</name>
1616

1717
<dependencies>
18-
<dependency>
19-
<groupId>org.gephi</groupId>
20-
<artifactId>db-drivers</artifactId>
21-
<version>0.9.0</version>
22-
</dependency>
18+
<dependency>
19+
<groupId>org.gephi</groupId>
20+
<artifactId>db-drivers</artifactId>
21+
</dependency>
2322
</dependencies>
2423

2524
<build>
@@ -32,10 +31,10 @@
3231
<author>Stuart Turton</author>
3332
<authorEmail></authorEmail>
3433
<authorUrl></authorUrl>
35-
<sourceCodeUrl>$sourcecode_url</sourceCodeUrl>
34+
<sourceCodeUrl>https://github.com/sturton/gephi-plugins</sourceCodeUrl>
3635
<publicPackages>
3736
<!-- Insert public packages -->
38-
<publicPackage>uk.co.oracletroubadour</publicPackage>
37+
<publicPackage>uk.co.oracletroubadour</publicPackage>
3938
</publicPackages>
4039
</configuration>
4140
</plugin>
Lines changed: 76 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
/*
2-
* To change this template, choose Tools | Templates
3-
* and open the template in the editor.
4-
*/
5-
package uk.co.oracletroubadour.gephi.plugins;
1+
package uk.co.oracletroubadour.gephi.plugins;
62

73
import java.io.File;
84

9-
import java.sql.Connection;
105
import java.sql.Driver;
116
import java.sql.DriverManager;
12-
import java.sql.SQLException;
137

148
import java.net.MalformedURLException;
159
import java.net.URL;
@@ -18,150 +12,107 @@
1812
import java.util.logging.*;
1913
import java.util.*;
2014

21-
2215
/**
2316
*
2417
* @author Stuart Turton
2518
*/
26-
public class JDBCUtils
27-
{
19+
public class JDBCUtils {
20+
2821
/**
2922
* An Oracle JDBC thin driver SQLDriver implementation for GEPHI.
30-
*
31-
* @see org.gephi.io.database.drivers.SQLDriver
23+
*
24+
* @see org.gephi.io.database.drivers.SQLDriver
3225
*/
33-
private static final String CLASS_NAME =JDBCUtils.class.getName();
26+
private static final String CLASS_NAME = JDBCUtils.class.getName();
3427

3528
private static final Logger logger = Logger.getLogger(CLASS_NAME);
3629

37-
38-
public void registerDriver(String driverClass, List<String> driverPaths) throws Exception
39-
{
40-
logger.warning("registerDriver: Before") ;
41-
logger.warning("registerDriver: driverPaths , size="+ driverPaths.size() ) ;
42-
for (String path : driverPaths)
43-
{
44-
logger.warning("registerDriver: driverPath =\""+ path +"\"" ) ;
45-
}
46-
47-
48-
String[] driverPathsArray = new String[ driverPaths.size() ] ;
49-
logger.warning("registerDriver: Array size :"+ driverPathsArray.length ) ;
50-
registerDriver(driverClass, driverPaths.toArray(driverPathsArray) );
51-
logger.warning("registerDriver: After") ;
30+
public void registerDriver(String driverClass, List<String> driverPaths) throws Exception {
31+
logger.info("registerDriver: Before");
32+
logger.log(Level.INFO, "registerDriver: driverPaths , size={0}", driverPaths.size());
33+
for (String path : driverPaths) {
34+
logger.log(Level.INFO, "registerDriver: driverPath =\"{0}\"", path);
35+
}
36+
37+
String[] driverPathsArray = new String[driverPaths.size()];
38+
logger.log(Level.INFO, "registerDriver: Array size :{0}", driverPathsArray.length);
39+
registerDriver(driverClass, driverPaths.toArray(driverPathsArray));
40+
logger.info("registerDriver: After");
5241
}
5342

54-
public void registerDriver(String driverClass, String[] driverPaths) throws Exception
55-
{
56-
57-
try
58-
{
59-
Driver driver = getDriver(driverClass, driverPaths );
60-
DriverManager.registerDriver(driver) ;
61-
}
62-
catch (Exception e)
63-
{
64-
System.err.println(e);
65-
throw new Exception ("Failed to register class \""+driverClass+"\" using paths \"" + driverPaths + "\"."
66-
,e
67-
);
68-
}
69-
}
43+
public void registerDriver(String driverClass, String[] driverPaths) throws Exception {
7044

71-
public Driver getDriver(String driverClass, List<String> driverPaths) throws Exception
72-
{
73-
return getDriver(driverClass, driverPaths.toArray(new String[driverPaths.size()] ) ) ;
45+
try {
46+
Driver driver = getDriver(driverClass, driverPaths);
47+
DriverManager.registerDriver(driver);
48+
} catch (Exception e) {
49+
logger.log(Level.SEVERE, e.getMessage(), e);
50+
throw new Exception("Failed to register class \"" + driverClass + "\" using paths \"" + Arrays.toString(driverPaths) + "\".", e);
51+
}
7452
}
7553

76-
public Driver getDriver(String driverClass, String driverPath) throws Exception
77-
{
78-
return getDriver(driverClass, new String[] { driverPath } ) ;
54+
public Driver getDriver(String driverClass, List<String> driverPaths) throws Exception {
55+
return getDriver(driverClass, driverPaths.toArray(new String[driverPaths.size()]));
7956
}
8057

81-
public Driver getDriver(String driverClass, String[] driverPaths) throws Exception
82-
{
83-
List<URL> classpath = null ;
84-
ClassLoader loader = null ;
85-
Driver driver = null;
86-
87-
if( null != driverPaths && driverPaths.length > 0 )
88-
{
89-
classpath = new ArrayList<URL>() ;
90-
for (String path : driverPaths )
91-
{
92-
classpath.addAll( getExistingUrls(path) );
93-
}
94-
}
95-
96-
logger.warning("classpath has "+ classpath.size() + " elements" ) ;
97-
logger.warning("classpath: "+ classpath ) ;
98-
loader = getDriverClassLoader(classpath);
99-
logger.warning("ClassLoader generated" ) ;
100-
101-
try
102-
{
103-
logger.warning("searching for Driver with custom ClassLoader" ) ;
104-
driver = (Driver) Class.forName(driverClass, true, loader).newInstance();
105-
logger.warning("Driver returned" ) ;
106-
}
107-
catch (Exception e)
108-
{
109-
System.err.println(e);
110-
logger.throwing (CLASS_NAME, "getDriver", e ) ;
111-
throw new Exception ("Could not find class \""+driverClass+"\" in paths \"" + driverPaths + "\"."
112-
, e
113-
);
114-
}
115-
116-
return driver ;
58+
public Driver getDriver(String driverClass, String driverPath) throws Exception {
59+
return getDriver(driverClass, new String[]{driverPath});
11760
}
11861

62+
public Driver getDriver(String driverClass, String[] driverPaths) throws Exception {
63+
List<URL> classpath = null;
64+
Driver driver = null;
65+
66+
if (null != driverPaths && driverPaths.length > 0) {
67+
classpath = new ArrayList<URL>();
68+
for (String path : driverPaths) {
69+
classpath.addAll(getExistingUrls(path));
70+
}
71+
}
72+
73+
logger.log(Level.INFO, "classpath has {0} elements", classpath.size());
74+
logger.log(Level.INFO, "classpath: {0}", classpath);
75+
ClassLoader loader = getDriverClassLoader(classpath);
76+
logger.info("ClassLoader generated");
77+
78+
try {
79+
logger.info("searching for Driver with custom ClassLoader");
80+
driver = (Driver) Class.forName(driverClass, true, loader).newInstance();
81+
logger.info("Driver returned");
82+
} catch (Exception e) {
83+
logger.log(Level.SEVERE, e.getMessage(), e);
84+
logger.throwing(CLASS_NAME, "getDriver", e);
85+
throw new Exception("Could not find class \"" + driverClass + "\" in paths \"" + Arrays.toString(driverPaths) + "\".", e);
86+
}
87+
88+
return driver;
89+
}
11990

120-
public ClassLoader getDriverClassLoader (List<URL> classpath)
121-
{
122-
ClassLoader loader = null ;
123-
124-
if ( null != classpath && classpath.size() > 0 )
125-
{
126-
//Extend the existing ClassLoader with the passed in list of URLs
127-
loader = new URLClassLoader(classpath.toArray( new URL[classpath.size()])
128-
,getClass().getClassLoader()
129-
);
130-
}
131-
else
132-
{
133-
loader = getClass().getClassLoader();
134-
}
91+
public ClassLoader getDriverClassLoader(List<URL> classpath) {
92+
ClassLoader loader;
13593

94+
if (classpath != null && !classpath.isEmpty()) {
95+
//Extend the existing ClassLoader with the passed in list of URLs
96+
loader = new URLClassLoader(classpath.toArray(new URL[classpath.size()]), getClass().getClassLoader());
97+
} else {
98+
loader = getClass().getClassLoader();
99+
}
136100

137-
return loader ;
101+
return loader;
138102
}
139103

104+
public List<URL> getExistingUrls(String path) throws MalformedURLException {
105+
List<URL> existingUrls = new ArrayList<URL>();
140106

107+
String[] pieces = path.split(File.pathSeparator);
108+
for (String piece : pieces) {
109+
File file = new File(piece);
110+
if (file.exists()) {
111+
existingUrls.add(file.toURI().toURL());
112+
}
113+
}
141114

142-
public List<URL> getExistingUrls (String path) throws MalformedURLException
143-
{
144-
List<URL> existingUrls = new ArrayList<URL>() ;
145-
146-
String[] pieces = path.split(File.pathSeparator);
147-
for (String piece : pieces )
148-
{
149-
File file = new File(piece);
150-
if (file.exists())
151-
{
152-
existingUrls.add(file.toURI().toURL()) ;
153-
}
154-
}
155-
156-
return existingUrls ;
115+
return existingUrls;
157116
}
158117

159-
160-
161118
}
162-
163-
164-
165-
166-
167-

0 commit comments

Comments
 (0)