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
2 changes: 0 additions & 2 deletions api/src/org/labkey/api/ApiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,11 @@ public void registerServlets(ServletContext servletCtx)
ParameterSubstitutionTest.class,
Portal.TestCase.class,
PropertyManager.TestCase.class,
//RateLimiter.TestCase.class,
RecordFactory.TestCase.class,
ResultSetDataIterator.TestCase.class,
ResultSetSelectorTestCase.class,
RoleSet.TestCase.class,
RowTrackingResultSetWrapper.TestCase.class,
SQLFragment.IntegrationTestCase.class,
SecurityManager.TestCase.class,
SimpleTranslator.TranslateTestCase.class,
SqlSelectorTestCase.class,
Expand Down
45 changes: 4 additions & 41 deletions api/src/org/labkey/api/data/BaseColumnInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ public BaseColumnInfo(ColumnInfo from)
this(from, from.getParentTable());
}


public BaseColumnInfo(ColumnInfo from, TableInfo parent)
{
this(from.getFieldKey(), parent, from.getJdbcType());
Expand Down Expand Up @@ -199,7 +198,6 @@ public BaseColumnInfo(ResultSetMetaData rsmd, int col) throws SQLException
setAlias(SqlDialect.makeDatabaseIdentifier(rsmd.getColumnName(col), new SQLFragment(rsmd.getColumnName(col))));
}


/* Most ColumnInfos represent a column in the database. However, some are created only for meta-data purposes.
* e.g. for DataLoader or "fake" ResultsImpl.
* These columns do not have a SqlDialect. This constructor method is useful in that case. In particular it will
Expand Down Expand Up @@ -235,15 +233,13 @@ public SQLFragment getSql()
}
}


/* used by TableInfo.addColumn */
public boolean lockName()
{
_lockName = true;
return true;
}


/** use setFieldKey() avoid ambiguity when columns have "/" */
public void setName(@NotNull String name)
{
Expand All @@ -255,7 +251,6 @@ public void setName(@NotNull String name)
_fieldKey = newFieldKey;
}


@Override @NotNull
public String getName()
{
Expand All @@ -265,22 +260,19 @@ public String getName()
return _fieldKey.toString();
}


@Override
public void setFieldKey(@NotNull FieldKey key)
{
checkLocked();
_fieldKey = Objects.requireNonNull(key);
}


@Override @NotNull
public FieldKey getFieldKey()
{
return _fieldKey;
}


// use only for debugging, will change after call to getAlias()
@Override
public boolean isAliasSet()
Expand Down Expand Up @@ -363,7 +355,6 @@ public void copyAttributesFrom(ColumnInfo col)
setUserEditable(col.isUserEditable()); //This can impact UniqueId fields if not set
}


/*
* copy "non-core" attributes, e.g. leave key and type information alone
*/
Expand Down Expand Up @@ -538,7 +529,6 @@ public void setExtraAttributesFrom(BaseColumnInfo col)
setScannable(col.isScannable());
}


/**
* copy the url string expression from col with the specified rewrites
* @param col source of the url StringExpression
Expand Down Expand Up @@ -571,7 +561,6 @@ public void copyURLFrom(ColumnInfo col, @Nullable FieldKey parent, @Nullable Map
setOnClick(col.getOnClick());
}


/* only copy if all field keys are in the map */
public void copyURLFromStrict(ColumnInfo col, Map<FieldKey,FieldKey> remap)
{
Expand Down Expand Up @@ -698,15 +687,13 @@ public SqlDialect getSqlDialect()
return _parentTable.getSqlDialect();
}


// Return the actual value we have stashed; use this when copying attributes, so you don't hard-code label
@Override
public String getLabelValue()
{
return _label;
}


@Override
public String getLabel()
{
Expand All @@ -715,7 +702,6 @@ public String getLabel()
return _label;
}


@Override
public boolean isFormatStringSet()
{
Expand Down Expand Up @@ -843,22 +829,19 @@ public TableDescription getFkTableDescription()
return getFk().getLookupTableDescription();
}


@Override
public boolean isUserEditable()
{
return _isUserEditable;
}


@Override
public void setUserEditable(boolean editable)
{
checkLocked();
_isUserEditable = editable;
}


@Override
public void setDisplayColumnFactory(DisplayColumnFactory factory)
{
Expand Down Expand Up @@ -898,25 +881,23 @@ public boolean isVersionColumn()
return JdbcType.BINARY == getJdbcType() && 8 == getScale() && "timestamp".equals(getSqlTypeName());
}


@Override
public SQLFragment getVersionUpdateExpression()
{
if (JdbcType.TIMESTAMP == getJdbcType())
{
return new SQLFragment("CURRENT_TIMESTAMP"); // Instead of {fn now()} -- see #27534
}
else if ("_ts".equalsIgnoreCase(getName()) && !getSqlDialect().isSqlServer() && JdbcType.BIGINT == getJdbcType())
return new SQLFragment().appendNowTimestamp();

if (JdbcType.BIGINT == getJdbcType() && "_ts".equalsIgnoreCase(getName()) && !getSqlDialect().isSqlServer())
{
TableInfo t = getParentTable();
String tsName = t.getSchema().getName() + "." + Objects.requireNonNull(t.getMetaDataIdentifier()).getId() + "_ts";
String sqlString = getSqlDialect().getStringHandler().quoteStringLiteral(tsName);
return new SQLFragment("nextval(" + sqlString + ")");
}

return null;
}


@Override
public String getInputType()
{
Expand All @@ -936,7 +917,6 @@ else if (getJdbcType() == JdbcType.BOOLEAN)
return _inputType;
}


@Override
public int getInputLength()
{
Expand All @@ -951,7 +931,6 @@ public int getInputLength()
return _inputLength;
}


@Override
public int getInputRows()
{
Expand Down Expand Up @@ -1094,7 +1073,6 @@ public void copyToXml(ColumnType xmlCol, boolean full)
}
}


public void loadFromXml(ColumnType xmlCol, boolean merge)
{
checkLocked();
Expand Down Expand Up @@ -1448,7 +1426,6 @@ public static boolean booleanFromString(String str)
}
}


public static boolean booleanFromObj(Object o)
{
if (null == o)
Expand Down Expand Up @@ -1657,7 +1634,6 @@ public DisplayColumn getRenderer()
}
}


public static Collection<BaseColumnInfo> createFromDatabaseMetaData(String schemaName, SchemaTableInfo parentTable, @Nullable String columnNamePattern) throws SQLException
{
//Use linked hash map to preserve ordering...
Expand Down Expand Up @@ -1801,7 +1777,6 @@ else if (key.pkColumnNames.size() == 2 && "container".equalsIgnoreCase(key.fkCol
return colMap.values();
}


private static void inferMetadata(BaseColumnInfo col)
{
String colName = col.getName();
Expand Down Expand Up @@ -1856,7 +1831,6 @@ private static void inferMetadata(BaseColumnInfo col)
}
}


@Override
public String getSqlTypeName()
{
Expand All @@ -1874,8 +1848,6 @@ public String getSqlTypeName()
return _sqlTypeName;
}



@Override
public void setSqlTypeName(String sqlTypeName)
{
Expand Down Expand Up @@ -1908,7 +1880,6 @@ public void setJdbcType(JdbcType type)
_sqlTypeName = null;
}


@Override
public @NotNull JdbcType getJdbcType()
{
Expand All @@ -1932,7 +1903,6 @@ public void setJdbcType(JdbcType type)
return _jdbcType == null ? JdbcType.OTHER : _jdbcType;
}


@Override
public ForeignKey getFk()
{
Expand Down Expand Up @@ -1960,7 +1930,6 @@ public void setFk(@NotNull Builder<ForeignKey> b)
_fk = b.build();
}


@Override
public void setScale(int scale)
{
Expand All @@ -1975,15 +1944,13 @@ public void setPrecision(int precision)
super.setPrecision(precision);
}


/** @return whether the column is part of the primary key for the table */
@Override
public boolean isKeyField()
{
return _isKeyField;
}


@Override
public void setKeyField(boolean keyField)
{
Expand Down Expand Up @@ -2053,14 +2020,12 @@ public void setIsUnselectable(boolean b)
_isUnselectable = b;
}


@Override
public TableInfo getParentTable()
{
return _parentTable;
}


@Override
public void setParentTable(TableInfo parentTable)
{
Expand Down Expand Up @@ -2182,7 +2147,6 @@ public void setValidators(List<? extends IPropertyValidator> validators)
_validators = copyFixedList(validators);
}


@Override
public void checkLocked()
{
Expand Down Expand Up @@ -2219,7 +2183,6 @@ public void setCalculated(boolean calculated)
_calculated = calculated;
}


// If true, you can't use this column when auto-generating LabKey SQL, it is not selected in the underlying query
// only query can set this true
@Override
Expand Down
42 changes: 29 additions & 13 deletions api/src/org/labkey/api/data/SQLFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@

/**
* Holds both the SQL text and JDBC parameter values to use during invocation.
* User: Matthew
* Date: Apr 19, 2006
*/
public class SQLFragment implements Appendable, CharSequence
{
Expand Down Expand Up @@ -609,6 +607,21 @@ else if (Double.isFinite(N.doubleValue()))
return this;
}

public final SQLFragment appendNowTimestamp()
{
return appendValue(new NowTimestamp());
}

// Issue 27534: Stop using {fn now()} in function declarations
// Issue 48864: Query Table's use of web server time can cause discrepancies in created/modified timestamps
public final SQLFragment appendValue(NowTimestamp now)
{
if (null == now)
return appendNull();
getStringBuilder().append("CURRENT_TIMESTAMP");
return this;
}

public final SQLFragment appendValue(java.util.Date d)
{
if (null == d)
Expand Down Expand Up @@ -1293,17 +1306,6 @@ public void testMysql()
}
}


public static class IntegrationTestCase extends Assert
{
@Test
public void test()
{
// try some Dialect stuff and CTE executed against core schema
}
}


@Override
public boolean equals(Object obj)
{
Expand Down Expand Up @@ -1340,4 +1342,18 @@ public static SQLFragment join(Iterable<SQLFragment> fragments, String separator

return new SQLFragment(sql, params);
}

// Marker interface to hint that this value may be replaced by CURRENT_TIMESTAMP
public static class NowTimestamp extends java.sql.Timestamp
{
public NowTimestamp()
{
this(System.currentTimeMillis());
}

public NowTimestamp(long ms)
{
super(ms);
}
}
}
Loading