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

org.springframework.boot.autoconfigure.jdbc.plus.H2Url Maven / Gradle / Ivy

There is a newer version: 2.0.2.0
Show newest version
/*
 * Copyright 2016 the original author or authors.
 *
 * 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.
 */

package org.springframework.boot.autoconfigure.jdbc.plus;

import lombok.NonNull;

/**
 * {@link JdbcUrl} for H2
 */
public class H2Url extends JdbcUrl {
	
	/**
	 * Prefix
	 */
	public static final String PREFIX = "jdbc:h2:";
	
	/**
	 * URL is valid?
	 * 
	 * @param url URL
	 * @return {@code true} if URL is valid
	 */
	public static boolean isValid(String url) {
		
		try {
			
			@SuppressWarnings("unused")
			H2Url nop = new H2Url(url);
			
			return true;
		}
		catch (IllegalArgumentException e) {
			
			return false;
		}
	}
	
	/**
	 * Constructor
	 * 
	 * @param url URL
	 * @throws IllegalArgumentException if failed to parse URL
	 */
	public H2Url(String url) throws IllegalArgumentException {
		
		super(url);
	}
	
	@Override
	protected String getUrlPattern() {
		
		return "^" + PREFIX + "([^;]+)(.*?)$";
	}
	
	@Override
	protected String getPrefix() {
		
		return PREFIX;
	}
	
	@Override
	protected String getQueryStarter() {
		
		return this.getQueryJoiner();
	}
	
	@Override
	protected String getQueryJoiner() {
		
		return ";";
	}
	
	@Override
	protected String getParamJoiner() {
		
		return "=";
	}
	
	@Override
	protected String convertParamValue(Object value) {
		
		String converted = String.valueOf(value);
		
		if (value instanceof Boolean) {
			
			converted = converted.toUpperCase();
		}
		
		return converted;
	}
	
	/**
	 * Add parameter
	 * 
	 * @param key key
	 * @param value value
	 * @return {@link H2Url}
	 */
	public H2Url param(String key, Object value) {
		
		this.addParam(key, value);
		
		return this;
	}
	
	/**
	 * INIT
	 * 
	 * @param value value
	 * @return {@link H2Url}
	 */
	public H2Url init(String value) {
		
		this.addParam("INIT", value);
		
		return this;
	}
	
	/**
	 * DATABASE_TO_UPPER
	 * 
	 * @param value value
	 * @return {@link H2Url}
	 */
	public H2Url databaseToUpper(boolean value) {
		
		this.addParam("DATABASE_TO_UPPER", value);
		
		return this;
	}
	
	/**
	 * DB_CLOSE_DELAY
	 * 
	 * @param value value
	 * @return {@link H2Url}
	 */
	public H2Url dbCloseDelay(int value) {
		
		this.addParam("DB_CLOSE_DELAY", value);
		
		return this;
	}
	
	/**
	 * IGNORECASE
	 * 
	 * @param value value
	 * @return {@link H2Url}
	 */
	public H2Url ignoreCase(boolean value) {
		
		this.addParam("IGNORECASE", value);
		
		return this;
	}
	
	/**
	 * LOCK_TIMEOUT
	 * 
	 * @param value value
	 * @return {@link H2Url}
	 */
	public H2Url lockTimeout(int value) {
		
		this.addParam("LOCK_TIMEOUT", value);
		
		return this;
	}
	
	/**
	 * MODE
	 * 
	 * @param value {@link Mode}
	 * @return {@link H2Url}
	 */
	public H2Url mode(@NonNull Mode value) {
		
		this.addParam("MODE", value.name());
		
		return this;
	}
	
	/**
	 * MVCC
	 * 
	 * @param value value
	 * @return {@link H2Url}
	 */
	public H2Url mvcc(boolean value) {
		
		this.addParam("MVCC", value);
		
		return this;
	}
	
	/**
	 * TRACE_LEVEL_FILE
	 * 
	 * @param value value
	 * @return {@link H2Url}
	 */
	public H2Url traceLevelFile(int value) {
		
		this.addParam("TRACE_LEVEL_FILE", value);
		
		return this;
	}
	
	/**
	 * TRACE_LEVEL_SYSTEM_OUT
	 * 
	 * @param value value
	 * @return {@link H2Url}
	 */
	public H2Url traceLevelSystemOut(int value) {
		
		this.addParam("TRACE_LEVEL_SYSTEM_OUT", value);
		
		return this;
	}
	
	/**
	 * Compatibility mode
	 */
	public enum Mode {
		
		/**
		 * DB2
		 */
		DB2,
		
		/**
		 * Apache Derby
		 */
		Derby,
		
		/**
		 * HSQLDB
		 */
		HSQLDB,
		
		/**
		 * Microsoft SQL Server
		 */
		MSSQLServer,
		
		/**
		 * MySQL
		 */
		MySQL,
		
		/**
		 * Oracle Database
		 */
		Oracle,
		
		/**
		 * PostgreSQL
		 */
		PostgreSQL;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy