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

net.moznion.mysql.diff.MySqlConnectionInfo Maven / Gradle / Ivy

Go to download

Detect and extract diff between two table declarations from schema of MySQL

There is a newer version: 1.1.0
Show newest version
package net.moznion.mysql.diff;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Representation of connection information for MySQL.
 * 
 * @author moznion
 *
 */
@Getter
public class MySqlConnectionInfo {
  private final String host;
  private final String user;
  private final String pass;
  private final String jdbcUrl;

  /**
   * Builder class of MySqlConnectionInfo.
   * 
   * 

* This class provides following setters; *

*
    *
  • host(String hostName) // default value: "localhost"
  • *
  • port(int portNumber) // default value: 3306
  • *
  • user(String userName) // default value: "root"
  • *
  • host(String password) // default value: ""
  • *
*/ @Accessors(fluent = true) public static class Builder { @Setter private String host = "localhost"; @Setter private int port = 3306; @Setter private String user = "root"; @Setter private String pass = ""; private List properties = new ArrayList<>(Arrays.asList("allowMultiQueries=true")); /** * Add a property. * * @param property */ public void addProperty(String property) { properties.add(property); } /** * Add properties. * * @param properties */ public void addProperties(List properties) { this.properties.addAll(properties); } /** * Set host name, port number and options by URL of a remote MySQL. * * @param url URL of a remote MySQL (e.g. * jdbc:mysql://localhost:8888/something_table?cacheServerConfiguration=true) * @throws URISyntaxException */ public Builder url(String url) throws URISyntaxException { MySqlConnectionUri connectionUri = new MySqlConnectionUri(url); host = connectionUri.getHost(); port = connectionUri.getPort(); addProperties(connectionUri.getQueries()); return this; } /** * Builds MySqlConnectionInfo. * * @return New MySqlConnectionInfo instance. */ public MySqlConnectionInfo build() { return new MySqlConnectionInfo(this); } } /** * Dispenses a new builder of MySqlConnectionInfo. * * @return Builder of MySqlConnectionInfo. */ public static Builder builder() { return new Builder(); } private MySqlConnectionInfo(Builder builder) { host = builder.host; user = builder.user; pass = builder.pass; jdbcUrl = new StringBuilder() .append("jdbc:mysql://") .append(builder.host) .append(":") .append(builder.port) .append("?") .append(String.join("&", builder.properties)) .toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy