Skip to content

Commit

Permalink
Add JavaDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Jul 22, 2015
1 parent 1ff223e commit 0561c44
Show file tree
Hide file tree
Showing 15 changed files with 422 additions and 120 deletions.
141 changes: 141 additions & 0 deletions src/main/java/com/speedment/core/config/model/parameters/DbmsType.java
Expand Up @@ -16,46 +16,187 @@
*/
package com.speedment.core.config.model.parameters;

import com.speedment.core.config.model.Dbms;
import com.speedment.core.db.DbmsHandler;
import java.util.Optional;
import java.util.Set;

/**
* The {@code DbmsType} interface defines unique properties for different Dbms
* types. By implementing a new {@code DbmsType} and perhaps a new
* {@code DbmsHandler}, one may easily implement support for new Dbms vendor
* types.
*
* @author pemi
* @since 2.0
*/
public interface DbmsType {

/**
* Returns the non-null name for this {@code DbmsType}. For example MySQL or
* Oracle
*
* @return the non-null name for this {@code DbmsType}
*/
String getName();

/**
* Returns the non-null Driver Manager Name for this {@code DbmsType}. For
* example "MySQL-AB JDBC Driver" or "Oracle JDBC Driver"
*
* @return the non-null Driver Manager Name
*/
String getDriverManagerName();

/**
* Returns the default port for this {@code DbmsType}. For example 3306
* (MySQL) or 1521 (Oracle)
*
* @return the default port
*/
int getDefaultPort();

/**
* Returns the delimiter used between a Schema and a Table for this
* {@code DbmsType}. Most {@code DbmsType} are using a "." as a separator.
*
* @return the delimiter used between a Schema and a Table
*/
String getSchemaTableDelimiter();

/**
* Returns a textual representation of what the database name is used for.
* Some databases (notably MySQL) does not use the database name for
* anything whereas other (such as Oracle) are using the name as an address
* (i.e. for Oracle the name is used as SID)
*
* @return a textual representation of what the database name is used for
*/
String getDbmsNameMeaning();

/**
* Returns if this {@code DbmsType} is supported by Speedment in the current
* implementation.
*
* @return if this {@code DbmsType} is supported by Speedment in the current
* implementation
*/
boolean isSupported();

// Implementation specifics
/**
* Returns the non-null fully qualified JDBC class name for this
* {@code DbmsType}. For example "com.mysql.jdbc.Driver" or
* "oracle.jdbc.OracleDriver"
*
* @return the non-null name for this {@code DbmsType}
*/
String getDriverName();

/**
* Returns a non-null String representation of the default connector
* parameters to be used by this {@code DbmsType}. The connector parameters
* can be used to select different modes or to set parameters for the JDBC
* connection.
*
* @return a non-null String representation of the default connector
* parameters
*/
Optional<String> getDefaultConnectorParameters();

/**
* Returns the non-null JDBC connector name to be used by this
* {@code DbmsType}. The connector name is the name that is to be placed in
* the beginning of the JDBC connector string
* "jdbc:{jdbcConnectorName}://some_host". For example "mysql" or
* "oracle:thin".
*
* @return a non-null String representation of the default connector
* parameters
*/
String getJdbcConnectorName();

/**
* Returns the non-null field encloser start string. The field encloser
* start string precedes a database entity name like a table or schema name
* when quoted. Quoted names are used to avoid that entity names collide
* with reserved keywords like "key" or "user". So a table named "user" in
* the "key" schema can be quoted to "key"."user". Examples of values are
* '`' for MySQL or '"' for Oracle.
*
* @return the non-null field encloser start string
*
* @see #getFieldEncloserStart(boolean)
* @see #getFieldEncloserEnd()
* @see #getFieldEncloserEnd(boolean)
*/
default String getFieldEncloserStart() {
return getFieldEncloserStart(false);
}

/**
* Returns the non-null field encloser end string. The field encloser end
* string follows a database entity name like a table or schema name when
* quoted. Quoted names are used to avoid that entity names collide with
* reserved keywords like "key" or "user". So a table named "user" in the
* "key" schema can be quoted to "key"."user". Examples of values are '`'
* for MySQL or '"' for Oracle.
*
* @return the non-null field encloser end string
*
* @see #getFieldEncloserStart(boolean)
* @see #getFieldEncloserEnd()
* @see #getFieldEncloserEnd(boolean)
*/
default String getFieldEncloserEnd() {
return getFieldEncloserEnd(false);
}

/**
* Returns the non-null field encloser start string. The method parameter
* denotes if the field encloser is placed within quotes or not. For example
* for Oracle, since the field encloser is the '"' character itself, it
* needs to be escaped if within quotes.
*
* @param isWithinQuotes if the field encloser is within quotes
* @return Returns the non-null field encloser start string
*
* @see #getFieldEncloserStart()
*/
String getFieldEncloserStart(final boolean isWithinQuotes);

/**
* Returns the non-null field encloser end string. The method parameter
* denotes if the field encloser is placed within quotes or not. For example
* for Oracle, since the field encloser is the '"' character itself, it
* needs to be escaped if within quotes.
*
* @param isWithinQuotes if the field encloser is within quotes
* @return Returns the non-null field encloser start string
*
* @see #getFieldEncloserEnd()
*/
String getFieldEncloserEnd(final boolean isWithinQuotes);

/**
* Returns a non-null Set of Strings that represents schema names that are
* to be excluded when examining a Dbms for schemas. The set typically
* contains names for system tables and similar things. For example for
* MySQL, the schemas "MySQL" and "information_schema" are typically
* excluded.
*
* @return a non-null Set of Strings that represents schema names that are
* to be excluded when examining a Dbms for schemas
*/
Set<String> getSchemaExcludSet();

/**
* Creates and returns a new {@code DbmsHandler} instance for the given
* database.
*
* @param dbms the Dbms configuration to use
* @return a new {@code DbmsHandler} instance for the given database
*/
DbmsHandler makeDbmsHandler(Dbms dbms);

}
Expand Up @@ -18,12 +18,17 @@

