All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jooq.tools.jdbc.MockFileDatabaseConfiguration Maven / Gradle / Ivy

There is a newer version: 3.19.15
Show newest version
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Other licenses:
 * -----------------------------------------------------------------------------
 * Commercial licenses for this work are available. These replace the above
 * Apache-2.0 license and offer limited warranties, support, maintenance, and
 * commercial database integrations.
 *
 * For more information, please visit: http://www.jooq.org/licenses
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
package org.jooq.tools.jdbc;

import java.io.File;
import java.io.InputStream;
import java.io.LineNumberReader;
import java.io.Reader;
import java.io.StringReader;

import org.jooq.Source;

/**
 * A configuration object for the {@link MockFileDatabase}.
 * 

* Disclaimer: The general idea of mocking a JDBC connection with this * jOOQ API is to provide quick workarounds, injection points, etc. using a very * simple JDBC abstraction. It is NOT RECOMMENDED to emulate an entire database * (including complex state transitions, transactions, locking, etc.) using this * mock API. Once you have this requirement, please consider using an actual * database instead for integration testing (e.g. using * https://www.testcontainers.org), * rather than implementing your test database inside of a * MockDataProvider. * * @author Lukas Eder */ public final class MockFileDatabaseConfiguration { final LineNumberReader in; final boolean patterns; final String nullLiteral; public MockFileDatabaseConfiguration() { this(new LineNumberReader(new StringReader("")), false, null); } private MockFileDatabaseConfiguration( LineNumberReader in, boolean patterns, String nullLiteral ) { this.in = in; this.patterns = patterns; this.nullLiteral = nullLiteral; } public final MockFileDatabaseConfiguration source(File file) { return source(Source.of(file, "UTF-8")); } public final MockFileDatabaseConfiguration source(File file, String encoding) { return source(Source.of(file, encoding)); } public final MockFileDatabaseConfiguration source(InputStream stream) { return source(Source.of(stream, "UTF-8")); } public final MockFileDatabaseConfiguration source(InputStream stream, String encoding) { return source(Source.of(stream, encoding)); } public final MockFileDatabaseConfiguration source(Source source) { return source(source.reader()); } public final MockFileDatabaseConfiguration source(Reader reader) { return new MockFileDatabaseConfiguration(new LineNumberReader(reader), patterns, nullLiteral); } public final MockFileDatabaseConfiguration source(String string) { return source(Source.of(string)); } public final MockFileDatabaseConfiguration patterns(boolean newPatterns) { return new MockFileDatabaseConfiguration(in, newPatterns, nullLiteral); } public final MockFileDatabaseConfiguration nullLiteral(String newNullLiteral) { return new MockFileDatabaseConfiguration(in, patterns, newNullLiteral); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy