MCPcopy Create free account
hub / github.com/apache/calcite / Driver

Class Driver

core/src/main/java/org/apache/calcite/jdbc/Driver.java:56–245  ·  view source on GitHub ↗

Calcite JDBC driver.

Source from the content-addressed store, hash-verified

54 * Calcite JDBC driver.
55 */
56public class Driver extends UnregisteredDriver {
57 public static final String CONNECT_STRING_PREFIX = "jdbc:calcite:";
58
59 protected final @Nullable Supplier<CalcitePrepare> prepareFactory;
60
61 static {
62 new Driver().register();
63 }
64
65 /** Creates a Driver. */
66 public Driver() {
67 this(null);
68 }
69
70 /** Creates a Driver with a factory for {@code CalcitePrepare} objects;
71 * if the factory is null, the driver will call
72 * {@link CalcitePrepare#DEFAULT_FACTORY}. */
73 protected Driver(@Nullable Supplier<CalcitePrepare> prepareFactory) {
74 this.prepareFactory = prepareFactory;
75 }
76
77 /** Creates a copy of this Driver with a new factory for creating
78 * {@link CalcitePrepare}.
79 *
80 * <p>Allows users of the Driver to change the factory without subclassing
81 * the Driver. But subclasses of the driver should override this method to
82 * create an instance of their subclass.
83 *
84 * @param prepareFactory Supplier of a {@code CalcitePrepare}
85 * @return Driver with the provided prepareFactory
86 */
87 public Driver withPrepareFactory(Supplier<CalcitePrepare> prepareFactory) {
88 requireNonNull(prepareFactory, "prepareFactory");
89 if (this.prepareFactory == prepareFactory) {
90 return this;
91 }
92 return new Driver(prepareFactory);
93 }
94
95 /** Creates a {@link CalcitePrepare} to be used to prepare a statement for
96 * execution.
97 *
98 * <p>If you wish to use a custom prepare, either override this method or
99 * call {@link #withPrepareFactory(Supplier)}. */
100 public CalcitePrepare createPrepare() {
101 if (prepareFactory != null) {
102 return prepareFactory.get();
103 }
104 return CalcitePrepare.DEFAULT_FACTORY.apply();
105 }
106
107 /** Returns a factory with which to create a {@link CalcitePrepare}.
108 *
109 * <p>Now deprecated; if you wish to use a custom prepare, please call
110 * {@link #withPrepareFactory(Supplier)}
111 * or override {@link #createPrepare()}. */
112 @Deprecated // to be removed before 2.0
113 protected Function0<CalcitePrepare> createPrepareFactory() {

Callers

nothing calls this directly

Calls 1

registerMethod · 0.65

Tested by

no test coverage detected