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

br.com.objectos.db.Vendor Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2014 Objectos, Fábrica de Software LTDA.
 *
 * 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 br.com.objectos.db;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import com.zaxxer.hikari.HikariConfig;

/**
 * @author [email protected] (Marcio Endo)
 */
public abstract class Vendor {

  protected Vendor() {
  }

  public void loadDriverClass() throws ClassNotFoundException {
    Class.forName(driverClassName());
  }

  public final String url(String server, int port) {
    return String.format(urlFormat(), server, port);
  }

  public final String url(String server, int port, Map parameters) {
    StringBuilder res = new StringBuilder(url(server, port));

    Iterator> entries = parameters.entrySet().iterator();
    if (entries.hasNext()) {
      res.append('?');
      Entry entry = entries.next();
      res.append(entry.getKey()).append('=').append(entry.getValue());
      while (entries.hasNext()) {
        entry = entries.next();
        res.append('&').append(entry.getKey()).append('=').append(entry.getValue());
      }
    }

    return res.toString();
  }

  protected String catalogName(String dbName) {
    return null;
  }

  protected abstract void configure(DatabaseConfig config, HikariConfig hk);

  protected abstract String driverClassName();

  protected String schemaName(String dbName) {
    return null;
  }

  protected abstract String urlFormat();

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy