QueryState { public ResultSet invoke(Connection conn, Statement statement) throws SQLException { switch (type) { case SQL: boolean ret = Objects.requireNonNull(statement).execute(sql); ResultSet results = statement.getResultSet(); assert ret || null == results; return results; case METADATA: DatabaseMetaData metadata = Objects.requireNonNull(conn).getMetaData(); switch (metaDataOperation) { case GET_ATTRIBUTES: verifyOpArgs(4); return metadata.getAttributes((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2], (String) operationArgs[3]); case GET_BEST_ROW_IDENTIFIER: verifyOpArgs(5); return metadata.getBestRowIdentifier((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2], (int) operationArgs[3], (boolean) operationArgs[4]); case GET_CATALOGS: verifyOpArgs(0); return metadata.getCatalogs(); case GET_COLUMNS: verifyOpArgs(4); return metadata.getColumns((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2], (String) operationArgs[3]); case GET_COLUMN_PRIVILEGES: verifyOpArgs(4); return metadata.getColumnPrivileges((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2], (String) operationArgs[3]); case GET_CROSS_REFERENCE: verifyOpArgs(6); return metadata.getCrossReference((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2], (String) operationArgs[3], (String) operationArgs[4], (String) operationArgs[5]); case GET_EXPORTED_KEYS: verifyOpArgs(3); return metadata.getExportedKeys((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2]); case GET_FUNCTIONS: verifyOpArgs(3); return metadata.getFunctions((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2]); case GET_FUNCTION_COLUMNS: verifyOpArgs(4); return metadata.getFunctionColumns((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2], (String) operationArgs[3]); case GET_IMPORTED_KEYS: verifyOpArgs(3); return metadata.getImportedKeys((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2]); case GET_INDEX_INFO: verifyOpArgs(5); return metadata.getIndexInfo((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2], (boolean) operationArgs[3], (boolean) operationArgs[4]); case GET_PRIMARY_KEYS: verifyOpArgs(3); return metadata.getPrimaryKeys((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2]); case GET_PROCEDURES: verifyOpArgs(3); return metadata.getProcedures((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2]); case GET_PROCEDURE_COLUMNS: verifyOpArgs(4); return metadata.getProcedureColumns((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2], (String) operationArgs[3]); case GET_PSEUDO_COLUMNS: verifyOpArgs(4); return metadata.getPseudoColumns((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2], (String) operationArgs[3]); case GET_SCHEMAS: verifyOpArgs(0); return metadata.getSchemas(); case GET_SCHEMAS_WITH_ARGS: verifyOpArgs(2); return metadata.getSchemas((String) operationArgs[0], (String) operationArgs[1]); case GET_SUPER_TABLES: verifyOpArgs(3); return metadata.getSuperTables((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2]); case GET_SUPER_TYPES: verifyOpArgs(3); return metadata.getSuperTypes((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2]); case GET_TABLES: verifyOpArgs(4); return metadata.getTables((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2], (String[]) operationArgs[3]); case GET_TABLE_PRIVILEGES: verifyOpArgs(3); return metadata.getTablePrivileges((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2]); case GET_TABLE_TYPES: verifyOpArgs(0); return metadata.getTableTypes(); case GET_TYPE_INFO: verifyOpArgs(0); return metadata.getTypeInfo(); case GET_UDTS: verifyOpArgs(4); return metadata.getUDTs((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2], (int[]) operationArgs[3]); case GET_VERSION_COLUMNS: verifyOpArgs(3); return metadata.getVersionColumns((String) operationArgs[0], (String) operationArgs[1], (String) operationArgs[2]); default: throw new IllegalArgumentException("Unhandled Metadata operation: " + metaDataOperation); } default: throw new IllegalArgumentException("Unable to process QueryState of type " + type); } } QueryState(String sql);  QueryState(MetaDataOperation op, Object... args);  QueryState(StateType type, String sql, MetaDataOperation op, Object... args);  QueryState(); StateType getType(); String getSql(); MetaDataOperation getMetaDataOperation(); Object[] getOperationArgs(); ResultSet invoke(Connection conn, Statement statement); Common.QueryState toProto(); static QueryState fromProto(Common.QueryState protoState); @Override int hashCode(); @Override boolean equals(Object obj); @JsonProperty("type")
  final StateType type; @JsonProperty("sql")
  final String sql; @JsonProperty("metaDataOperation")
  final MetaDataOperation metaDataOperation; @JsonProperty("operationArgs")
  final Object[] operationArgs; }
