Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion api/src/org/labkey/api/data/DbScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ private static LabKeyDataSource setPrimaryDataSource(Map<String, LabKeyDataSourc
LOG.info(
"Initializing DbScope with the following configuration:" +
"\n DataSource Name: " + getDbScopeLoader().getDsName() +
"\n Server URL: " + dbmd.getURL() +
"\n Server URL: " + filterUrl(dbmd.getURL()) +
"\n Database Name: " + _databaseName +
"\n Database Product Name: " + _databaseProductName +
"\n Database Product Version: " + (null != _dialect ? _dialect.getProductVersion(_databaseProductVersion) : _databaseProductVersion) +
Expand All @@ -615,6 +615,19 @@ private static LabKeyDataSource setPrimaryDataSource(Map<String, LabKeyDataSourc
}
}

// MariaDB driver adds username and password to the URL. This masks the password so we don't log it.
private String filterUrl(String url)
{
int start = url.indexOf("password=");
if (start != -1)
{
start = start + 9;
int end = Math.max(url.length(), url.indexOf('&', start));
url = url.substring(0, start) + StringUtils.repeat('?', end - start) + url.substring(end);
}
return url;
}

private String determineDriverLocation(Class<Driver> driverClass)
{
try
Expand Down
123 changes: 63 additions & 60 deletions api/src/org/labkey/api/data/TableSelectorTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,84 +38,87 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;

/**
* User: adam
* Date: 1/19/12
* Time: 5:54 PM
*/
public class TableSelectorTestCase extends AbstractSelectorTestCase<TableSelector>
{
@Test
public void testTableSelector() throws SQLException
{
// Calls below can be used to test that Oracle and MySQL dialects behave as expected, following our maxRows, offset,
// and other rules. Uncomment these lines and their corresponding bean classes below.

// Call below can be used to test that Oracle dialect behaves as expected, following our maxRows, offset, and other
// rules. Uncomment this line and the corresponding bean class below.
// testTableSelector(DbSchema.get("oracle.granite", DbSchemaType.Bare).getTable("account"), Account.class);
// testTableSelector(DbSchema.get("mySql.sakila", DbSchemaType.Bare).getTable("country"), Country.class);

// Test MySQL database, if present
DbSchema sakila = DbSchema.get("mySql.sakila", DbSchemaType.Bare);
if (sakila.existsInDatabase())
testTableSelector(sakila.getTable("country"), Country.class);
testTableSelector(CoreSchema.getInstance().getTableInfoActiveUsers(), User.class);
testTableSelector(CoreSchema.getInstance().getTableInfoModules(), ModuleContext.class);
}

// public static class Country
// {
// private int _country_id;
// private String _country;
// private Date _last_update;
//
// public int getCountry_id()
// {
// return _country_id;
// }
//
// public void setCountry_id(int country_id)
// {
// _country_id = country_id;
// }
//
// public String getCountry()
// {
// return _country;
// }
//
// public void setCountry(String country)
// {
// _country = country;
// }
//
// public Date getLast_update()
// {
// return _last_update;
// }
//
// public void setLast_update(Date last_update)
// {
// _last_update = last_update;
// }
//
// @Override
// public boolean equals(Object o)
// {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// Country country = (Country) o;
// return _country_id == country._country_id && Objects.equals(_country, country._country) && Objects.equals(_last_update, country._last_update);
// }
//
// @Override
// public int hashCode()
// {
// return Objects.hash(_country_id, _country, _last_update);
// }
// }
//
@SuppressWarnings("unused")
public static class Country
{
private int _country_id;
private String _country;
private Date _last_update;

public int getCountry_id()
{
return _country_id;
}

public void setCountry_id(int country_id)
{
_country_id = country_id;
}

public String getCountry()
{
return _country;
}

public void setCountry(String country)
{
_country = country;
}

public Date getLast_update()
{
return _last_update;
}

public void setLast_update(Date last_update)
{
_last_update = last_update;
}

@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Country country = (Country) o;
return _country_id == country._country_id && Objects.equals(_country, country._country) && Objects.equals(_last_update, country._last_update);
}

@Override
public int hashCode()
{
return Objects.hash(_country_id, _country, _last_update);
}
}

// public static class Account
// {
// private int _account_id;
Expand Down
11 changes: 5 additions & 6 deletions api/src/org/labkey/api/data/dialect/StandardJdbcHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ protected String parseDatabase(String url)
if (-1 == dbEnd)
dbEnd = url.length();

// Database name starts after the last '/' or ':'
int slash = url.lastIndexOf('/', dbEnd);
int colon = url.lastIndexOf(':', dbEnd);
// Last '/' is the database delimiter, except for "jdbc:postgresql:database"
char dbDelimiter = url.contains("/") ? '/' : ':';
int dbDelimiterIndex = url.lastIndexOf(dbDelimiter, dbEnd);

int dbDelimiter = Math.max(slash, colon);

return url.substring(dbDelimiter + 1, dbEnd);
// dbDelimiterIndex == 1 means no database name, so return empty string in that case
return dbDelimiterIndex != 1 ? url.substring(dbDelimiterIndex + 1, dbEnd) : "";
}
}
8 changes: 7 additions & 1 deletion api/src/org/labkey/api/data/dialect/sqlKeywords.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A list of SQL keyword candidates -- all known and potential future keywords across all databases. We use this for testing.
# Sources include the old, hard-coded keyword lists in the dialects, the reserved word lists in the PostgreSQL, MySQL, and
# SQL Server documentation, and the return values of DatabaseMetaData.getSqlKeywords() for every database we support.
# Note: build is required after altering this file.
# Note: a build is required after altering this file.
a
abort
abs
Expand Down Expand Up @@ -241,6 +241,7 @@ degree
delay_key_write
delayed
delete
delete_domain_id
delimiter
delimiters
dense_rank
Expand Down Expand Up @@ -281,6 +282,7 @@ dlurlscheme
dlurlserver
dlvalue
do
do_domain_ids
document
domain
double
Expand Down Expand Up @@ -432,6 +434,7 @@ identity_insert
identitycol
if
ignore
ignore_domain_ids
ignore_server_ids
ilike
immediate
Expand Down Expand Up @@ -749,6 +752,7 @@ p
pack_keys
pad
page
page_checksum
parallel
parameter
parameter_mode
Expand All @@ -759,6 +763,7 @@ parameter_specific_name
parameter_specific_schema
parameters
parse_gcol_expr
parse_vcol_expr
parser
partial
partition
Expand Down Expand Up @@ -851,6 +856,7 @@ redo_buffer_size
redofile
redundant
ref
ref_system_id
reference
references
referencing
Expand Down