|
| ElementDB (IElement element) |
|
Connection | getConnection () throws SQLException |
|
boolean | positionFirst (ResultSet rs, int first) throws SQLException |
|
boolean | iterate (ResultSet rs, int count, int current) throws SQLException |
|
int | findLast (ResultSet rs) throws SQLException |
|
ResultSet | query (String sql) throws SQLException |
|
ResultSet | query (String sql, Collection params) throws SQLException |
|
ResultSet | query (String sql, Object[] params) throws SQLException |
|
int | execute (String sql) throws SQLException |
|
int | execute (String sql, Collection params) throws SQLException |
|
int | execute (String sql, Object[] params) throws SQLException |
|
void | execute (String commands[]) throws SQLException |
|
void | close (ResultSet rs) throws SQLException |
|
void | close () throws SQLException |
|
void | renderNavigator (PrintWriter out, String param) |
|
java.util.Date | toDate (java.sql.Timestamp date) |
|
java.sql.Timestamp | toTimestamp (java.util.Date date) |
|
java.util.Date | toDate (java.sql.Date date) |
|
java.sql.Date | toSqlDate (java.util.Date date) |
|
- Author
- Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g
Definition at line 37 of file ElementDB.java.
◆ ElementDB()
org.turro.elephant.db.ElementDB.ElementDB |
( |
IElement |
element | ) |
|
◆ close() [1/2]
void org.turro.elephant.db.ElementDB.close |
( |
| ) |
throws SQLException |
◆ close() [2/2]
void org.turro.elephant.db.ElementDB.close |
( |
ResultSet |
rs | ) |
throws SQLException |
◆ execute() [1/4]
void org.turro.elephant.db.ElementDB.execute |
( |
String |
commands[] | ) |
throws SQLException |
◆ execute() [2/4]
int org.turro.elephant.db.ElementDB.execute |
( |
String |
sql | ) |
throws SQLException |
Definition at line 138 of file ElementDB.java.
140 return con.createStatement().executeUpdate(sql);
Connection getConnection()
◆ execute() [3/4]
int org.turro.elephant.db.ElementDB.execute |
( |
String |
sql, |
|
|
Collection |
params |
|
) |
| throws SQLException |
◆ execute() [4/4]
int org.turro.elephant.db.ElementDB.execute |
( |
String |
sql, |
|
|
Object[] |
params |
|
) |
| throws SQLException |
Definition at line 147 of file ElementDB.java.
152 PreparedStatement ps = con.prepareStatement(sql);
153 for(
int i = 0; i < params.length; i++) {
154 if(params[i] !=
null) {
155 ps.setObject(i + 1, params[i]);
158 ps.setNull(i + 1, java.sql.Types.VARCHAR);
161 return ps.executeUpdate();
◆ findLast()
int org.turro.elephant.db.ElementDB.findLast |
( |
ResultSet |
rs | ) |
throws SQLException |
◆ getConnection()
Connection org.turro.elephant.db.ElementDB.getConnection |
( |
| ) |
throws SQLException |
Definition at line 50 of file ElementDB.java.
51 if(
conn ==
null ||
conn.isClosed()) {
52 String driverClass = ((IManageable)
element).getAttributes().getAttributeValue(
"attrib:jdbc-driver",
null),
53 url = ((IManageable)
element).getAttributes().getAttributeValue(
"attrib:jdbc-url",
null),
54 user = ((IManageable)
element).getAttributes().getAttributeValue(
"attrib:jdbc-user",
null),
55 password = ((IManageable)
element).getAttributes().getAttributeValue(
"attrib:jdbc-password",
null);
56 if(driverClass !=
null && url !=
null) {
59 url = url.replaceAll(
"\\#ctx",
60 ElephantContext.getRealPath(
63 url = url.replaceAll(
"\\#root", ElephantContext.getRealPath(
"/"));
64 url = url.replaceAll(
"\\\\",
"/");
66 Class.forName(driverClass);
67 if(user !=
null && user.length() > 0 && password !=
null) {
68 conn = DriverManager.getConnection(url, user, password);
71 conn = DriverManager.getConnection(url);
74 }
catch (ClassNotFoundException | SQLException ex) {
75 Logger.getLogger(
ElementDB.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
ElementDB(IElement element)
◆ iterate()
boolean org.turro.elephant.db.ElementDB.iterate |
( |
ResultSet |
rs, |
|
|
int |
count, |
|
|
int |
current |
|
) |
| throws SQLException |
◆ positionFirst()
boolean org.turro.elephant.db.ElementDB.positionFirst |
( |
ResultSet |
rs, |
|
|
int |
first |
|
) |
| throws SQLException |
Definition at line 84 of file ElementDB.java.
86 boolean hasNext =
true;
88 while((current < first) && hasNext) {
◆ query() [1/3]
ResultSet org.turro.elephant.db.ElementDB.query |
( |
String |
sql | ) |
throws SQLException |
Definition at line 112 of file ElementDB.java.
114 return con.createStatement().executeQuery(sql);
◆ query() [2/3]
ResultSet org.turro.elephant.db.ElementDB.query |
( |
String |
sql, |
|
|
Collection |
params |
|
) |
| throws SQLException |
Definition at line 117 of file ElementDB.java.
118 return query(sql, params.toArray());
ResultSet query(String sql)
◆ query() [3/3]
ResultSet org.turro.elephant.db.ElementDB.query |
( |
String |
sql, |
|
|
Object[] |
params |
|
) |
| throws SQLException |
Definition at line 121 of file ElementDB.java.
126 PreparedStatement ps = con.prepareStatement(sql);
127 for(
int i = 0; i < params.length; i++) {
128 if(params[i] !=
null) {
129 ps.setObject(i + 1, params[i]);
132 ps.setNull(i + 1, java.sql.Types.VARCHAR);
135 return ps.executeQuery();
◆ renderNavigator()
void org.turro.elephant.db.ElementDB.renderNavigator |
( |
PrintWriter |
out, |
|
|
String |
param |
|
) |
| |
Definition at line 179 of file ElementDB.java.
180 if(totalCount <= lastCount)
return;
181 out.print(
"<div class='dbnav'>");
185 out.print(
"<a href='?" + param +
"=" + (
lastFirst - lastCount) +
"'>");
186 out.print(
"<<");
190 int iter = (int)Math.ceil(((
double)totalCount) / ((double)lastCount));
191 for(
int i = 0; i < iter; i++) {
193 out.print(
"<li class='active'>");
198 out.print(
"<a href='?" + param +
"=" + (i * lastCount) +
"'>");
205 out.print(
"<a href='?" + param +
"=" + (
lastFirst + lastCount) +
"'>");
206 out.print(
">>");
◆ toDate() [1/2]
java.util.Date org.turro.elephant.db.ElementDB.toDate |
( |
java.sql.Date |
date | ) |
|
Definition at line 224 of file ElementDB.java.
225 if(date ==
null)
return null;
226 return new java.util.Date(date.getTime());
◆ toDate() [2/2]
java.util.Date org.turro.elephant.db.ElementDB.toDate |
( |
java.sql.Timestamp |
date | ) |
|
Definition at line 214 of file ElementDB.java.
215 if(date ==
null)
return null;
216 return new java.util.Date(date.getTime());
◆ toSqlDate()
java.sql.Date org.turro.elephant.db.ElementDB.toSqlDate |
( |
java.util.Date |
date | ) |
|
Definition at line 229 of file ElementDB.java.
230 if(date ==
null)
return null;
231 return new java.sql.Date(date.getTime());
◆ toTimestamp()
java.sql.Timestamp org.turro.elephant.db.ElementDB.toTimestamp |
( |
java.util.Date |
date | ) |
|
Definition at line 219 of file ElementDB.java.
220 if(date ==
null)
return null;
221 return new java.sql.Timestamp(date.getTime());
◆ conn
Connection org.turro.elephant.db.ElementDB.conn = null |
|
protected |
◆ element
IElement org.turro.elephant.db.ElementDB.element |
|
protected |
◆ lastFirst
int org.turro.elephant.db.ElementDB.lastFirst |
|
protected |
The documentation for this class was generated from the following file: