Merge branch 'jetty-9.4.x' of github.com:eclipse/jetty.project into jetty-9.4.x

This commit is contained in:
Greg Wilkins 2016-09-16 17:17:02 +10:00
commit 98da23c374
2 changed files with 40 additions and 22 deletions

View File

@ -130,6 +130,9 @@ public class DatabaseAdaptor
*/ */
public String convertIdentifier (String identifier) public String convertIdentifier (String identifier)
{ {
if (identifier == null)
return null;
if (_dbName == null) if (_dbName == null)
throw new IllegalStateException ("DbAdaptor missing metadata"); throw new IllegalStateException ("DbAdaptor missing metadata");

View File

@ -65,6 +65,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
public final static int MAX_INTERVAL_NOT_SET = -999; public final static int MAX_INTERVAL_NOT_SET = -999;
protected DatabaseAdaptor _dbAdaptor; protected DatabaseAdaptor _dbAdaptor;
protected String _schemaName = null;
protected String _tableName = "JettySessions"; protected String _tableName = "JettySessions";
protected String _idColumn = "sessionId"; protected String _idColumn = "sessionId";
protected String _contextPathColumn = "contextPath"; protected String _contextPathColumn = "contextPath";
@ -85,7 +86,15 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
{ {
_dbAdaptor = dbadaptor; _dbAdaptor = dbadaptor;
} }
public String getSchemaName()
{
return _schemaName;
}
public void setSchemaName(String schemaName)
{
checkNotNull(schemaName);
_schemaName = schemaName;
}
public String getTableName() public String getTableName()
{ {
@ -97,6 +106,11 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
_tableName = tableName; _tableName = tableName;
} }
private String getSchemaTableName()
{
return (getSchemaName()!=null?getSchemaName()+".":"")+getTableName();
}
public String getIdColumn() public String getIdColumn()
{ {
return _idColumn; return _idColumn;
@ -223,12 +237,12 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
public String getCreateIndexOverExpiryStatementAsString (String indexName) public String getCreateIndexOverExpiryStatementAsString (String indexName)
{ {
return "create index "+indexName+" on "+getTableName()+" ("+getExpiryTimeColumn()+")"; return "create index "+indexName+" on "+getSchemaTableName()+" ("+getExpiryTimeColumn()+")";
} }
public String getCreateIndexOverSessionStatementAsString (String indexName) public String getCreateIndexOverSessionStatementAsString (String indexName)
{ {
return "create index "+indexName+" on "+getTableName()+" ("+getIdColumn()+", "+getContextPathColumn()+")"; return "create index "+indexName+" on "+getSchemaTableName()+" ("+getIdColumn()+", "+getContextPathColumn()+")";
} }
public String getAlterTableForMaxIntervalAsString () public String getAlterTableForMaxIntervalAsString ()
@ -236,7 +250,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
if (_dbAdaptor == null) if (_dbAdaptor == null)
throw new IllegalStateException ("No DBAdaptor"); throw new IllegalStateException ("No DBAdaptor");
String longType = _dbAdaptor.getLongType(); String longType = _dbAdaptor.getLongType();
String stem = "alter table "+getTableName()+" add "+getMaxIntervalColumn()+" "+longType; String stem = "alter table "+getSchemaTableName()+" add "+getMaxIntervalColumn()+" "+longType;
if (_dbAdaptor.getDBName().contains("oracle")) if (_dbAdaptor.getDBName().contains("oracle"))
return stem + " default "+ MAX_INTERVAL_NOT_SET + " not null"; return stem + " default "+ MAX_INTERVAL_NOT_SET + " not null";
else else
@ -250,7 +264,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
} }
public String getInsertSessionStatementAsString() public String getInsertSessionStatementAsString()
{ {
return "insert into "+getTableName()+ return "insert into "+getSchemaTableName()+
" ("+getIdColumn()+", "+getContextPathColumn()+", "+getVirtualHostColumn()+", "+getLastNodeColumn()+ " ("+getIdColumn()+", "+getContextPathColumn()+", "+getVirtualHostColumn()+", "+getLastNodeColumn()+
", "+getAccessTimeColumn()+", "+getLastAccessTimeColumn()+", "+getCreateTimeColumn()+", "+getCookieTimeColumn()+ ", "+getAccessTimeColumn()+", "+getLastAccessTimeColumn()+", "+getCreateTimeColumn()+", "+getCookieTimeColumn()+
", "+getLastSavedTimeColumn()+", "+getExpiryTimeColumn()+", "+getMaxIntervalColumn()+", "+getMapColumn()+") "+ ", "+getLastSavedTimeColumn()+", "+getExpiryTimeColumn()+", "+getMaxIntervalColumn()+", "+getMapColumn()+") "+
@ -260,7 +274,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
public PreparedStatement getUpdateSessionStatement(Connection connection, String canonicalContextPath) public PreparedStatement getUpdateSessionStatement(Connection connection, String canonicalContextPath)
throws SQLException throws SQLException
{ {
String s = "update "+getTableName()+ String s = "update "+getSchemaTableName()+
" set "+getLastNodeColumn()+" = ?, "+getAccessTimeColumn()+" = ?, "+ " set "+getLastNodeColumn()+" = ?, "+getAccessTimeColumn()+" = ?, "+
getLastAccessTimeColumn()+" = ?, "+getLastSavedTimeColumn()+" = ?, "+getExpiryTimeColumn()+" = ?, "+ getLastAccessTimeColumn()+" = ?, "+getLastSavedTimeColumn()+" = ?, "+getExpiryTimeColumn()+" = ?, "+
getMaxIntervalColumn()+" = ?, "+getMapColumn()+" = ? where "; getMaxIntervalColumn()+" = ?, "+getMapColumn()+" = ? where ";
@ -293,7 +307,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
if (_dbAdaptor.isEmptyStringNull()) if (_dbAdaptor.isEmptyStringNull())
{ {
PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+ PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+
" from "+getTableName()+" where "+ " from "+getSchemaTableName()+" where "+
getContextPathColumn()+" is null and "+ getContextPathColumn()+" is null and "+
getVirtualHostColumn()+" = ? and "+getExpiryTimeColumn()+" >0 and "+getExpiryTimeColumn()+" <= ?"); getVirtualHostColumn()+" = ? and "+getExpiryTimeColumn()+" >0 and "+getExpiryTimeColumn()+" <= ?");
statement.setString(1, vhost); statement.setString(1, vhost);
@ -303,7 +317,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
} }
PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+ PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+
" from "+getTableName()+" where "+getContextPathColumn()+" = ? and "+ " from "+getSchemaTableName()+" where "+getContextPathColumn()+" = ? and "+
getVirtualHostColumn()+" = ? and "+ getVirtualHostColumn()+" = ? and "+
getExpiryTimeColumn()+" >0 and "+getExpiryTimeColumn()+" <= ?"); getExpiryTimeColumn()+" >0 and "+getExpiryTimeColumn()+" <= ?");
@ -325,7 +339,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
if (_dbAdaptor.isEmptyStringNull()) if (_dbAdaptor.isEmptyStringNull())
{ {
PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+ PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+
" from "+getTableName()+" where "+ " from "+getSchemaTableName()+" where "+
getLastNodeColumn() + " = ? and "+ getLastNodeColumn() + " = ? and "+
getContextPathColumn()+" is null and "+ getContextPathColumn()+" is null and "+
getVirtualHostColumn()+" = ? and "+getExpiryTimeColumn()+" >0 and "+getExpiryTimeColumn()+" <= ?"); getVirtualHostColumn()+" = ? and "+getExpiryTimeColumn()+" >0 and "+getExpiryTimeColumn()+" <= ?");
@ -337,7 +351,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
} }
PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+ PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+
" from "+getTableName()+" where "+ " from "+getSchemaTableName()+" where "+
getLastNodeColumn()+" = ? and "+ getLastNodeColumn()+" = ? and "+
getContextPathColumn()+" = ? and "+ getContextPathColumn()+" = ? and "+
getVirtualHostColumn()+" = ? and "+ getVirtualHostColumn()+" = ? and "+
@ -358,7 +372,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
throw new IllegalStateException("No DB adaptor"); throw new IllegalStateException("No DB adaptor");
PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getContextPathColumn()+", "+getVirtualHostColumn()+ PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getContextPathColumn()+", "+getVirtualHostColumn()+
" from "+getTableName()+ " from "+getSchemaTableName()+
" where "+getExpiryTimeColumn()+" >0 and "+getExpiryTimeColumn()+" <= ?"); " where "+getExpiryTimeColumn()+" >0 and "+getExpiryTimeColumn()+" <= ?");
return statement; return statement;
} }
@ -376,7 +390,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
if (_dbAdaptor.isEmptyStringNull()) if (_dbAdaptor.isEmptyStringNull())
{ {
PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+ PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+
" from "+getTableName()+ " from "+getSchemaTableName()+
" where "+getIdColumn()+" = ? and "+ " where "+getIdColumn()+" = ? and "+
getContextPathColumn()+" is null and "+ getContextPathColumn()+" is null and "+
getVirtualHostColumn()+" = ?"); getVirtualHostColumn()+" = ?");
@ -385,7 +399,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
} }
PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+ PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+
" from "+getTableName()+ " from "+getSchemaTableName()+
" where "+getIdColumn()+" = ? and "+ " where "+getIdColumn()+" = ? and "+
getContextPathColumn()+" = ? and "+ getContextPathColumn()+" = ? and "+
getVirtualHostColumn()+" = ?"); getVirtualHostColumn()+" = ?");
@ -422,7 +436,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
{ {
if (_dbAdaptor.isEmptyStringNull()) if (_dbAdaptor.isEmptyStringNull())
{ {
PreparedStatement statement = connection.prepareStatement("select * from "+getTableName()+ PreparedStatement statement = connection.prepareStatement("select * from "+getSchemaTableName()+
" where "+getIdColumn()+" = ? and "+ " where "+getIdColumn()+" = ? and "+
getContextPathColumn()+" is null and "+ getContextPathColumn()+" is null and "+
getVirtualHostColumn()+" = ?"); getVirtualHostColumn()+" = ?");
@ -433,7 +447,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
} }
} }
PreparedStatement statement = connection.prepareStatement("select * from "+getTableName()+ PreparedStatement statement = connection.prepareStatement("select * from "+getSchemaTableName()+
" where "+getIdColumn()+" = ? and "+getContextPathColumn()+ " where "+getIdColumn()+" = ? and "+getContextPathColumn()+
" = ? and "+getVirtualHostColumn()+" = ?"); " = ? and "+getVirtualHostColumn()+" = ?");
statement.setString(1, id); statement.setString(1, id);
@ -451,7 +465,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
if (_dbAdaptor == null) if (_dbAdaptor == null)
throw new IllegalStateException("No DB adaptor"); throw new IllegalStateException("No DB adaptor");
String s = "update "+getTableName()+ String s = "update "+getSchemaTableName()+
" set "+getLastNodeColumn()+" = ?, "+getAccessTimeColumn()+" = ?, "+ " set "+getLastNodeColumn()+" = ?, "+getAccessTimeColumn()+" = ?, "+
getLastAccessTimeColumn()+" = ?, "+getLastSavedTimeColumn()+" = ?, "+getExpiryTimeColumn()+" = ?, "+ getLastAccessTimeColumn()+" = ?, "+getLastSavedTimeColumn()+" = ?, "+getExpiryTimeColumn()+" = ?, "+
getMaxIntervalColumn()+" = ?, "+getMapColumn()+" = ? where "; getMaxIntervalColumn()+" = ?, "+getMapColumn()+" = ? where ";
@ -492,7 +506,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
{ {
if (_dbAdaptor.isEmptyStringNull()) if (_dbAdaptor.isEmptyStringNull())
{ {
PreparedStatement statement = connection.prepareStatement("delete from "+getTableName()+ PreparedStatement statement = connection.prepareStatement("delete from "+getSchemaTableName()+
" where "+getIdColumn()+" = ? and "+getContextPathColumn()+ " where "+getIdColumn()+" = ? and "+getContextPathColumn()+
" = ? and "+getVirtualHostColumn()+" = ?"); " = ? and "+getVirtualHostColumn()+" = ?");
statement.setString(1, id); statement.setString(1, id);
@ -501,7 +515,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
} }
} }
PreparedStatement statement = connection.prepareStatement("delete from "+getTableName()+ PreparedStatement statement = connection.prepareStatement("delete from "+getSchemaTableName()+
" where "+getIdColumn()+" = ? and "+getContextPathColumn()+ " where "+getIdColumn()+" = ? and "+getContextPathColumn()+
" = ? and "+getVirtualHostColumn()+" = ?"); " = ? and "+getVirtualHostColumn()+" = ?");
statement.setString(1, id); statement.setString(1, id);
@ -531,7 +545,9 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
//make the session table if necessary //make the session table if necessary
String tableName = _dbAdaptor.convertIdentifier(getTableName()); String tableName = _dbAdaptor.convertIdentifier(getTableName());
try (ResultSet result = metaData.getTables(null, null, tableName, null)) String schemaName = _dbAdaptor.convertIdentifier(getSchemaName());
System.err.println ("Tablename: "+tableName+" SchemaName:"+schemaName);
try (ResultSet result = metaData.getTables(null, schemaName, tableName, null))
{ {
if (!result.next()) if (!result.next())
{ {
@ -544,8 +560,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
ResultSet colResult = null; ResultSet colResult = null;
try try
{ {
colResult = metaData.getColumns(null, null, colResult = metaData.getColumns(null, schemaName, tableName,
_dbAdaptor.convertIdentifier(getTableName()),
_dbAdaptor.convertIdentifier(getMaxIntervalColumn())); _dbAdaptor.convertIdentifier(getMaxIntervalColumn()));
} }
catch (SQLException s) catch (SQLException s)
@ -585,7 +600,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
boolean index1Exists = false; boolean index1Exists = false;
boolean index2Exists = false; boolean index2Exists = false;
try (ResultSet result = metaData.getIndexInfo(null, null, tableName, false, false)) try (ResultSet result = metaData.getIndexInfo(null, schemaName, tableName, false, true))
{ {
while (result.next()) while (result.next())
{ {