Skip to content
Merged
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
27 changes: 24 additions & 3 deletions api/src/org/labkey/api/data/TableSelectorTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.labkey.api.collections.CsvSet;
import org.labkey.api.data.Selector.ForEachBlock;
Expand All @@ -30,6 +31,7 @@
import org.labkey.api.util.ExceptionUtil;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.TestContext;
import org.labkey.api.util.logging.LogHelper;
import org.springframework.jdbc.UncategorizedSQLException;

import java.sql.ResultSet;
Expand All @@ -50,6 +52,8 @@

public class TableSelectorTestCase extends AbstractSelectorTestCase<TableSelector>
{
private static final Logger LOG = LogHelper.getLogger(TableSelectorTestCase.class, "Test progress");

@Test
public void testTableSelector() throws SQLException
{
Expand All @@ -59,13 +63,25 @@ public void testTableSelector() throws SQLException
// testTableSelector(DbSchema.get("oracle.granite", DbSchemaType.Bare).getTable("account"), Account.class);

// Test MySQL or MariaDB database, if present
List<DbScope> mySqlScopes = Stream.of("mySql", "mariadb")
.map(DbScope::getDbScope).filter(Objects::nonNull).toList();
List<DbScope> mySqlScopes = DbScope.getDbScopesToTest().stream()
.filter(scope -> Set.of("MySQL", "MariaDB").contains(scope.getSqlDialect().getProductName()))
.toList();

for (DbScope mySqlScope: mySqlScopes)
{
DbSchema sakila = mySqlScope.getSchema("sakila", DbSchemaType.Bare);
if (sakila.existsInDatabase())
testTableSelector(sakila.getTable("country"), Country.class);
{
testTableSelector(sakila.getTable("Country"), Country.class);
}
else
{
DbSchema sys = mySqlScope.getSchema("sys", DbSchemaType.Bare);
if (sys.existsInDatabase())
{
testTableSelector(sys.getTable("sys_config"), Config.class);
}
}
}
testTableSelector(CoreSchema.getInstance().getTableInfoActiveUsers(), User.class);
testTableSelector(CoreSchema.getInstance().getTableInfoModules(), ModuleContext.class);
Expand Down Expand Up @@ -124,6 +140,8 @@ public int hashCode()
}
}

record Config(String Variable, String Value, Date Set_Time, String Set_By){}

// public static class Account
// {
// private int _account_id;
Expand Down Expand Up @@ -430,6 +448,9 @@ private void testColumnList(TableSelector selector, boolean stable) throws SQLEx

private <K> void testTableSelector(TableInfo table, Class<K> clazz) throws SQLException
{
DbSchema schema = table.getSchema();
LOG.info("Testing {}.{}.{}", schema.getScope().getDisplayName(), schema.getName(), table.getName());

TableSelector selector = new TableSelector(table);

test(selector, clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected String parseDatabase(String url) throws ServletException
if (-1 == dbEnd)
dbEnd = url.length();

// Last '/' is the database delimiter, except for "jdbc:postgresql:database"
// Last '/' is the database delimiter, except for "jdbc:postgresql:database" and old Oracle formats
char dbDelimiter = url.contains("/") ? '/' : ':';
int dbDelimiterIndex = url.lastIndexOf(dbDelimiter, dbEnd);

Expand Down
Loading