Skip to content

Commit b0c90e8

Browse files
committed
- New version of java wrappers as the "wrappers" package
deleted: storage/connect/JdbcApacheInterface.class deleted: storage/connect/JdbcApacheInterface.java deleted: storage/connect/JdbcDSInterface.class deleted: storage/connect/JdbcDSInterface.java modified: storage/connect/JdbcInterface.java modified: storage/connect/ha_connect.cc modified: storage/connect/jdbconn.cpp modified: storage/connect/jdbconn.h modified: storage/connect/tabjdbc.cpp modified: storage/connect/tabjdbc.h added: storage/connect/ApacheInterface.java added: storage/connect/Client.java added: storage/connect/JdbcInterface.jar added: storage/connect/MariadbInterface.java added: storage/connect/MysqlInterface.java added: storage/connect/OracleInterface.java added: storage/connect/PostgresqlInterface.java added: storage/connect/wrappers/ApacheInterface.class added: storage/connect/wrappers/Client.class added: storage/connect/wrappers/JdbcInterface.class added: storage/connect/wrappers/MariadbInterface.class added: storage/connect/wrappers/MysqlInterface.class added: storage/connect/wrappers/OracleInterface.class added: storage/connect/wrappers/PostgresqlInterface.class
1 parent 92dbe32 commit b0c90e8

24 files changed

+593
-1493
lines changed

storage/connect/ApacheInterface.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package wrappers;
2+
3+
import java.sql.*;
4+
import java.util.Hashtable;
5+
import org.apache.commons.dbcp2.BasicDataSource;
6+
7+
public class ApacheInterface extends JdbcInterface {
8+
static Hashtable<String,BasicDataSource> pool = new Hashtable<String, BasicDataSource>();
9+
10+
public ApacheInterface() {
11+
this(true);
12+
} // end of default constructor
13+
14+
public ApacheInterface(boolean b) {
15+
super(b);
16+
} // end of constructor
17+
18+
@Override
19+
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
20+
int rc = 0;
21+
String url = parms[1];
22+
BasicDataSource ds = null;
23+
24+
if (DEBUG)
25+
System.out.println("Connecting to Apache data source");
26+
27+
try {
28+
if (url == null)
29+
throw new Exception("URL cannot be null");
30+
31+
if ((ds = pool.get(url)) == null) {
32+
ds = new BasicDataSource();
33+
ds.setDriverClassName(parms[0]);
34+
ds.setUrl(url);
35+
ds.setUsername(parms[2]);
36+
ds.setPassword(parms[3]);
37+
pool.put(url, ds);
38+
} // endif ds
39+
40+
// Get a connection from the data source
41+
conn = ds.getConnection();
42+
43+
// Get the data base meta data object
44+
dbmd = conn.getMetaData();
45+
46+
// Get a statement from the connection
47+
stmt = GetStmt(fsize, scrollable);
48+
} catch (SQLException se) {
49+
SetErrmsg(se);
50+
rc = -2;
51+
} catch (Exception e) {
52+
SetErrmsg(e);
53+
rc = -3;
54+
} // end try/catch
55+
56+
return rc;
57+
} // end of JdbcConnect
58+
59+
} // end of class ApacheInterface