@Test public void testMetadataGetAttributes() throws Exception { final String catalog = "catalog"; final String schemaPattern = null; final String typeNamePattern = "%"; final String attributeNamePattern = "%"; QueryState state = new QueryState(MetaDataOperation.GET_ATTRIBUTES, catalog, schemaPattern, typeNamePattern, attributeNamePattern); state.invoke(conn, statement); Mockito.verify(metadata).getAttributes(catalog, schemaPattern, typeNamePattern, attributeNamePattern); }
@Test public void testMetadataGetIndexInfo() throws Exception { final String catalog = ""; final String schema = null; final String table = "my_table"; final boolean unique = true; final boolean approximate = true; QueryState state = new QueryState(MetaDataOperation.GET_INDEX_INFO, new Object[] { catalog, schema, table, unique, approximate }); state.invoke(conn, statement); Mockito.verify(metadata).getIndexInfo(catalog, schema, table, unique, approximate); }
@Test public void testMetadataGetPrimaryKeys() throws Exception { final String catalog = ""; final String schema = null; final String table = "my_table"; QueryState state = new QueryState(MetaDataOperation.GET_PRIMARY_KEYS, new Object[] { catalog, schema, table }); state.invoke(conn, statement); Mockito.verify(metadata).getPrimaryKeys(catalog, schema, table); }
@Test public void testMetadataGetProcedureColumns() throws Exception { final String catalog = ""; final String schemaPattern = null; final String procedureNamePattern = "%"; final String columnNamePattern = "%"; QueryState state = new QueryState(MetaDataOperation.GET_PROCEDURE_COLUMNS, new Object[] { catalog, schemaPattern, procedureNamePattern, columnNamePattern }); state.invoke(conn, statement); Mockito.verify(metadata).getProcedureColumns(catalog, schemaPattern, procedureNamePattern, columnNamePattern); }
@Test public void testMetadataGetProcedures() throws Exception { final String catalog = ""; final String schemaPattern = null; final String procedureNamePattern = "%"; QueryState state = new QueryState(MetaDataOperation.GET_PROCEDURES, new Object[] { catalog, schemaPattern, procedureNamePattern, }); state.invoke(conn, statement); Mockito.verify(metadata).getProcedures(catalog, schemaPattern, procedureNamePattern); }
@Test public void testMetadataGetPseudoColumns() throws Exception { final String catalog = ""; final String schemaPattern = null; final String tableNamePattern = "%"; final String columnNamePattern = "%"; QueryState state = new QueryState(MetaDataOperation.GET_PSEUDO_COLUMNS, new Object[] { catalog, schemaPattern, tableNamePattern, columnNamePattern }); state.invoke(conn, statement); Mockito.verify(metadata).getPseudoColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern); }
@Test public void testMetadataGetSchemas() throws Exception { QueryState state = new QueryState(MetaDataOperation.GET_SCHEMAS, new Object[0]); state.invoke(conn, statement); Mockito.verify(metadata).getSchemas(); }
@Test public void testMetadataGetSchemasWithArgs() throws Exception { final String catalog = ""; final String schemaPattern = null; QueryState state = new QueryState(MetaDataOperation.GET_SCHEMAS_WITH_ARGS, new Object[] { catalog, schemaPattern }); state.invoke(conn, statement); Mockito.verify(metadata).getSchemas(catalog, schemaPattern); }
@Test public void testMetadataGetSuperTables() throws Exception { final String catalog = ""; final String schemaPattern = null; final String tableNamePattern = "%"; QueryState state = new QueryState(MetaDataOperation.GET_SUPER_TABLES, new Object[] { catalog, schemaPattern, tableNamePattern }); state.invoke(conn, statement); Mockito.verify(metadata).getSuperTables(catalog, schemaPattern, tableNamePattern); }
@Test public void testMetadataGetSuperTypes() throws Exception { final String catalog = ""; final String schemaPattern = null; final String tableNamePattern = "%"; QueryState state = new QueryState(MetaDataOperation.GET_SUPER_TYPES, new Object[] { catalog, schemaPattern, tableNamePattern }); state.invoke(conn, statement); Mockito.verify(metadata).getSuperTypes(catalog, schemaPattern, tableNamePattern); }
@Test public void testMetadataGetTablePrivileges() throws Exception { final String catalog = ""; final String schemaPattern = null; final String tableNamePattern = "%"; QueryState state = new QueryState(MetaDataOperation.GET_TABLE_PRIVILEGES, new Object[] { catalog, schemaPattern, tableNamePattern }); state.invoke(conn, statement); Mockito.verify(metadata).getTablePrivileges(catalog, schemaPattern, tableNamePattern); }
@Test public void testMetadataGetBestRowIdentifier() throws Exception { final String catalog = "catalog"; final String schema = null; final String table = "table"; final int scope = 1; final boolean nullable = true; QueryState state = new QueryState(MetaDataOperation.GET_BEST_ROW_IDENTIFIER, new Object[] { catalog, schema, table, scope, nullable }); state.invoke(conn, statement); Mockito.verify(metadata).getBestRowIdentifier(catalog, schema, table, scope, nullable); }
@Test public void testMetadataGetTables() throws Exception { final String catalog = ""; final String schemaPattern = null; final String tableNamePattern = "%"; final String[] types = new String[] {"VIEW", "TABLE"}; QueryState state = new QueryState(MetaDataOperation.GET_TABLES, new Object[] { catalog, schemaPattern, tableNamePattern, types }); state.invoke(conn, statement); Mockito.verify(metadata).getTables(catalog, schemaPattern, tableNamePattern, types); }
@Test public void testMetadataGetTableTypes() throws Exception { QueryState state = new QueryState(MetaDataOperation.GET_TABLE_TYPES, new Object[0]); state.invoke(conn, statement); Mockito.verify(metadata).getTableTypes(); }
@Test public void testMetadataGetTypeInfo() throws Exception { QueryState state = new QueryState(MetaDataOperation.GET_TYPE_INFO, new Object[0]); state.invoke(conn, statement); Mockito.verify(metadata).getTypeInfo(); }
@Test public void testMetadataGetUDTs() throws Exception { final String catalog = ""; final String schemaPattern = null; final String typeNamePattern = "%"; final int[] types = new int[] {1, 2}; QueryState state = new QueryState(MetaDataOperation.GET_UDTS, new Object[] { catalog, schemaPattern, typeNamePattern, types }); state.invoke(conn, statement); Mockito.verify(metadata).getUDTs(catalog, schemaPattern, typeNamePattern, types); }
@Test public void testMetadataGetVersionColumns() throws Exception { final String catalog = ""; final String schemaPattern = null; final String table = "my_table"; QueryState state = new QueryState(MetaDataOperation.GET_VERSION_COLUMNS, new Object[] { catalog, schemaPattern, table }); state.invoke(conn, statement); Mockito.verify(metadata).getVersionColumns(catalog, schemaPattern, table); }
@Test public void testMetadataGetCatalogs() throws Exception { QueryState state = new QueryState(MetaDataOperation.GET_CATALOGS, new Object[0]); state.invoke(conn, statement); Mockito.verify(metadata).getCatalogs(); }
@Test public void testMetadataGetColumnPrivileges() throws Exception { final String catalog = null; final String schema = "schema"; final String table = "table"; final String columnNamePattern = "%"; QueryState state = new QueryState(MetaDataOperation.GET_COLUMN_PRIVILEGES, new Object[] { catalog, schema, table, columnNamePattern }); state.invoke(conn, statement); Mockito.verify(metadata).getColumnPrivileges(catalog, schema, table, columnNamePattern); }
@Test public void testMetadataGetColumns() throws Exception { final String catalog = null; final String schemaPattern = "%"; final String tableNamePattern = "%"; final String columnNamePattern = "%"; QueryState state = new QueryState(MetaDataOperation.GET_COLUMNS, new Object[] { catalog, schemaPattern, tableNamePattern, columnNamePattern }); state.invoke(conn, statement); Mockito.verify(metadata).getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern); }
@Test public void testMetadataGetCrossReference() throws Exception { final String parentCatalog = null; final String parentSchema = null; final String parentTable = "%"; final String foreignCatalog = null; final String foreignSchema = null; final String foreignTable = "%"; QueryState state = new QueryState(MetaDataOperation.GET_CROSS_REFERENCE, new Object[] { parentCatalog, parentSchema, parentTable, foreignCatalog, foreignSchema, foreignTable }); state.invoke(conn, statement); Mockito.verify(metadata).getCrossReference(parentCatalog, parentSchema, parentTable, foreignCatalog, foreignSchema, foreignTable); }
@Test public void testMetadataGetExportedKeys() throws Exception { final String catalog = ""; final String schema = null; final String table = "mytable"; QueryState state = new QueryState(MetaDataOperation.GET_EXPORTED_KEYS, new Object[] { catalog, schema, table }); state.invoke(conn, statement); Mockito.verify(metadata).getExportedKeys(catalog, schema, table); }
@Test public void testMetadataGetFunctionColumns() throws Exception { final String catalog = null; final String schemaPattern = "%"; final String functionNamePattern = "%"; final String columnNamePattern = "%"; QueryState state = new QueryState(MetaDataOperation.GET_FUNCTION_COLUMNS, new Object[] { catalog, schemaPattern, functionNamePattern, columnNamePattern }); state.invoke(conn, statement); Mockito.verify(metadata).getFunctionColumns(catalog, schemaPattern, functionNamePattern, columnNamePattern); }
@Test public void testMetadataGetFunctions() throws Exception { final String catalog = null; final String schemaPattern = "%"; final String functionNamePattern = "%"; QueryState state = new QueryState(MetaDataOperation.GET_FUNCTIONS, new Object[] { catalog, schemaPattern, functionNamePattern }); state.invoke(conn, statement); Mockito.verify(metadata).getFunctions(catalog, schemaPattern, functionNamePattern); }
@Test public void testMetadataGetImportedKeys() throws Exception { final String catalog = ""; final String schema = null; final String table = "my_table"; QueryState state = new QueryState(MetaDataOperation.GET_IMPORTED_KEYS, new Object[] { catalog, schema, table }); state.invoke(conn, statement); Mockito.verify(metadata).getImportedKeys(catalog, schema, table); }