import com.speedment.core.annotations.Api;
import com.speedment.core.config.model.ConfigEntity;
import com.speedment.core.config.model.Dbms;
import com.speedment.core.db.DbmsHandler;
import com.speedment.core.db.impl.vendor.MySqlDbmsHandler;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Stream;

/**
Expand All @@ -34,30 +39,32 @@
public enum StandardDbmsType implements EnumHelper<StandardDbmsType>, DbmsType {

MYSQL(
"MySQL",
"MySQL-AB JDBC Driver",
3306,
".",
"Just a name",
"com.mysql.jdbc.Driver",
"useUnicode=true&characterEncoding=UTF-8&useServerPrepStmts=true&useCursorFetch=true&zeroDateTimeBehavior=convertToNull",
"mysql",
"`",
"`",
Collections.unmodifiableSet(new HashSet<>(Arrays.asList("MySQL", "information_schema")))
"MySQL",
"MySQL-AB JDBC Driver",
3306,
".",
"Just a name",
"com.mysql.jdbc.Driver",
"useUnicode=true&characterEncoding=UTF-8&useServerPrepStmts=true&useCursorFetch=true&zeroDateTimeBehavior=convertToNull",
"mysql",
"`",
"`",
Collections.unmodifiableSet(new HashSet<>(Arrays.asList("MySQL", "information_schema"))),
d -> new MySqlDbmsHandler(d)
),
MARIADB(
"MariaDB",
"MariaDB JDBC Driver",
3305,
".",
"Just a name",
"com.mysql.jdbc.Driver",
"useUnicode=true&characterEncoding=UTF-8&useServerPrepStmts=true&useCursorFetch=true&zeroDateTimeBehavior=convertToNull",
"mariadb",
"`",
"`",
Collections.unmodifiableSet(new HashSet<>(Arrays.asList("MySQL", "information_schema")))
"MariaDB",
"MariaDB JDBC Driver",
3305,
".",
"Just a name",
"com.mysql.jdbc.Driver",
"useUnicode=true&characterEncoding=UTF-8&useServerPrepStmts=true&useCursorFetch=true&zeroDateTimeBehavior=convertToNull",
"mariadb",
"`",
"`",
Collections.unmodifiableSet(new HashSet<>(Arrays.asList("MySQL", "information_schema"))),
d -> new MySqlDbmsHandler(d)
);
//
// ORACLE("Oracle", "Oracle JDBC Driver", 1521, ".", "SID"),
Expand All @@ -70,29 +77,31 @@ public enum StandardDbmsType implements EnumHelper<StandardDbmsType>, DbmsType {
private static final Map<String, StandardDbmsType> NAME_MAP = EnumHelper.Hidden.buildMap(values());

private StandardDbmsType(
final String name,
final String driverManagerName,
final int defaultPort,
final String schemaTableDelimiter,
final String nameMeaning,
final String driverName,
final String defaultConnectionParameters,
final String jdbcConnectorName,
final String fieldEncloserStart,
final String fieldEncloserEnd,
final Set<String> schemaExcludSet
final String name,
final String driverManagerName,
final int defaultPort,
final String schemaTableDelimiter,
final String nameMeaning,
final String driverName,
final String defaultConnectionParameters,
final String jdbcConnectorName,
final String fieldEncloserStart,
final String fieldEncloserEnd,
final Set<String> schemaExcludSet,
final Function<Dbms, DbmsHandler> dbmsMapper
) {
this.name = name;
this.driverManagerName = driverManagerName;
this.name = Objects.requireNonNull(name);
this.driverManagerName = Objects.requireNonNull(driverManagerName);
this.defaultPort = defaultPort;
this.schemaTableDelimiter = schemaTableDelimiter;
this.nameMeaning = nameMeaning;
this.driverName = driverName;
this.defaultConnectionParameters = defaultConnectionParameters;
this.jdbcConnectorName = jdbcConnectorName;
this.fieldEncloserStart = fieldEncloserStart;
this.fieldEncloserEnd = fieldEncloserEnd;
this.schemaExcludSet = schemaExcludSet;
this.schemaTableDelimiter = Objects.requireNonNull(schemaTableDelimiter);
this.nameMeaning = Objects.requireNonNull(nameMeaning);
this.driverName = Objects.requireNonNull(driverName);
this.defaultConnectionParameters = Objects.requireNonNull(defaultConnectionParameters);
this.jdbcConnectorName = Objects.requireNonNull(jdbcConnectorName);
this.fieldEncloserStart = Objects.requireNonNull(fieldEncloserStart);
this.fieldEncloserEnd = Objects.requireNonNull(fieldEncloserEnd);
this.schemaExcludSet = Objects.requireNonNull(schemaExcludSet);
this.dbmsMapper = Objects.requireNonNull(dbmsMapper);
}
private final String name;
private final String driverManagerName;
Expand All @@ -105,6 +114,7 @@ private StandardDbmsType(
private final String fieldEncloserStart;
private final String fieldEncloserEnd;
private final Set<String> schemaExcludSet;
private final Function<Dbms, DbmsHandler> dbmsMapper;

@Override
public String getName() {
Expand Down Expand Up @@ -179,9 +189,14 @@ public static StandardDbmsType defaultFor(final ConfigEntity entity) {
public static Stream<StandardDbmsType> stream() {
return Stream.of(values());
}

@Override
public Set<String> getSchemaExcludSet() {
return schemaExcludSet;
}

@Override
public DbmsHandler makeDbmsHandler(Dbms dbms) {
return dbmsMapper.apply(dbms);
}
}

0 comments on commit 0561c44

Please sign in to comment.