-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from alfasoftware/fix/deprecate-oraclecustomh…
…int-and-postgresqlcustomhint Fix/deprecate oraclecustomhint and postgresqlcustomhint
- Loading branch information
Showing
13 changed files
with
256 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
morf-core/src/main/java/org/alfasoftware/morf/sql/DialectSpecificHint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.alfasoftware.morf.sql; | ||
|
||
import java.util.Objects; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** | ||
* A generic {@link org.alfasoftware.morf.sql.Hint} class that holds custom hints for a given database type. | ||
* It should be used instead of {@link org.alfasoftware.morf.sql.CustomHint} | ||
* | ||
*/ | ||
public class DialectSpecificHint implements Hint { | ||
|
||
private final String databaseType; | ||
|
||
private final String hintContents; | ||
|
||
/** | ||
* | ||
* @param databaseType a database type identifier. Eg: ORACLE, PGSQL, SQL_SERVER | ||
* @param hintContents the hint contents themselves, without the delimiters. Eg: without /*+ and *"/ * for Oracle hints | ||
*/ | ||
public DialectSpecificHint(String databaseType, String hintContents) { | ||
super(); | ||
|
||
if (StringUtils.isBlank(databaseType)) { | ||
throw new IllegalArgumentException("databaseType cannot be blank"); | ||
} | ||
|
||
if (StringUtils.isBlank(hintContents)) { | ||
throw new IllegalArgumentException("hintContents cannot be blank"); | ||
} | ||
|
||
this.databaseType = databaseType; | ||
this.hintContents = hintContents; | ||
} | ||
|
||
|
||
public String getDatabaseType() { | ||
return databaseType; | ||
} | ||
|
||
|
||
public String getHintContents() { | ||
return hintContents; | ||
} | ||
|
||
|
||
/** | ||
* Tests whether the supplied databaseType string is equal to the databaseType that is held by this class. | ||
* The test is performed using {@link java.lang.String#equals(Object)}. | ||
* | ||
* @param databaseType a database type identifier. Eg: ORACLE, PGSQL, SQL_SERVER | ||
* @return true if the databaseType parameter is equal to this databaseType, false otherwise | ||
*/ | ||
public boolean isSameDatabaseType(String databaseType) { | ||
return this.databaseType.equals(databaseType); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(databaseType, hintContents); | ||
} | ||
|
||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null) return false; | ||
if (getClass() != obj.getClass()) return false; | ||
DialectSpecificHint other = (DialectSpecificHint) obj; | ||
return Objects.equals(databaseType, other.databaseType) && Objects.equals(hintContents, other.hintContents); | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return "DialectSpecificHint [databaseType=" + databaseType + ", hintContents=" + hintContents + "]"; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
morf-core/src/test/java/org/alfasoftware/morf/sql/TestDialectSpecificHint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.alfasoftware.morf.sql; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import org.junit.Test; | ||
|
||
public class TestDialectSpecificHint { | ||
|
||
/** | ||
* We should not be able to create a DialectSpecificHint object with blank parameters | ||
*/ | ||
@Test(expected = IllegalArgumentException.class) | ||
public void testConstructorWithFirstParameterEmptyThrowsException() { | ||
new DialectSpecificHint("", "not_empty"); | ||
fail("Did not catch IllegalArgumentException"); | ||
} | ||
|
||
|
||
/** | ||
* We should not be able to create a DialectSpecificHint object with blank parameters | ||
*/ | ||
@Test(expected = IllegalArgumentException.class) | ||
public void testConstructorWithSecondParameterEmptyThrowsException() { | ||
new DialectSpecificHint("not_empty", ""); | ||
fail("Did not catch IllegalArgumentException"); | ||
} | ||
|
||
@Test | ||
public void testIsSameDatabaseType() { | ||
DialectSpecificHint dialectSpecificHint = new DialectSpecificHint("SOME_DATABASE_TYPE", "SOME_HINT"); | ||
assertTrue(dialectSpecificHint.isSameDatabaseType("SOME_DATABASE_TYPE")); | ||
assertFalse(dialectSpecificHint.isSameDatabaseType("DIFFERENT_DATABASE_TYPE")); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.