Skip to content

Commit

Permalink
Create DatabaseNamingConvention. Fix #139
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Forslund committed Mar 1, 2016
1 parent 4e5e916 commit 43d1499
Show file tree
Hide file tree
Showing 14 changed files with 989 additions and 756 deletions.
78 changes: 6 additions & 72 deletions src/main/java/com/speedment/config/db/parameters/DbmsType.java
Expand Up @@ -20,6 +20,7 @@
import com.speedment.annotation.Api; import com.speedment.annotation.Api;
import com.speedment.config.db.Dbms; import com.speedment.config.db.Dbms;
import com.speedment.db.ConnectionUrlGenerator; import com.speedment.db.ConnectionUrlGenerator;
import com.speedment.db.DatabaseNamingConvention;
import com.speedment.db.DbmsHandler; import com.speedment.db.DbmsHandler;
import com.speedment.internal.core.config.dbms.DbmsTypeImpl; import com.speedment.internal.core.config.dbms.DbmsTypeImpl;
import com.speedment.internal.core.manager.sql.SpeedmentPredicateView; import com.speedment.internal.core.manager.sql.SpeedmentPredicateView;
Expand Down Expand Up @@ -112,80 +113,13 @@ public interface DbmsType {
* @return the non-null name for this {@code DbmsType} * @return the non-null name for this {@code DbmsType}
*/ */
String getDriverName(); String getDriverName();


/**
* 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 * Returns the naming convention used by this database.
* to be excluded when examining a Dbms for schemas. The set typically *
* contains names for system tables and similar things. For example for * @return the naming convention
* 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> getSchemaExcludeSet(); DatabaseNamingConvention getDatabaseNamingConvention();


/** /**
* Creates and returns a new {@code DbmsHandler} instance for the given * Creates and returns a new {@code DbmsHandler} instance for the given
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/com/speedment/db/DatabaseNamingConvention.java
@@ -0,0 +1,83 @@
/*
* Copyright 2016 Speedment, Inc..
*
* 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 com.speedment.db;

import com.speedment.annotation.Api;
import com.speedment.config.db.Column;
import com.speedment.config.db.Table;
import java.util.Set;

/**
* Regulates how the full name of a database entity is constructed.
*
* @author Emil Forslund
* @since 2.3
*/
@Api(version="2.3")
public interface DatabaseNamingConvention {

/**
* Returns the full name used in the database for the specified
* {@link Column}. This is typically constructed by combining the table and
* the column name with a separator, but that might be different in
* different implementations.
*
* @param column the column to retreive the name of
* @return the full name
*/
String fullNameOf(Column column);

/**
* Returns the full name used in the database for the specified
* {@link Table}. This is typically constructed by combining the schema and
* the table name with a separator, but that might be different in
* different implementations.
*
* @param table the table to retreive the name of
* @return the full name
*/
String fullNameOf(Table table);

/**
* Quotes the specified value field in accordance to this database naming
* convention. This is typically used around values.
*
* @param field the content to quote
* @return the quoted content
*/
String quoteField(String field);

/**
* Encloses the specified database name field in accordance to this database
* namingconvention. This is typically used around column or table names.
*
* @param field the content to quote
* @return the quoted content
*/
String encloseField(String field);

/**
* 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> getSchemaExcludeSet();
}

0 comments on commit 43d1499

Please sign in to comment.