storage/connect/Client.java

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
package wrappers;
2+
3+
import java.io.BufferedReader;
4+
import java.io.Console;
5+
import java.io.IOException;
6+
import java.io.InputStreamReader;
7+
8+
public class Client {
9+
static boolean DEBUG = true;
10+
static final Console c = System.console();
11+
static JdbcInterface jdi = null;
12+
13+
public static void main(String[] args) {
14+
int rc, n, ncol, i = 0, fsize = 0;
15+
boolean scrollable = false;
16+
String s;
17+
String[] parms = new String[4];
18+
19+
if (args.length > 0)
20+
try {
21+
i = Integer.parseInt(args[i]);
22+
} catch (NumberFormatException e) {
23+
i = 0;
24+
} // end try/catch
25+
26+
switch (i) {
27+
case 1:
28+
jdi = new ApacheInterface(DEBUG);
29+
break;
30+
case 2:
31+
jdi = new MysqlInterface(DEBUG);
32+
break;
33+
case 3:
34+
jdi = new MariadbInterface(DEBUG);
35+
break;
36+
case 4:
37+
jdi = new OracleInterface(DEBUG);
38+
break;
39+
case 5:
40+
jdi = new PostgresqlInterface(DEBUG);
41+
break;
42+
default:
43+
jdi = new JdbcInterface(DEBUG);
44+
} // endswitch i
45+
46+
parms[0] = getLine("Driver: ", false);
47+
parms[1] = getLine("URL: ", false);
48+
parms[2] = getLine("User: ", false);
49+
parms[3] = getLine("Password: ", true);
50+
s = getLine("Fsize: ", false);
51+
fsize = (s != null) ? Integer.parseInt(s) : 0;
52+
s = getLine("Scrollable: ", false);
53+
scrollable = (s != null) ? s.toLowerCase().charAt(0) != 'n' : false;
54+
55+
rc = jdi.JdbcConnect(parms, fsize, scrollable);
56+
57+
if (rc == 0) {
58+
String query;
59+
System.out.println("Successfully connected to " + parms[1]);
60+
61+
while ((query = getLine("Query: ", false)) != null) {
62+
n = jdi.Execute(query);
63+
System.out.println("Returned n = " + n);
64+
65+
if ((ncol = jdi.GetResult()) > 0)
66+
PrintResult(ncol);
67+
else
68+
System.out.println("Affected rows = " + n);
69+
70+
} // endwhile
71+
72+
rc = jdi.JdbcDisconnect();
73+
System.out.println("Disconnect returned " + rc);
74+
} else
75+
System.out.println(jdi.GetErrmsg() + " rc=" + rc);
76+
77+
} // end of main
78+
79+
private static void PrintResult(int ncol) {
80+
// Get result set meta data
81+
int i;
82+
String columnName;
83+
84+
// Get the column names; column indices start from 1
85+
for (i = 1; i <= ncol; i++) {
86+
columnName = jdi.ColumnName(i);
87+
88+
if (columnName == null)
89+
return;
90+
91+
// Get the name of the column's table name
92+
//String tableName = rsmd.getTableName(i);
93+
94+
if (i > 1)
95+
System.out.print("\t");
96+
97+
System.out.print(columnName);
98+
} // endfor i
99+
100+
System.out.println();
101+
102+
// Loop through the result set
103+
while (jdi.ReadNext() > 0) {
104+
for (i = 1; i <= ncol; i++) {
105+
if (i > 1)
106+
System.out.print("\t");
107+
108+
if (DEBUG)
109+
System.out.print("(" + jdi.ColumnType(i, null) + ")");
110+
111+
switch (jdi.ColumnType(i, null)) {
112+
case java.sql.Types.VARCHAR:
113+
case java.sql.Types.LONGVARCHAR:
114+
case java.sql.Types.CHAR:
115+
System.out.print(jdi.StringField(i, null));
116+
break;
117+
case java.sql.Types.INTEGER:
118+
System.out.print(jdi.IntField(i, null));
119+
break;
120+
case java.sql.Types.BIGINT:
121+
System.out.print(jdi.BigintField(i, null));
122+
break;
123+
case java.sql.Types.TIMESTAMP:
124+
System.out.print(jdi.TimestampField(i, null));
125+
break;
126+
case java.sql.Types.TIME:
127+
System.out.print(jdi.TimeField(i, null));
128+
break;
129+
case java.sql.Types.DATE:
130+
System.out.print(jdi.DateField(i, null));
131+
break;
132+
case java.sql.Types.SMALLINT:
133+
System.out.print(jdi.IntField(i, null));
134+
break;
135+
case java.sql.Types.DOUBLE:
136+
case java.sql.Types.REAL:
137+
case java.sql.Types.FLOAT:
138+
case java.sql.Types.DECIMAL:
139+
System.out.print(jdi.DoubleField(i, null));
140+
break;
141+
case java.sql.Types.BOOLEAN:
142+
System.out.print(jdi.BooleanField(i, null));
143+
default:
144+
break;
145+
} // endswitch Type
146+
147+
} // endfor i
148+
149+
System.out.println();
150+
} // end while rs
151+
152+
} // end of PrintResult
153+
154+
// ==================================================================
155+
private static String getLine(String p, boolean b) {
156+
String response;
157+
158+
if (c != null) {
159+
// Standard console mode
160+
if (b) {
161+
response = new String(c.readPassword(p));
162+
} else
163+
response = c.readLine(p);
164+
165+
} else {
166+
// For instance when testing from Eclipse
167+
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
168+
169+
System.out.print(p);
170+
171+
try {
172+
// Cannot suppress echo for password entry
173+
response = in.readLine();
174+
} catch (IOException e) {
175+
response = "";
176+
} // end of try/catch
177+
178+
} // endif c
179+
180+
return (response.isEmpty()) ? null : response;
181+
} // end of getLine
182+
183+
} // end of class Client
-15 KB
Binary file not shown.

0 commit comments

Comments
 (0)