equal
deleted
inserted
replaced
24 */ |
24 */ |
25 package jdk.incubator.sql2; |
25 package jdk.incubator.sql2; |
26 |
26 |
27 import java.util.ServiceLoader; |
27 import java.util.ServiceLoader; |
28 import java.util.ServiceLoader.Provider; |
28 import java.util.ServiceLoader.Provider; |
29 import java.util.function.Function; |
|
30 |
29 |
31 /** |
30 /** |
32 * This interface supports injecting a {@link DataSourceFactory}. The SPI |
31 * This interface supports injecting a {@link DataSourceFactory}. The SPI |
33 * mechanism will find {@link DataSourceFactory} implementations with the |
32 * mechanism will find {@link DataSourceFactory} implementations with the |
34 * given class name. |
33 * given class name. |
40 |
39 |
41 /** |
40 /** |
42 * Uses SPI to find a {@link DataSourceFactory} with the requested name or |
41 * Uses SPI to find a {@link DataSourceFactory} with the requested name or |
43 * {@code null} if one is not found. |
42 * {@code null} if one is not found. |
44 * |
43 * |
|
44 * @param <T> |
45 * @param name the name of the class that implements the factory |
45 * @param name the name of the class that implements the factory |
46 * @return a {@link DataSourceFactory} for {@code name} or {@code null} if one |
46 * @return a {@link DataSourceFactory} for {@code name} or {@code null} if one |
47 * is not found |
47 * is not found |
48 */ |
48 */ |
49 public static DataSourceFactory forName(String name) { |
49 public static <T extends DataSourceFactory> T newFactory(String name) { |
50 if (name == null) throw new IllegalArgumentException("DataSourceFactory name is null"); |
50 if (name == null) throw new IllegalArgumentException("DataSourceFactory name is null"); |
51 return ServiceLoader |
51 return (T)ServiceLoader |
52 .load(DataSourceFactory.class) |
52 .load(DataSourceFactory.class) |
53 .stream() |
53 .stream() |
54 .filter(p -> p.type().getName().equals(name)) |
54 .filter(p -> p.type().getName().equals(name)) |
55 .findFirst() |
55 .findFirst() |
56 .map(Provider::get) |
56 .map(Provider::get) |