📄 jdbcstore.java
字号:
return (this.sessionAppCol);
}
/**
* Set the Id column for the table.
*
* @param sessionIdCol the column name
*/
public void setSessionIdCol(String sessionIdCol) {
String oldSessionIdCol = this.sessionIdCol;
this.sessionIdCol = sessionIdCol;
support.firePropertyChange("sessionIdCol",
oldSessionIdCol,
this.sessionIdCol);
}
/**
* Return the Id column for the table.
*/
public String getSessionIdCol() {
return (this.sessionIdCol);
}
/**
* Set the Data column for the table
*
* @param sessionDataCol the column name
*/
public void setSessionDataCol(String sessionDataCol) {
String oldSessionDataCol = this.sessionDataCol;
this.sessionDataCol = sessionDataCol;
support.firePropertyChange("sessionDataCol",
oldSessionDataCol,
this.sessionDataCol);
}
/**
* Return the data column for the table
*/
public String getSessionDataCol() {
return (this.sessionDataCol);
}
/**
* Set the Is Valid column for the table
*
* @param sessionValidCol The column name
*/
public void setSessionValidCol(String sessionValidCol) {
String oldSessionValidCol = this.sessionValidCol;
this.sessionValidCol = sessionValidCol;
support.firePropertyChange("sessionValidCol",
oldSessionValidCol,
this.sessionValidCol);
}
/**
* Return the Is Valid column
*/
public String getSessionValidCol() {
return (this.sessionValidCol);
}
/**
* Set the Max Inactive column for the table
*
* @param sessionMaxInactiveCol The column name
*/
public void setSessionMaxInactiveCol(String sessionMaxInactiveCol) {
String oldSessionMaxInactiveCol = this.sessionMaxInactiveCol;
this.sessionMaxInactiveCol = sessionMaxInactiveCol;
support.firePropertyChange("sessionMaxInactiveCol",
oldSessionMaxInactiveCol,
this.sessionMaxInactiveCol);
}
/**
* Return the Max Inactive column
*/
public String getSessionMaxInactiveCol() {
return (this.sessionMaxInactiveCol);
}
/**
* Set the Last Accessed column for the table
*
* @param sessionLastAccessedCol The column name
*/
public void setSessionLastAccessedCol(String sessionLastAccessedCol) {
String oldSessionLastAccessedCol = this.sessionLastAccessedCol;
this.sessionLastAccessedCol = sessionLastAccessedCol;
support.firePropertyChange("sessionLastAccessedCol",
oldSessionLastAccessedCol,
this.sessionLastAccessedCol);
}
/**
* Return the Last Accessed column
*/
public String getSessionLastAccessedCol() {
return (this.sessionLastAccessedCol);
}
// --------------------------------------------------------- Public Methods
/**
* Return an array containing the session identifiers of all Sessions
* currently saved in this Store. If there are no such Sessions, a
* zero-length array is returned.
*
* @exception IOException if an input/output error occurred
*/
public String[] keys() throws IOException {
ResultSet rst = null;
String keys[] = null;
synchronized (this) {
int numberOfTries = 2;
while (numberOfTries > 0) {
Connection _conn = getConnection();
if (_conn == null) {
return (new String[0]);
}
try {
if (preparedKeysSql == null) {
String keysSql = "SELECT " + sessionIdCol + " FROM "
+ sessionTable + " WHERE " + sessionAppCol
+ " = ?";
preparedKeysSql = _conn.prepareStatement(keysSql);
}
preparedKeysSql.setString(1, getName());
rst = preparedKeysSql.executeQuery();
ArrayList tmpkeys = new ArrayList();
if (rst != null) {
while (rst.next()) {
tmpkeys.add(rst.getString(1));
}
}
keys = (String[]) tmpkeys.toArray(new String[tmpkeys.size()]);
// Break out after the finally block
numberOfTries = 0;
} catch (SQLException e) {
manager.getContainer().getLogger().error(sm.getString(getStoreName() + ".SQLException", e));
keys = new String[0];
// Close the connection so that it gets reopened next time
if (dbConnection != null)
close(dbConnection);
} finally {
try {
if (rst != null) {
rst.close();
}
} catch (SQLException e) {
;
}
release(_conn);
}
numberOfTries--;
}
}
return (keys);
}
/**
* Return an integer containing a count of all Sessions
* currently saved in this Store. If there are no Sessions,
* <code>0</code> is returned.
*
* @exception IOException if an input/output error occurred
*/
public int getSize() throws IOException {
int size = 0;
ResultSet rst = null;
synchronized (this) {
int numberOfTries = 2;
while (numberOfTries > 0) {
Connection _conn = getConnection();
if (_conn == null) {
return (size);
}
try {
if (preparedSizeSql == null) {
String sizeSql = "SELECT COUNT(" + sessionIdCol
+ ") FROM " + sessionTable + " WHERE "
+ sessionAppCol + " = ?";
preparedSizeSql = _conn.prepareStatement(sizeSql);
}
preparedSizeSql.setString(1, getName());
rst = preparedSizeSql.executeQuery();
if (rst.next()) {
size = rst.getInt(1);
}
// Break out after the finally block
numberOfTries = 0;
} catch (SQLException e) {
manager.getContainer().getLogger().error(sm.getString(getStoreName() + ".SQLException", e));
if (dbConnection != null)
close(dbConnection);
} finally {
try {
if (rst != null)
rst.close();
} catch (SQLException e) {
;
}
release(_conn);
}
numberOfTries--;
}
}
return (size);
}
/**
* Load the Session associated with the id <code>id</code>.
* If no such session is found <code>null</code> is returned.
*
* @param id a value of type <code>String</code>
* @return the stored <code>Session</code>
* @exception ClassNotFoundException if an error occurs
* @exception IOException if an input/output error occurred
*/
public Session load(String id)
throws ClassNotFoundException, IOException {
ResultSet rst = null;
StandardSession _session = null;
Loader loader = null;
ClassLoader classLoader = null;
ObjectInputStream ois = null;
BufferedInputStream bis = null;
Container container = manager.getContainer();
synchronized (this) {
int numberOfTries = 2;
while (numberOfTries > 0) {
Connection _conn = getConnection();
if (_conn == null) {
return (null);
}
try {
if (preparedLoadSql == null) {
String loadSql = "SELECT " + sessionIdCol + ", "
+ sessionDataCol + " FROM " + sessionTable
+ " WHERE " + sessionIdCol + " = ? AND "
+ sessionAppCol + " = ?";
preparedLoadSql = _conn.prepareStatement(loadSql);
}
preparedLoadSql.setString(1, id);
preparedLoadSql.setString(2, getName());
rst = preparedLoadSql.executeQuery();
if (rst.next()) {
bis = new BufferedInputStream(rst.getBinaryStream(2));
if (container != null) {
loader = container.getLoader();
}
if (loader != null) {
classLoader = loader.getClassLoader();
}
if (classLoader != null) {
ois = new CustomObjectInputStream(bis,
classLoader);
} else {
ois = new ObjectInputStream(bis);
}
if (manager.getContainer().getLogger().isDebugEnabled()) {
manager.getContainer().getLogger().debug(sm.getString(getStoreName() + ".loading",
id, sessionTable));
}
_session = (StandardSession) manager.createEmptySession();
_session.readObjectData(ois);
_session.setManager(manager);
} else if (manager.getContainer().getLogger().isDebugEnabled()) {
manager.getContainer().getLogger().debug(getStoreName() + ": No persisted data object found");
}
// Break out after the finally block
numberOfTries = 0;
} catch (SQLException e) {
manager.getContainer().getLogger().error(sm.getString(getStoreName() + ".SQLException", e));
if (dbConnection != null)
close(dbConnection);
} finally {
try {
if (rst != null) {
rst.close();
}
} catch (SQLException e) {
;
}
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
;
}
}
release(_conn);
}
numberOfTries--;
}
}
return (_session);
}
/**
* Remove the Session with the specified session identifier from
* this Store, if present. If no such Session is present, this method
* takes no action.
*
* @param id Session identifier of the Session to be removed
*
* @exception IOException if an input/output error occurs
*/
public void remove(String id) throws IOException {
synchronized (this) {
int numberOfTries = 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -