diff --git a/h2/pom.xml b/h2/pom.xml index bf51f64af3237cda60589d905dfb752ce72fa556..227aa7718b85e47d70936064711e1ae62d86f3ad 100644 --- a/h2/pom.xml +++ b/h2/pom.xml @@ -109,6 +109,12 @@ <version>4.12</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.ow2.asm</groupId> + <artifactId>asm</artifactId> + <version>6.1</version> + <scope>test</scope> + </dependency> <!-- END TEST DEPENDENCIES !--> </dependencies> diff --git a/h2/src/main/org/h2/command/Parser.java b/h2/src/main/org/h2/command/Parser.java index cbfdf8dab8c982830180e0c8c0ae11be5160b128..0c0b5761e4c8ad99d44c6b560b0bdd0f44027290 100644 --- a/h2/src/main/org/h2/command/Parser.java +++ b/h2/src/main/org/h2/command/Parser.java @@ -6937,8 +6937,15 @@ public class Parser { return command; } + /** + * Checks the table is the DUAL special table. + * + * @param tableName table name. + * @return {@code true} if the table is DUAL special table. Otherwise returns {@code false}. + * @see <a href="https://en.wikipedia.org/wiki/DUAL_table">Wikipedia: DUAL table</a> + */ boolean isDualTable(String tableName) { - return ((schemaName == null || equalsToken(schemaName, "SYS")) && equalsToken("DUAL", tableName)) + return ((schemaName == null || equalsToken(schemaName, "SYS")) && equalsToken("F", tableName)) || (database.getMode().sysDummy1 && (schemaName == null || equalsToken(schemaName, "SYSIBM")) && equalsToken("SYSDUMMY1", tableName)); } diff --git a/h2/src/main/org/h2/command/dml/Query.java b/h2/src/main/org/h2/command/dml/Query.java index 1f1b7488e0fbddc6be70c81fbf7df5edfe7d449f..04ec0c85a1cb2191c88ba9ae81130c6b199e19a6 100644 --- a/h2/src/main/org/h2/command/dml/Query.java +++ b/h2/src/main/org/h2/command/dml/Query.java @@ -52,8 +52,14 @@ public abstract class Query extends Prepared { */ Expression[] expressionArray; + /** + * Describes one element of the ORDER BY clause of a query. + */ ArrayList<SelectOrderBy> orderList; + /** + * A sort order represents an ORDER BY clause in a query. + */ SortOrder sort; /** @@ -397,7 +403,7 @@ public abstract class Query extends Prepared { } fireBeforeSelectTriggers(); if (noCache || !session.getDatabase().getOptimizeReuseResults() || - (session.isLazyQueryExecution() && !neverLazy)) { + (session.isLazyQueryExecution() /* && !neverLazy*/)) { return queryWithoutCacheLazyCheck(limit, target); } Value[] params = getParameterValues(); @@ -459,6 +465,18 @@ public abstract class Query extends Prepared { } } + /** + * Initialize the order or distinct expression. + * + * @param session the session + * @param expressions the select list expressions + * @param expressionSQL the select list SQL snippets + * @param e the expression. + * @param visible the number of visible columns in the select list + * @param mustBeInResult all order by expressions must be in the select list + * @param filters the table filters1 + * @return index on the expression in the {@link #expressions} list. + */ static int initExpression(Session session, ArrayList<Expression> expressions, ArrayList<String> expressionSQL, Expression e, int visible, boolean mustBeInResult, ArrayList<TableFilter> filters) { @@ -690,6 +708,11 @@ public abstract class Query extends Prepared { return visitor.getMaxDataModificationId(); } + /** + * Appends query limits info to the plan. + * + * @param buff sl plan string builder. + */ void appendLimitToSQL(StringBuilder buff) { if (offsetExpr != null) { String count = StringUtils.unEnclose(offsetExpr.getSQL()); diff --git a/h2/src/main/org/h2/command/dml/Select.java b/h2/src/main/org/h2/command/dml/Select.java index 82654cdfa1f3e4b1276315c8e9eacbbf93ea8af8..ef6c4413cc33bee1aa9e24e5a0b09d64de7d3106 100644 --- a/h2/src/main/org/h2/command/dml/Select.java +++ b/h2/src/main/org/h2/command/dml/Select.java @@ -72,7 +72,7 @@ public class Select extends Query { /** * The main (top) table filter. */ - TableFilter topTableFilter; + private TableFilter topTableFilter; private final ArrayList<TableFilter> filters = Utils.newSmallArrayList(); private final ArrayList<TableFilter> topFilters = Utils.newSmallArrayList(); @@ -83,7 +83,7 @@ public class Select extends Query { /** * The visible columns (the ones required in the result). */ - int visibleColumnCount; + private int visibleColumnCount; /** * {@code DISTINCT ON(...)} expressions. @@ -98,17 +98,17 @@ public class Select extends Query { /** * The indexes of the group-by columns. */ - int[] groupIndex; + private int[] groupIndex; /** * Whether a column in the expression list is part of a group-by. */ - boolean[] groupByExpression; + private boolean[] groupByExpression; - SelectGroups groupData; + private SelectGroups groupData; private int havingIndex; - boolean isGroupQuery; + private boolean isGroupQuery; private boolean isGroupSortedQuery; private boolean isWindowQuery; private boolean isForUpdate, isForUpdateMvcc; diff --git a/h2/src/main/org/h2/command/dml/SelectGroups.java b/h2/src/main/org/h2/command/dml/SelectGroups.java index b343811243f4627247a46bead652db44642a6c26..8522f8979e1b6274e62ada62fe1a94d326ad6d1a 100644 --- a/h2/src/main/org/h2/command/dml/SelectGroups.java +++ b/h2/src/main/org/h2/command/dml/SelectGroups.java @@ -194,8 +194,14 @@ public abstract class SelectGroups { } } + /** + * H2 session. + */ final Session session; + /** + * The query's column list, including invisible expressions such as order by expressions. + */ final ArrayList<Expression> expressions; /** @@ -235,6 +241,7 @@ public abstract class SelectGroups { * is this query is a group query * @param groupIndex * the indexes of group expressions, or null + * @return new instance of the grouped data. */ public static SelectGroups getInstance(Session session, ArrayList<Expression> expressions, boolean isGroupQuery, int[] groupIndex) { @@ -247,7 +254,10 @@ public abstract class SelectGroups { } /** - * Is there currently a group-by active + * Is there currently a group-by active. + * + * @return {@code true} if there is currently a group-by active, + * otherwise returns {@code false}. */ public boolean isCurrentGroup() { return currentGroupByExprData != null; @@ -273,7 +283,7 @@ public abstract class SelectGroups { * * @param expr * expression - * @param object + * @param obj * expression data to set */ public final void setCurrentGroupExprData(Expression expr, Object obj) { @@ -292,6 +302,11 @@ public abstract class SelectGroups { currentGroupByExprData[index] = obj; } + /** + * Creates new object arrays to holds group-by data. + * + * @return new object array to holds group-by data. + */ final Object[] createRow() { return new Object[Math.max(exprToIndexInGroupByData.size(), expressions.size())]; } @@ -321,7 +336,7 @@ public abstract class SelectGroups { * expression * @param partitionKey * a key of partition - * @param object + * @param obj * window expression data to set */ public final void setWindowExprData(DataAnalysisOperation expr, Value partitionKey, PartitionData obj) { @@ -338,6 +353,10 @@ public abstract class SelectGroups { } } + /** + * Update group-by data specified by implementation. + * The + */ abstract void updateCurrentGroupExprData(); /** @@ -412,4 +431,10 @@ public abstract class SelectGroups { currentGroupRowId++; } + /** + * @return Expressions. + */ + public ArrayList<Expression> expressions() { + return expressions; + } } diff --git a/h2/src/main/org/h2/engine/Database.java b/h2/src/main/org/h2/engine/Database.java index fdab8a87207d62176f0762f9bf150731d87fb79a..bdc36752ba12676f6ef117237d88d60574d924a2 100644 --- a/h2/src/main/org/h2/engine/Database.java +++ b/h2/src/main/org/h2/engine/Database.java @@ -1123,6 +1123,11 @@ public class Database implements DataHandler { } } + /** + * Release IDs. + * + * @param idsToRelease IDs to release. + */ void releaseDatabaseObjectIds(BitSet idsToRelease) { synchronized (objectIds) { objectIds.andNot(idsToRelease); diff --git a/h2/src/main/org/h2/engine/OnExitDatabaseCloser.java b/h2/src/main/org/h2/engine/OnExitDatabaseCloser.java index 67a560c8311d52fef2351973fca4b293e1811f62..22b67f220f64119307ddbaea7b85e1c6e89c39db 100644 --- a/h2/src/main/org/h2/engine/OnExitDatabaseCloser.java +++ b/h2/src/main/org/h2/engine/OnExitDatabaseCloser.java @@ -22,6 +22,11 @@ class OnExitDatabaseCloser extends Thread { private static boolean terminated; + /** + * Register database instance to close one on the JVM process shutdown. + * + * @param db Database instance. + */ static synchronized void register(Database db) { if (terminated) { // Shutdown in progress @@ -46,6 +51,11 @@ class OnExitDatabaseCloser extends Thread { } } + /** + * Unregister database instance. + * + * @param db Database instance. + */ static synchronized void unregister(Database db) { if (terminated) { // Shutdown in progress, do nothing diff --git a/h2/src/main/org/h2/expression/condition/ConditionInParameter.java b/h2/src/main/org/h2/expression/condition/ConditionInParameter.java index ccf1a70fe191d42f217f781b9da67daccfaa4993..5fcaa8506517d75993a5a7410c99854616ac925a 100644 --- a/h2/src/main/org/h2/expression/condition/ConditionInParameter.java +++ b/h2/src/main/org/h2/expression/condition/ConditionInParameter.java @@ -65,6 +65,14 @@ public class ConditionInParameter extends Condition { private final Parameter parameter; + /** + * Gets evaluated condition value. + * + * @param database database instance. + * @param l left value. + * @param value parameter value. + * @return Evaluated condition value. + */ static Value getValue(Database database, Value l, Value value) { boolean hasNull = false; if (value.containsNull()) { diff --git a/h2/src/main/org/h2/jdbc/JdbcLob.java b/h2/src/main/org/h2/jdbc/JdbcLob.java index 5d06988ed2ad1cf139cce78940f9872b1a282c59..333c3e82d5f6ed11c43ee38ae0a2a0ff63ead24a 100644 --- a/h2/src/main/org/h2/jdbc/JdbcLob.java +++ b/h2/src/main/org/h2/jdbc/JdbcLob.java @@ -69,8 +69,19 @@ public abstract class JdbcLob extends TraceObject { CLOSED; } + /** + * JDBC connection. + */ final JdbcConnection conn; + + /** + * Value. + */ Value value; + + /** + * State. + */ State state; JdbcLob(JdbcConnection conn, Value value, State state, int type, int id) { @@ -80,6 +91,10 @@ public abstract class JdbcLob extends TraceObject { this.state = state; } + /** + * Check that connection and LOB is not closed, otherwise throws exception with + * error code {@link org.h2.api.ErrorCode#OBJECT_CLOSED}. + */ void checkClosed() { conn.checkClosed(); if (state == State.CLOSED) { @@ -87,6 +102,10 @@ public abstract class JdbcLob extends TraceObject { } } + /** + * Check the state of the LOB and throws the exception when check failed + * (set is supported only for a new LOB). + */ void checkEditable() { checkClosed(); if (state != State.NEW) { @@ -94,6 +113,10 @@ public abstract class JdbcLob extends TraceObject { } } + /** + * Check the state of the LOB and throws the exception when check failed + * (the LOB must be set completely before read). + */ void checkReadable() throws SQLException, IOException { checkClosed(); if (state == State.SET_CALLED) { @@ -101,6 +124,10 @@ public abstract class JdbcLob extends TraceObject { } } + /** + * Change the state LOB state (LOB value is set completely and available to read). + * @param blob LOB value. + */ void completeWrite(Value blob) { checkClosed(); state = State.WITH_VALUE; @@ -146,10 +173,22 @@ public abstract class JdbcLob extends TraceObject { } } + /** + * Returns the writer. + * + * @return Writer. + * @throws IOException If an I/O error occurs. + */ Writer setCharacterStreamImpl() throws IOException { return IOUtils.getBufferedWriter(setClobOutputStreamImpl()); } + /** + * Returns the writer stream. + * + * @return Output stream.. + * @throws IOException If an I/O error occurs. + */ LobPipedOutputStream setClobOutputStreamImpl() throws IOException { // PipedReader / PipedWriter are a lot slower // than PipedInputStream / PipedOutputStream diff --git a/h2/src/main/org/h2/jdbc/JdbcResultSet.java b/h2/src/main/org/h2/jdbc/JdbcResultSet.java index fe44460af2d1bf84cec8cfa34dcff079bc2ea6ee..f1862aec2303da3bde8453967d9270e71dfccff2 100644 --- a/h2/src/main/org/h2/jdbc/JdbcResultSet.java +++ b/h2/src/main/org/h2/jdbc/JdbcResultSet.java @@ -3606,7 +3606,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS * Updates a column in the current or insert row. * * @param columnIndex (1,2,...) - * @param x the value + * @param xmlObject the value * @throws SQLException if the result set is closed or not updatable */ @Override @@ -3633,7 +3633,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS * Updates a column in the current or insert row. * * @param columnLabel the column label - * @param x the value + * @param xmlObject the value * @throws SQLException if the result set is closed or not updatable */ @Override diff --git a/h2/src/main/org/h2/message/DbException.java b/h2/src/main/org/h2/message/DbException.java index 71f15f2975f6953eec663e7cf7242137b43e6e5f..f26649ce531c01942bb25dc61903572a075a68ae 100644 --- a/h2/src/main/org/h2/message/DbException.java +++ b/h2/src/main/org/h2/message/DbException.java @@ -55,6 +55,10 @@ public class DbException extends RuntimeException { private static final Properties MESSAGES = new Properties(); + /** + * Thrown when OOME exception is happened on handle error + * inside {@link #convert(java.lang.Throwable)}. + */ public static final SQLException SQL_OOME = new SQLException("OutOfMemoryError", "HY000", OUT_OF_MEMORY, new OutOfMemoryError()); private static final DbException OOME = new DbException(SQL_OOME); @@ -432,6 +436,7 @@ public class DbException extends RuntimeException { * @param errorCode the error code * @param cause the exception that was the reason for this exception * @param stackTrace the stack trace + * @return the SQLException object */ public static SQLException getJdbcSQLException(String message, String sql, String state, int errorCode, Throwable cause, String stackTrace) { diff --git a/h2/src/main/org/h2/mvstore/DataUtils.java b/h2/src/main/org/h2/mvstore/DataUtils.java index 78477fdc8d544695158d83c51d0fefd834068cf2..a7a3a79844e7fbe0235a2511eee1595df7a20873 100644 --- a/h2/src/main/org/h2/mvstore/DataUtils.java +++ b/h2/src/main/org/h2/mvstore/DataUtils.java @@ -252,6 +252,7 @@ public final class DataUtils { * * @param out the output stream * @param x the value + * @throws IOException if some data could not be written */ public static void writeVarInt(OutputStream out, int x) throws IOException { while ((x & ~0x7f) != 0) { @@ -341,6 +342,7 @@ public final class DataUtils { * * @param out the output stream * @param x the value + * @throws IOException if some data could not be written */ public static void writeVarLong(OutputStream out, long x) throws IOException { diff --git a/h2/src/main/org/h2/mvstore/MVMap.java b/h2/src/main/org/h2/mvstore/MVMap.java index 577c210e042a5e33c0951131d14bc83775682414..33a72f72573bca6c4f549d243ee38eaac31df2e2 100644 --- a/h2/src/main/org/h2/mvstore/MVMap.java +++ b/h2/src/main/org/h2/mvstore/MVMap.java @@ -154,6 +154,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> * * @param key the key (may not be null) * @param value the value (may not be null) + * @param decisionMaker callback object for update logic * @return the old value if the key existed, or null otherwise */ public final V put(K key, V value, DecisionMaker<? super V> decisionMaker) { @@ -873,6 +874,9 @@ public class MVMap<K, V> extends AbstractMap<K, V> * @param oldRoot the old root reference, will use the current root reference, * if null is specified * @param newRoot the new root page + * @param attemptUpdateCounter how many attempt (including current) + * were made to update root + * @return new RootReference or null if update failed */ protected final boolean updateRoot(RootReference oldRoot, Page newRoot, int attemptUpdateCounter) { return setNewRoot(oldRoot, newRoot, attemptUpdateCounter, true) != null; diff --git a/h2/src/main/org/h2/mvstore/MVStore.java b/h2/src/main/org/h2/mvstore/MVStore.java index ce173216272f97903b5ba4c5d6acd718e5fc301d..3f75682391c4b60a2d730fdaaf56c8028ddd56c7 100644 --- a/h2/src/main/org/h2/mvstore/MVStore.java +++ b/h2/src/main/org/h2/mvstore/MVStore.java @@ -474,6 +474,7 @@ public class MVStore implements AutoCloseable { * does not yet exist. If a map with this name is already open, this map is * returned. * + * @param <M> the map type * @param <K> the key type * @param <V> the value type * @param name the name of the map diff --git a/h2/src/main/org/h2/mvstore/StreamStore.java b/h2/src/main/org/h2/mvstore/StreamStore.java index cfa1aaacafe6b240127d274e1d255219dca11895..d30d265bef26e4ae416221def6ea4f746d2bcb57 100644 --- a/h2/src/main/org/h2/mvstore/StreamStore.java +++ b/h2/src/main/org/h2/mvstore/StreamStore.java @@ -95,6 +95,7 @@ public class StreamStore { * * @param in the stream * @return the id (potentially an empty array) + * @throws IOException If an I/O error occurs */ @SuppressWarnings("resource") public byte[] put(InputStream in) throws IOException { diff --git a/h2/src/main/org/h2/mvstore/tx/Transaction.java b/h2/src/main/org/h2/mvstore/tx/Transaction.java index 23f63a8d63c0ad8020c234b8ed0cd5eb5e67de76..49972ef61439eacf3942280c48222376f720817c 100644 --- a/h2/src/main/org/h2/mvstore/tx/Transaction.java +++ b/h2/src/main/org/h2/mvstore/tx/Transaction.java @@ -546,6 +546,8 @@ public class Transaction { /** * Remove the map. * + * @param <K> the key type + * @param <V> the value type * @param map the map */ public <K, V> void removeMap(TransactionMap<K, V> map) { diff --git a/h2/src/main/org/h2/result/SimpleResult.java b/h2/src/main/org/h2/result/SimpleResult.java index 20879a9c610c0229b774c85516ad858adcaf9b60..93a389af5a8edec3e3efeeceb7d2b485f08fd31b 100644 --- a/h2/src/main/org/h2/result/SimpleResult.java +++ b/h2/src/main/org/h2/result/SimpleResult.java @@ -19,17 +19,17 @@ public class SimpleResult implements ResultInterface { static final class Column { - final String alias; + private final String alias; - final String columnName; + private final String columnName; - final int columnType; + private final int columnType; - final long columnPrecision; + private final long columnPrecision; - final int columnScale; + private final int columnScale; - final int displaySize; + private final int displaySize; Column(String alias, String columnName, int columnType, long columnPrecision, int columnScale, int displaySize) { @@ -94,16 +94,36 @@ public class SimpleResult implements ResultInterface { this.rowId = -1; } + /** + * Add column to the result. + * + * @param alias Column's alias. + * @param columnName Column's name. + * @param columnType Column's type. + * @param columnPrecision Column's precision. + * @param columnScale Column's scale. + * @param displaySize Column's display data size. + */ public void addColumn(String alias, String columnName, int columnType, long columnPrecision, int columnScale, int displaySize) { addColumn(new Column(alias, columnName, columnType, columnPrecision, columnScale, displaySize)); } + /** + * Add column to the result. + * + * @param column Column info. + */ void addColumn(Column column) { assert rows.isEmpty(); columns.add(column); } + /** + * Add row to result. + * + * @param values Row's values. + */ public void addRow(Value... values) { assert values.length == columns.size(); rows.add(values); diff --git a/h2/src/main/org/h2/security/auth/AuthenticationInfo.java b/h2/src/main/org/h2/security/auth/AuthenticationInfo.java index eccfdfcfb904c61933f53818dcf434af835e809a..b7062e8781caf967e0812de664cd850614bdc1b9 100644 --- a/h2/src/main/org/h2/security/auth/AuthenticationInfo.java +++ b/h2/src/main/org/h2/security/auth/AuthenticationInfo.java @@ -20,7 +20,7 @@ public class AuthenticationInfo { private String realm; /* - * Can be used by authenticator to hold informations + * Can be used by authenticator to hold information. */ Object nestedIdentity; @@ -58,14 +58,16 @@ public class AuthenticationInfo { } /** - * get nested identity + * Gets nested identity. + * + * @return nested identity object. */ public Object getNestedIdentity() { return nestedIdentity; } /** - * Method used by authenticators to hold informations about authenticated + * Method used by authenticators to hold information about authenticated * user * * @param nestedIdentity @@ -75,6 +77,9 @@ public class AuthenticationInfo { this.nestedIdentity = nestedIdentity; } + /** + * Clean authentication data. + */ public void clean() { this.password = null; this.nestedIdentity = null; diff --git a/h2/src/main/org/h2/security/auth/Authenticator.java b/h2/src/main/org/h2/security/auth/Authenticator.java index 788301e9337e59ac654f935587dcafe8bc6c6d0a..ae8dc7be0b3ddbeac96203f8abdae4ef83e91c76 100644 --- a/h2/src/main/org/h2/security/auth/Authenticator.java +++ b/h2/src/main/org/h2/security/auth/Authenticator.java @@ -16,6 +16,8 @@ public interface Authenticator { /** * Perform user authentication. * + * @param authenticationInfo authentication info. + * @param database target database instance. * @return valid database user or null if user doesn't exists in the * database */ diff --git a/h2/src/main/org/h2/security/auth/AuthenticatorFactory.java b/h2/src/main/org/h2/security/auth/AuthenticatorFactory.java index 5eafccff511a0b060cc8ccbb4258d2cf558b7156..0ae47ba20a8d4bc17dc43b903a5b52a89956755f 100644 --- a/h2/src/main/org/h2/security/auth/AuthenticatorFactory.java +++ b/h2/src/main/org/h2/security/auth/AuthenticatorFactory.java @@ -10,6 +10,10 @@ package org.h2.security.auth; */ public class AuthenticatorFactory { + /** + * Factory method. + * @return authenticator instance. + */ public static Authenticator createAuthenticator() { return DefaultAuthenticator.getInstance(); } diff --git a/h2/src/main/org/h2/security/auth/ConfigProperties.java b/h2/src/main/org/h2/security/auth/ConfigProperties.java index 776b84816b42148c7abc971b20c3bbda124d33b7..4c800e4e2799ef4e9fa8ee9c8b6a95b539d7483d 100644 --- a/h2/src/main/org/h2/security/auth/ConfigProperties.java +++ b/h2/src/main/org/h2/security/auth/ConfigProperties.java @@ -38,6 +38,13 @@ public class ConfigProperties { } } + /** + * Returns the string value of specified property. + * + * @param name property name. + * @param defaultValue default value. + * @return the string property value or {@code defaultValue} if the property is missing. + */ public String getStringValue(String name, String defaultValue) { String result = properties.get(name); if (result == null) { @@ -46,6 +53,13 @@ public class ConfigProperties { return result; } + /** + * Returns the string value of specified property. + * + * @param name property name. + * @return the string property value. + * @throws AuthConfigException if the property is missing. + */ public String getStringValue(String name) { String result = properties.get(name); if (result == null) { @@ -54,6 +68,13 @@ public class ConfigProperties { return result; } + /** + * Returns the integer value of specified property. + * + * @param name property name. + * @param defaultValue default value. + * @return the integer property value or {@code defaultValue} if the property is missing. + */ public int getIntValue(String name, int defaultValue) { String result = properties.get(name); if (result == null) { @@ -62,6 +83,13 @@ public class ConfigProperties { return Integer.parseInt(result); } + /** + * Returns the integer value of specified property. + * + * @param name property name. + * @return the integer property value. + * @throws AuthConfigException if the property is missing. + */ public int getIntValue(String name) { String result = properties.get(name); if (result == null) { @@ -70,6 +98,13 @@ public class ConfigProperties { return Integer.parseInt(result); } + /** + * Returns the boolean value of specified property. + * + * @param name property name. + * @param defaultValue default value. + * @return the boolean property value or {@code defaultValue} if the property is missing. + */ public boolean getBooleanValue(String name, boolean defaultValue) { String result = properties.get(name); if (result == null) { diff --git a/h2/src/main/org/h2/security/auth/DefaultAuthenticator.java b/h2/src/main/org/h2/security/auth/DefaultAuthenticator.java index 5fa8b4033016aba797114fe5334561bb3c25a993..f5c4c37d1e87a218f7bb1496d3378bfb7ff3db3c 100644 --- a/h2/src/main/org/h2/security/auth/DefaultAuthenticator.java +++ b/h2/src/main/org/h2/security/auth/DefaultAuthenticator.java @@ -54,19 +54,12 @@ public class DefaultAuthenticator implements Authenticator { public static final String DEFAULT_REALMNAME = "H2"; private Map<String, CredentialsValidator> realms = new HashMap<>(); - private List<UserToRolesMapper> userToRolesMappers = new ArrayList<>(); - private boolean allowUserRegistration; - private boolean persistUsers; - private boolean createMissingRoles; - private boolean skipDefaultInitialization; - private boolean initialized; - private static DefaultAuthenticator instance; protected static final DefaultAuthenticator getInstance() { @@ -95,34 +88,62 @@ public class DefaultAuthenticator implements Authenticator { /** * If set save users externals defined during the authentication. + * + * @return {@code true} if user will be persisted, + * otherwise returns {@code false} */ public boolean isPersistUsers() { return persistUsers; } + /** + * If set to {@code true} saves users externals defined during the authentication. + * + * @param persistUsers {@code true} if user will be persisted, + * otherwise {@code false}. + */ public void setPersistUsers(boolean persistUsers) { this.persistUsers = persistUsers; } /** * If set create external users in the database if not present. + * + * @return {@code true} if creation external user is allowed, + * otherwise returns {@code false} */ public boolean isAllowUserRegistration() { return allowUserRegistration; } + /** + * If set to{@code true} creates external users in the database if not present. + * + * @param allowUserRegistration {@code true} if creation external user is allowed, + * otherwise returns {@code false} + */ public void setAllowUserRegistration(boolean allowUserRegistration) { this.allowUserRegistration = allowUserRegistration; } /** * When set create roles not found in the database. If not set roles not - * found in the database are silently skipped + * found in the database are silently skipped. + * + * @return {@code true} if not found roles will be created, + * {@code false} roles are silently skipped. */ public boolean isCreateMissingRoles() { return createMissingRoles; } + /** + * Sets the flag that define behavior in case external roles not found in the database. + * + * + * @param createMissingRoles when is {@code true} not found roles are created, + * when is {@code false} roles are silently skipped. + */ public void setCreateMissingRoles(boolean createMissingRoles) { this.createMissingRoles = createMissingRoles; } @@ -209,7 +230,7 @@ public class DefaultAuthenticator implements Authenticator { } } - void defaultConfiguration() { + private void defaultConfiguration() { createMissingRoles = false; allowUserRegistration = true; realms = new HashMap<>(); @@ -232,7 +253,7 @@ public class DefaultAuthenticator implements Authenticator { configureFrom(config); } - void configureFrom(H2AuthConfig config) throws AuthenticationException { + private void configureFrom(H2AuthConfig config) throws AuthenticationException { allowUserRegistration = config.isAllowUserRegistration(); createMissingRoles = config.isCreateMissingRoles(); Map<String, CredentialsValidator> newRealms = new HashMap<>(); @@ -270,7 +291,7 @@ public class DefaultAuthenticator implements Authenticator { this.userToRolesMappers = newUserToRolesMapper; } - boolean updateRoles(AuthenticationInfo authenticationInfo, User user, Database database) + private boolean updateRoles(AuthenticationInfo authenticationInfo, User user, Database database) throws AuthenticationException { boolean updatedDb = false; Set<String> roles = new HashSet<>(); diff --git a/h2/src/main/org/h2/security/auth/H2AuthConfig.java b/h2/src/main/org/h2/security/auth/H2AuthConfig.java index 6f91659e3160ce39ac2f240cddb72988214da762..0650e8eafcb281c8b245885a27d572abaf5f9dac 100644 --- a/h2/src/main/org/h2/security/auth/H2AuthConfig.java +++ b/h2/src/main/org/h2/security/auth/H2AuthConfig.java @@ -9,32 +9,54 @@ import java.util.ArrayList; import java.util.List; /** - * Describe configuration of H2 DefaultAuthenticator + * Describe configuration of H2 DefaultAuthenticator. */ public class H2AuthConfig { private boolean allowUserRegistration=true; + private boolean createMissingRoles=true; + private List<RealmConfig> realms; + private List<UserToRolesMapperConfig> userToRolesMappers; + /** + * Allow user registration flag. If set to {@code true} + * creates external users in the database if not present. + * + * @return {@code true} in case user registration is allowed, + * otherwise returns {@code false}. + */ public boolean isAllowUserRegistration() { return allowUserRegistration; } + /** + * @param allowUserRegistration Allow user registration flag. + */ public void setAllowUserRegistration(boolean allowUserRegistration) { this.allowUserRegistration = allowUserRegistration; } - boolean createMissingRoles=true; - + /** + * When set create roles not found in the database. If not set roles not + * found in the database are silently skipped. + * @return {@code true} if the flag is set, otherwise returns {@code false}. + */ public boolean isCreateMissingRoles() { return createMissingRoles; } + /** + * When set create roles not found in the database. If not set roles not + * found in the database are silently skipped + * @param createMissingRoles missing roles flag. + */ public void setCreateMissingRoles(boolean createMissingRoles) { this.createMissingRoles = createMissingRoles; } - List<RealmConfig> realms; - + /** + * @return configuration of authentication realms. + */ public List<RealmConfig> getRealms() { if (realms == null) { realms = new ArrayList<>(); @@ -42,12 +64,16 @@ public class H2AuthConfig { return realms; } + /** + * @param realms configuration of authentication realms. + */ public void setRealms(List<RealmConfig> realms) { this.realms = realms; } - List<UserToRolesMapperConfig> userToRolesMappers; - + /** + * @return configuration of the mappers external users to database roles. + */ public List<UserToRolesMapperConfig> getUserToRolesMappers() { if (userToRolesMappers == null) { userToRolesMappers = new ArrayList<>(); @@ -55,6 +81,9 @@ public class H2AuthConfig { return userToRolesMappers; } + /** + * @param userToRolesMappers configuration of the mappers external users to database roles. + */ public void setUserToRolesMappers(List<UserToRolesMapperConfig> userToRolesMappers) { this.userToRolesMappers = userToRolesMappers; } diff --git a/h2/src/main/org/h2/security/auth/H2AuthConfigXml.java b/h2/src/main/org/h2/security/auth/H2AuthConfigXml.java index a4dbcbfeccb6a192d85652a1c2cc6405d0774c11..8ecbd7dc1206b70892c59c09fbac3eca5ba11ff9 100644 --- a/h2/src/main/org/h2/security/auth/H2AuthConfigXml.java +++ b/h2/src/main/org/h2/security/auth/H2AuthConfigXml.java @@ -20,9 +20,8 @@ import org.xml.sax.helpers.DefaultHandler; */ public class H2AuthConfigXml extends DefaultHandler{ - H2AuthConfig result; - - HasConfigProperties lastConfigProperties; + private H2AuthConfig result; + private HasConfigProperties lastConfigProperties; @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { @@ -68,7 +67,7 @@ public class H2AuthConfigXml extends DefaultHandler{ } } - static String getMandatoryAttributeValue(String attributeName, Attributes attributes) throws SAXException { + private static String getMandatoryAttributeValue(String attributeName, Attributes attributes) throws SAXException { String attributeValue=attributes.getValue(attributeName); if (attributeValue==null || attributeValue.trim().equals("")) { throw new SAXException("missing attribute "+attributeName); @@ -77,7 +76,7 @@ public class H2AuthConfigXml extends DefaultHandler{ } - static String getAttributeValueOr(String attributeName, Attributes attributes, String defaultValue) { + private static String getAttributeValueOr(String attributeName, Attributes attributes, String defaultValue) { String attributeValue=attributes.getValue(attributeName); if (attributeValue==null || attributeValue.trim().equals("")) { return defaultValue; @@ -85,12 +84,23 @@ public class H2AuthConfigXml extends DefaultHandler{ return attributeValue; } + /** + * Returns parsed authenticator configuration. + * + * @return Authenticator configuration. + */ public H2AuthConfig getResult() { return result; } /** - * Parse the xml + * Parse the xml. + * + * @param url the source of the xml configuration. + * @return Authenticator configuration. + * @throws ParserConfigurationException if a parser cannot be created. + * @throws SAXException for SAX errors. + * @throws IOException If an I/O error occurs */ public static H2AuthConfig parseFrom(URL url) throws SAXException, IOException, ParserConfigurationException { @@ -99,6 +109,15 @@ public class H2AuthConfigXml extends DefaultHandler{ } } + /** + * Parse the xml. + * + * @param inputStream the source of the xml configuration. + * @return Authenticator configuration. + * @throws ParserConfigurationException if a parser cannot be created. + * @throws SAXException for SAX errors. + * @throws IOException If an I/O error occurs + */ public static H2AuthConfig parseFrom(InputStream inputStream) throws SAXException, IOException, ParserConfigurationException { SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); diff --git a/h2/src/main/org/h2/security/auth/RealmConfig.java b/h2/src/main/org/h2/security/auth/RealmConfig.java index 4baecd2e4217e4d0e84fcfcbf75bdb89b80cdef6..a73d86741c27910ae70b3621c6c9b90bc485d44f 100644 --- a/h2/src/main/org/h2/security/auth/RealmConfig.java +++ b/h2/src/main/org/h2/security/auth/RealmConfig.java @@ -14,6 +14,8 @@ import java.util.List; public class RealmConfig implements HasConfigProperties { private String name; + private String validatorClass; + private List<PropertyConfig> properties; public String getName() { return name; @@ -23,7 +25,6 @@ public class RealmConfig implements HasConfigProperties { this.name = name; } - String validatorClass; public String getValidatorClass() { return validatorClass; @@ -33,8 +34,6 @@ public class RealmConfig implements HasConfigProperties { this.validatorClass = validatorClass; } - List<PropertyConfig> properties; - @Override public List<PropertyConfig> getProperties() { if (properties == null) { diff --git a/h2/src/main/org/h2/security/auth/UserToRolesMapperConfig.java b/h2/src/main/org/h2/security/auth/UserToRolesMapperConfig.java index 77d9869055b951cb43ae35787ab511cca606f0dd..07dc0fcf8cdcb77e9f528b6c50b15afba48c5f1f 100644 --- a/h2/src/main/org/h2/security/auth/UserToRolesMapperConfig.java +++ b/h2/src/main/org/h2/security/auth/UserToRolesMapperConfig.java @@ -10,21 +10,31 @@ import java.util.List; /** * Configuration for class that maps users to their roles. + * + * @see org.h2.api.UserToRolesMapper */ public class UserToRolesMapperConfig implements HasConfigProperties { private String className; - private List<PropertyConfig> properties; + /** + * @return Mapper class name. + */ public String getClassName() { return className; } + /** + * @param className mapper class name. + */ public void setClassName(String className) { this.className = className; } + /** + * @return Mapper properties. + */ @Override public List<PropertyConfig> getProperties() { if (properties == null) { diff --git a/h2/src/main/org/h2/store/fs/FilePath.java b/h2/src/main/org/h2/store/fs/FilePath.java index fb3576a508b5e4d1658e38990a337356f9932441..a3f15bb24b18603c0fc54ac1fd70a387848d534a 100644 --- a/h2/src/main/org/h2/store/fs/FilePath.java +++ b/h2/src/main/org/h2/store/fs/FilePath.java @@ -218,6 +218,7 @@ public abstract class FilePath { * @param append if true, the file will grow, if false, the file will be * truncated first * @return the output stream + * @throws IOException If an I/O error occurs */ public abstract OutputStream newOutputStream(boolean append) throws IOException; @@ -226,6 +227,7 @@ public abstract class FilePath { * * @param mode the access mode. Supported are r, rw, rws, rwd * @return the file object + * @throws IOException If an I/O error occurs */ public abstract FileChannel open(String mode) throws IOException; @@ -233,6 +235,7 @@ public abstract class FilePath { * Create an input stream to read from the file. * * @return the input stream + * @throws IOException If an I/O error occurs */ public abstract InputStream newInputStream() throws IOException; diff --git a/h2/src/main/org/h2/table/Table.java b/h2/src/main/org/h2/table/Table.java index 5d5c3c5c7d15728d7ab436e4f378c5696002d7cf..a604f61863155a0f9e58fffc1a22719003e35ae5 100644 --- a/h2/src/main/org/h2/table/Table.java +++ b/h2/src/main/org/h2/table/Table.java @@ -656,6 +656,13 @@ public abstract class Table extends SchemaObjectBase { } } + /** + * Create a new row for a table. + * + * @param data the values. + * @param memory whether the row is in memory. + * @return the created row. + */ public Row createRow(Value[] data, int memory) { return database.createRow(data, memory); } diff --git a/h2/src/main/org/h2/util/DateTimeUtils.java b/h2/src/main/org/h2/util/DateTimeUtils.java index effd31f572104869a2afda94554c88195f36abf3..a4d0b42f02981f8dd9738b0445d6e79d202d0225 100644 --- a/h2/src/main/org/h2/util/DateTimeUtils.java +++ b/h2/src/main/org/h2/util/DateTimeUtils.java @@ -457,6 +457,14 @@ public class DateTimeUtils { return ((((hour * 60L) + minute) * 60) + second) * NANOS_PER_SECOND + nanos; } + /** + * Parse nanoseconds. + * + * @param s String to parse. + * @param start Begin position at the string to read. + * @param end End position at the string to read. + * @return Parsed nanoseconds. + */ static int parseNanos(String s, int start, int end) { if (start >= end) { throw new IllegalArgumentException(s); @@ -1230,6 +1238,8 @@ public class DateTimeUtils { } /** + * Creates the instance of the {@link ValueTimestampTimeZone} from milliseconds. + * * @param ms milliseconds since 1970-01-01 (UTC) * @return timestamp with time zone with specified value and current time zone */ @@ -1473,6 +1483,11 @@ public class DateTimeUtils { } } + /** + * Skip trailing zeroes. + * + * @param buff String buffer. + */ static void stripTrailingZeroes(StringBuilder buff) { int i = buff.length() - 1; if (buff.charAt(i) == '0') { diff --git a/h2/src/main/org/h2/util/IntervalUtils.java b/h2/src/main/org/h2/util/IntervalUtils.java index 6d7ffb9eb1c2cc5d6e0d1758b659d005bd7485d9..f87431a2e00c4003e06a798d573b125f31a1c327 100644 --- a/h2/src/main/org/h2/util/IntervalUtils.java +++ b/h2/src/main/org/h2/util/IntervalUtils.java @@ -665,6 +665,8 @@ public class IntervalUtils { } /** + * Returns years value of interval, if any. + * * @param qualifier * qualifier * @param negative @@ -688,6 +690,8 @@ public class IntervalUtils { } /** + * Returns months value of interval, if any. + * * @param qualifier * qualifier * @param negative @@ -715,6 +719,8 @@ public class IntervalUtils { } /** + * Returns days value of interval, if any. + * * @param qualifier * qualifier * @param negative @@ -723,7 +729,7 @@ public class IntervalUtils { * value of leading field * @param remaining * values of all remaining fields - * @return months, or 0 + * @return days, or 0 */ public static long daysFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining) { switch (qualifier) { @@ -742,6 +748,8 @@ public class IntervalUtils { } /** + * Returns hours value of interval, if any. + * * @param qualifier * qualifier * @param negative @@ -779,6 +787,8 @@ public class IntervalUtils { } /** + * Returns minutes value of interval, if any. + * * @param qualifier * qualifier * @param negative @@ -819,6 +829,8 @@ public class IntervalUtils { } /** + * Returns nanoseconds value of interval, if any. + * * @param qualifier * qualifier * @param negative diff --git a/h2/src/main/org/h2/util/ValueHashMap.java b/h2/src/main/org/h2/util/ValueHashMap.java index 97fcacc63b8d73c30c6adc7fc18cdadc2eb8dff7..9d43e1a0e6f88e7d3f7945621d3a7d34228aa330 100644 --- a/h2/src/main/org/h2/util/ValueHashMap.java +++ b/h2/src/main/org/h2/util/ValueHashMap.java @@ -10,6 +10,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Set; + import org.h2.message.DbException; import org.h2.value.Value; import org.h2.value.ValueNull; @@ -35,7 +37,14 @@ import org.h2.value.ValueNull; */ public class ValueHashMap<V> extends HashBase { + /** + * Keys array. + */ Value[] keys; + + /** + * Values array. + */ V[] values; @Override @@ -202,6 +211,11 @@ public class ValueHashMap<V> extends HashBase { } } + /** + * Gets all map's entries. + * + * @return all map's entries. + */ public Iterable<Map.Entry<Value, V>> entries() { return new EntryIterable(); } diff --git a/h2/src/main/org/h2/util/geometry/EWKBUtils.java b/h2/src/main/org/h2/util/geometry/EWKBUtils.java index a0de1586e4af6830e9d6d05d38300fc4d8f3e3fb..cd67c3cb6783706accbbaed252fd93088bed098e 100644 --- a/h2/src/main/org/h2/util/geometry/EWKBUtils.java +++ b/h2/src/main/org/h2/util/geometry/EWKBUtils.java @@ -269,7 +269,7 @@ public final class EWKBUtils { * * @param ewkb * source EWKB - * @param dimension + * @param dimensionSystem * dimension system * @return canonical EWKB, may be the same as the source */ diff --git a/h2/src/main/org/h2/util/geometry/EWKTUtils.java b/h2/src/main/org/h2/util/geometry/EWKTUtils.java index cd4053e758bbe88eec66f6eca3347af62844c8fe..b3965610b1c30a6b8d49072b0b87de810ff2ac76 100644 --- a/h2/src/main/org/h2/util/geometry/EWKTUtils.java +++ b/h2/src/main/org/h2/util/geometry/EWKTUtils.java @@ -563,7 +563,7 @@ public final class EWKTUtils { * * @param ewkb * source EWKB - * @param dimension + * @param dimensionSystem * dimension system * @return EWKT representation */ @@ -594,7 +594,7 @@ public final class EWKTUtils { * * @param ewkt * source EWKT - * @param dimension + * @param dimensionSystem * dimension system * @return EWKB representation */ @@ -608,7 +608,7 @@ public final class EWKTUtils { /** * Parses a EWKB. * - * @param source + * @param ewkt * source EWKT * @param target * output target diff --git a/h2/src/main/org/h2/value/Value.java b/h2/src/main/org/h2/value/Value.java index 2754b7f8603e378be5f0874b7554257bb8784891..5dc4aa4dce8401f437edf938cc7e8a5a8114de20 100644 --- a/h2/src/main/org/h2/value/Value.java +++ b/h2/src/main/org/h2/value/Value.java @@ -1347,6 +1347,12 @@ public abstract class Value { return ValueResultSet.get(result); } + /** + * Creates new instance of the DbException for data conversion error. + * + * @param targetType Target data type. + * @return instance of the DbException. + */ DbException getDataConversionError(int targetType) { DataType from = DataType.getDataType(getType()); DataType to = DataType.getDataType(targetType); @@ -1489,6 +1495,13 @@ public abstract class Value { return (short) x; } + /** + * Checks value by Integer type numeric range. + * + * @param x integer value. + * @param column Column info. + * @return x + */ public static int convertToInt(long x, Object column) { if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE) { throw DbException.get( diff --git a/h2/src/main/org/h2/value/ValueCollectionBase.java b/h2/src/main/org/h2/value/ValueCollectionBase.java index 2c334121f074b797086fa3daaf689d7bd15073e4..672cc23f35da40d87d0c9a9270d97fca42485a15 100644 --- a/h2/src/main/org/h2/value/ValueCollectionBase.java +++ b/h2/src/main/org/h2/value/ValueCollectionBase.java @@ -16,6 +16,9 @@ import org.h2.util.MathUtils; */ public abstract class ValueCollectionBase extends Value { + /** + * Values. + */ final Value[] values; private int hash; diff --git a/h2/src/main/org/h2/value/ValueInterval.java b/h2/src/main/org/h2/value/ValueInterval.java index a3dd1c2b44345236ff4cf19589e2497f00183478..dde8b2748dd5301ec1a3c95181a413831bc39ad9 100644 --- a/h2/src/main/org/h2/value/ValueInterval.java +++ b/h2/src/main/org/h2/value/ValueInterval.java @@ -53,6 +53,8 @@ public class ValueInterval extends Value { private final long remaining; /** + * Creates interval value. + * * @param qualifier * qualifier * @param negative @@ -80,6 +82,7 @@ public class ValueInterval extends Value { * @param scale * fractional seconds precision. Ignored if specified type of * interval does not have seconds. + * @return displayed size. */ public static int getDisplaySize(int type, int precision, int scale) { switch (type) { diff --git a/h2/src/test/org/h2/test/TestAll.java b/h2/src/test/org/h2/test/TestAll.java index 21d2c2fd113f649fd6465878e73a2b5461bc0c52..f19358f1d1c445cfd49aa483a7ec3ce4a300435c 100644 --- a/h2/src/test/org/h2/test/TestAll.java +++ b/h2/src/test/org/h2/test/TestAll.java @@ -439,6 +439,10 @@ java org.h2.test.TestAll timer private Server server; + /** + * The map of executed tests to detect not executed tests. + * Boolean value is 'false' for a disabled test. + */ HashMap<Class<? extends TestBase>, Boolean> executedTests = new HashMap<>(); /** diff --git a/h2/src/test/org/h2/test/auth/TestAuthentication.java b/h2/src/test/org/h2/test/auth/TestAuthentication.java index 9b67b0f0f362191dff16e4603ebd283266d0ed97..affcc205b71c631436b9577466de138ffba89a7e 100644 --- a/h2/src/test/org/h2/test/auth/TestAuthentication.java +++ b/h2/src/test/org/h2/test/auth/TestAuthentication.java @@ -39,35 +39,50 @@ import org.h2.test.TestBase; */ public class TestAuthentication extends TestBase { + private static final String TESTXML = "<h2Auth allowUserRegistration=\"true\" createMissingRoles=\"false\">" + + "<realm name=\"ciao\" validatorClass=\"myclass\"/>" + + "<realm name=\"miao\" validatorClass=\"myclass1\">" + + "<property name=\"prop1\" value=\"value1\"/>" + + "<userToRolesMapper className=\"class1\">" + + "<property name=\"prop2\" value=\"value2\"/>" + + "</userToRolesMapper>" + + "</realm>" + + "</h2Auth>"; + + private String externalUserPassword; + private DefaultAuthenticator defaultAuthenticator; + private Session session; + private Database database; + + /** + * Run just this test. + * + * @param a ignored + */ public static void main(String... a) throws Exception { TestBase.createCaller().init().test(); } - String externalUserPassword; - - - String getExternalUserPassword() { + private String getExternalUserPassword() { if (externalUserPassword == null) { externalUserPassword = UUID.randomUUID().toString(); } return externalUserPassword; } - String getRealmName() { + private String getRealmName() { return "testRealm"; } - String getJaasConfigName() { + private String getJaasConfigName() { return "testJaasH2"; } - String getStaticRoleName() { + private String getStaticRoleName() { return "staticRole"; } - DefaultAuthenticator defaultAuthenticator; - - void configureAuthentication(Database database) { + private void configureAuthentication(Database database) { defaultAuthenticator = new DefaultAuthenticator(true); defaultAuthenticator.setAllowUserRegistration(true); defaultAuthenticator.setCreateMissingRoles(true); @@ -79,7 +94,7 @@ public class TestAuthentication extends TestBase { database.setAuthenticator(defaultAuthenticator); } - void configureJaas() { + private void configureJaas() { final Configuration innerConfiguration = Configuration.getConfiguration(); Configuration.setConfiguration(new Configuration() { @Override @@ -95,17 +110,14 @@ public class TestAuthentication extends TestBase { }); } - protected String getDatabaseURL() { + private String getDatabaseURL() { return "jdbc:h2:mem:" + getClass().getSimpleName(); } - protected String getExternalUser() { + private String getExternalUser() { return "user"; } - Session session; - Database database; - @Override public void test() throws Exception { Configuration oldConfiguration = Configuration.getConfiguration(); @@ -127,7 +139,7 @@ public class TestAuthentication extends TestBase { } } - protected void allTests() throws Exception { + private void allTests() throws Exception { testInvalidPassword(); testExternalUserWithoutRealm(); testExternalUser(); @@ -140,53 +152,46 @@ public class TestAuthentication extends TestBase { testXmlConfig(); } - protected void testInvalidPassword() throws Exception { + private void testInvalidPassword() throws Exception { try { Connection wrongLoginConnection = DriverManager.getConnection( getDatabaseURL() + ";AUTHREALM=" + getRealmName().toUpperCase(), getExternalUser(), ""); wrongLoginConnection.close(); throw new Exception("user should not be able to login with an invalid password"); - } catch (SQLException e) { + } catch (SQLException ignored) { } } - protected void testExternalUserWithoutRealm() throws Exception { + private void testExternalUserWithoutRealm() throws Exception { try { Connection wrongLoginConnection = DriverManager.getConnection(getDatabaseURL(), getExternalUser(), getExternalUserPassword()); wrongLoginConnection.close(); throw new Exception("user should not be able to login without a realm"); - } catch (SQLException e) { + } catch (SQLException ignored) { } } - protected void testExternalUser() throws Exception { - Connection rightConnection = DriverManager.getConnection( + private void testExternalUser() throws Exception { + try (Connection ignored = DriverManager.getConnection( getDatabaseURL() + ";AUTHREALM=" + getRealmName().toUpperCase(), getExternalUser(), - getExternalUserPassword()); - try { + getExternalUserPassword())) { User user = session.getDatabase().findUser((getExternalUser() + "@" + getRealmName()).toUpperCase()); assertNotNull(user); - } finally { - rightConnection.close(); } } - protected void testDatasource() throws Exception { - + private void testDatasource() throws Exception { DataSource dataSource = JdbcConnectionPool.create( getDatabaseURL() + ";AUTHREALM=" + getRealmName().toUpperCase(), getExternalUser(), getExternalUserPassword()); - Connection rightConnection = dataSource.getConnection(); - try { + try (Connection ignored = dataSource.getConnection()) { User user = session.getDatabase().findUser((getExternalUser() + "@" + getRealmName()).toUpperCase()); assertNotNull(user); - } finally { - rightConnection.close(); } } - protected void testAssignRealNameRole() throws Exception { + private void testAssignRealNameRole() throws Exception { String realmNameRoleName = "@" + getRealmName().toUpperCase(); Role realmNameRole = database.findRole(realmNameRoleName); if (realmNameRole == null) { @@ -194,35 +199,29 @@ public class TestAuthentication extends TestBase { session.getDatabase().addDatabaseObject(session, realmNameRole); session.commit(false); } - Connection rightConnection = DriverManager.getConnection( + try (Connection ignored = DriverManager.getConnection( getDatabaseURL() + ";AUTHREALM=" + getRealmName().toUpperCase(), getExternalUser(), - getExternalUserPassword()); - try { + getExternalUserPassword())) { User user = session.getDatabase().findUser((getExternalUser() + "@" + getRealmName()).toUpperCase()); assertNotNull(user); assertTrue(user.isRoleGranted(realmNameRole)); - } finally { - rightConnection.close(); } } - protected void testStaticRole() throws Exception { - Connection rightConnection = DriverManager.getConnection( + private void testStaticRole() throws Exception { + try (Connection ignored = DriverManager.getConnection( getDatabaseURL() + ";AUTHREALM=" + getRealmName().toUpperCase(), getExternalUser(), - getExternalUserPassword()); - try { + getExternalUserPassword())) { User user = session.getDatabase().findUser((getExternalUser() + "@" + getRealmName()).toUpperCase()); assertNotNull(user); Role staticRole = session.getDatabase().findRole(getStaticRoleName()); if (staticRole != null) { assertTrue(user.isRoleGranted(staticRole)); } - } finally { - rightConnection.close(); } } - protected void testUserRegistration() throws Exception { + private void testUserRegistration() throws Exception { boolean initialValueAllow = defaultAuthenticator.isAllowUserRegistration(); defaultAuthenticator.setAllowUserRegistration(false); try { @@ -233,7 +232,7 @@ public class TestAuthentication extends TestBase { wrongLoginConnection.close(); throw new Exception( "unregistered external users should not be able to login when allowUserRegistration=false"); - } catch (SQLException e) { + } catch (SQLException ignored) { } String validUserName = "new_" + getExternalUser(); User validUser = new User(database, database.allocateObjectId(), @@ -250,23 +249,19 @@ public class TestAuthentication extends TestBase { } } - public void testStaticUserCredentials() throws Exception { + private void testStaticUserCredentials() throws Exception { String userName="STATICUSER3"; - Connection rightConnection = DriverManager.getConnection( - getDatabaseURL() + ";AUTHREALM=" + getRealmName().toUpperCase()+"_STATIC",userName, - "staticpassword"); - try { - User user = session.getDatabase().findUser(userName+ "@" + getRealmName().toUpperCase()+"_STATIC"); + try (Connection ignored = DriverManager.getConnection( + getDatabaseURL() + ";AUTHREALM=" + getRealmName().toUpperCase() + "_STATIC", userName, + "staticpassword")) { + User user = session.getDatabase().findUser(userName + "@" + getRealmName().toUpperCase() + "_STATIC"); assertNotNull(user); - } finally { - rightConnection.close(); } } - protected void testSet() throws Exception{ - Connection rightConnection = DriverManager.getConnection( - getDatabaseURL()+";AUTHENTICATOR=FALSE","DBA",""); - try { + private void testSet() throws Exception{ + try (Connection ignored = DriverManager.getConnection( + getDatabaseURL() + ";AUTHENTICATOR=FALSE", "DBA", "")) { try { testExternalUser(); throw new Exception("External user shouldn't be allowed"); @@ -274,22 +269,11 @@ public class TestAuthentication extends TestBase { } } finally { configureAuthentication(database); - rightConnection.close(); } testExternalUser(); } - static final String TESTXML="<h2Auth allowUserRegistration=\"true\" createMissingRoles=\"false\">" - + "<realm name=\"ciao\" validatorClass=\"myclass\"/>" - + "<realm name=\"miao\" validatorClass=\"myclass1\">" - + "<property name=\"prop1\" value=\"value1\"/>" - + "<userToRolesMapper className=\"class1\">" - + "<property name=\"prop2\" value=\"value2\"/>" - + "</userToRolesMapper>" - + "</realm>" - + "</h2Auth>"; - - protected void testXmlConfig() throws Exception { + private void testXmlConfig() throws Exception { ByteArrayInputStream inputStream = new ByteArrayInputStream(TESTXML.getBytes()); H2AuthConfig config = H2AuthConfigXml.parseFrom(inputStream); assertTrue(config.isAllowUserRegistration()); diff --git a/h2/src/test/org/h2/test/jdbc/TestSQLXML.java b/h2/src/test/org/h2/test/jdbc/TestSQLXML.java index fea8b13cc76595e248e541ab16a676c77c725f66..164e5322236807dddb5394e934ddfd7a9760d63a 100644 --- a/h2/src/test/org/h2/test/jdbc/TestSQLXML.java +++ b/h2/src/test/org/h2/test/jdbc/TestSQLXML.java @@ -185,7 +185,7 @@ public class TestSQLXML extends TestDb { } } - void testSettersImpl(SQLXML sqlxml) throws SQLException { + private void testSettersImpl(SQLXML sqlxml) throws SQLException { PreparedStatement prep = conn.prepareStatement("UPDATE TEST SET X = ?"); prep.setSQLXML(1, sqlxml); assertEquals(1, prep.executeUpdate()); diff --git a/h2/src/test/org/h2/test/scripts/TestScript.java b/h2/src/test/org/h2/test/scripts/TestScript.java index fe6f4547be45ff8393843bd59c5698a28f4e9874..c1d21940c47cca9ae3532d1beb22acfe6f6e6c0e 100644 --- a/h2/src/test/org/h2/test/scripts/TestScript.java +++ b/h2/src/test/org/h2/test/scripts/TestScript.java @@ -289,7 +289,7 @@ public class TestScript extends TestDb { return s; } - public void putBack(String line) { + private void putBack(String line) { putBack.addLast(line); } diff --git a/h2/src/test/org/h2/test/unit/TestLocalResultFactory.java b/h2/src/test/org/h2/test/unit/TestLocalResultFactory.java index ffa003e7a20076cfb63d49dfe62164f48056e50d..9298f31c1af4ce1bfe887cd2cd15b731b81d4836 100644 --- a/h2/src/test/org/h2/test/unit/TestLocalResultFactory.java +++ b/h2/src/test/org/h2/test/unit/TestLocalResultFactory.java @@ -50,7 +50,8 @@ public class TestLocalResultFactory extends TestBase { * Test local result factory. */ public static class MyTestLocalResultFactory extends LocalResultFactory { - static final AtomicInteger COUNTER = new AtomicInteger(); + /** Call counter for the factory methods. */ + private static final AtomicInteger COUNTER = new AtomicInteger(); @Override public LocalResult create(Session session, Expression[] expressions, int visibleColumnCount) { COUNTER.incrementAndGet(); diff --git a/h2/src/test/org/h2/test/unit/TestValue.java b/h2/src/test/org/h2/test/unit/TestValue.java index 259dadcbf4d18b39f1c2463045bda325aab04d4e..6fa783596296a181e4b73018b5cad203e2c14d37 100644 --- a/h2/src/test/org/h2/test/unit/TestValue.java +++ b/h2/src/test/org/h2/test/unit/TestValue.java @@ -483,7 +483,7 @@ public class TestValue extends TestDb { return lob1.compareTypeSafe(lob2, null); } - static Value createLob(DataHandler dh, int type, byte[] bytes) { + private static Value createLob(DataHandler dh, int type, byte[] bytes) { if (dh == null) { return ValueLobDb.createSmallLob(type, bytes); } diff --git a/h2/src/tools/org/h2/build/Build.java b/h2/src/tools/org/h2/build/Build.java index 21acc2785b53c22d92e03d28ea048010619075b5..848f437b7cc2bc6f6994cb5196a6d0e85746b2a6 100644 --- a/h2/src/tools/org/h2/build/Build.java +++ b/h2/src/tools/org/h2/build/Build.java @@ -668,7 +668,9 @@ public class Build extends BuildBase { File.pathSeparator + "ext/lucene-queryparser-5.5.5.jar" + File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" + - File.pathSeparator + "ext/jts-core-1.15.0.jar", + File.pathSeparator + "ext/jts-core-1.15.0.jar" + + File.pathSeparator + "ext/asm-6.1.jar" + + File.pathSeparator + "ext/junit-4.12.jar", "-subpackages", "org.h2"); mkdir("docs/javadocImpl3"); @@ -684,7 +686,9 @@ public class Build extends BuildBase { File.pathSeparator + "ext/lucene-queryparser-5.5.5.jar" + File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" + - File.pathSeparator + "ext/jts-core-1.15.0.jar", + File.pathSeparator + "ext/jts-core-1.15.0.jar" + + File.pathSeparator + "ext/asm-6.1.jar" + + File.pathSeparator + "ext/junit-4.12.jar", "-subpackages", "org.h2.mvstore", "-exclude", "org.h2.mvstore.db"); @@ -701,7 +705,9 @@ public class Build extends BuildBase { File.pathSeparator + "ext/lucene-queryparser-5.5.5.jar" + File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" + - File.pathSeparator + "ext/jts-core-1.15.0.jar", + File.pathSeparator + "ext/jts-core-1.15.0.jar" + + File.pathSeparator + "ext/asm-6.1.jar" + + File.pathSeparator + "ext/junit-4.12.jar", "-subpackages", "org.h2", "-package", "-docletpath", "bin" + File.pathSeparator + "temp",