| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DatabasePlatform |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Copyright 2005-2009 The Kuali Foundation | |
| 3 | * | |
| 4 | * | |
| 5 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 6 | * you may not use this file except in compliance with the License. | |
| 7 | * You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.opensource.org/licenses/ecl2.php | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | package org.kuali.rice.core.database.platform; | |
| 18 | ||
| 19 | import javax.persistence.EntityManager; | |
| 20 | ||
| 21 | import org.apache.ojb.broker.PersistenceBroker; | |
| 22 | import org.apache.ojb.broker.query.Criteria; | |
| 23 | ||
| 24 | /** | |
| 25 | * Interface that abstracts database dependent sql from core | |
| 26 | * | |
| 27 | * TODO Had to move this down into embedded source because of the OJB dependencies. This probably will | |
| 28 | * go away once we get rid of the embedded plugin. | |
| 29 | * | |
| 30 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 31 | */ | |
| 32 | public interface DatabasePlatform { | |
| 33 | public String getCurTimeFunction(); | |
| 34 | public String getStrToDateFunction(); | |
| 35 | public String getDateFormatString(String dateFormatString); | |
| 36 | ||
| 37 | /** | |
| 38 | * Returns the name of a function for shifting a string to uppercase on | |
| 39 | * the relevant platform. | |
| 40 | * @return the name of a function as a String | |
| 41 | */ | |
| 42 | String getUpperCaseFunction(); | |
| 43 | ||
| 44 | /** | |
| 45 | * Supplies a parameterized sequence incrementation query | |
| 46 | * @param sequenceName name of the sequence to be incremented | |
| 47 | * @return parameterized sequence incrementation query | |
| 48 | */ | |
| 49 | Long getNextValSQL(String sequenceName, PersistenceBroker persistenceBroker); | |
| 50 | Long getNextValSQL(String sequenceName, EntityManager entityManager); | |
| 51 | ||
| 52 | /** | |
| 53 | * Generates the query used to select route header rows for update | |
| 54 | * @param routeHeaderId id of the routeHeader to select for update | |
| 55 | * @param wait whether to block until lock is released | |
| 56 | * @return the query used to select route header rows for update | |
| 57 | */ | |
| 58 | ||
| 59 | String getLockRouteHeaderQuerySQL(Long routeHeaderId, boolean wait); | |
| 60 | /** | |
| 61 | * Supplies the sql for a given date string that will satisfy a where clause | |
| 62 | * @param date in YYYY/MM/DD format | |
| 63 | * @param time in hh:mm:ss format | |
| 64 | * @return the sql for a given date string that will satisfy a where clause | |
| 65 | * @see SqlUtil#establishDateString(String, String, String, StringBuffer, DatabasePlatform) | |
| 66 | * @see SqlUtil#formatDate(String) | |
| 67 | * TODO: refactor to use a parsed Date object or milliseconds instead of date String | |
| 68 | */ | |
| 69 | String getDateSQL(String date, String time); | |
| 70 | ||
| 71 | /** | |
| 72 | * Returns the suffix to append to a SQL query in order to perform | |
| 73 | * a "select for update" lock on the table | |
| 74 | * | |
| 75 | * @param waitMillis the milliseconds to wait, -1 forever, 0 if no wait | |
| 76 | * @return the suffix to append to a SQL query in order to perform a "select for update" lock on the table | |
| 77 | */ | |
| 78 | String getSelectForUpdateSuffix(long waitMillis); | |
| 79 | ||
| 80 | /** | |
| 81 | * @param tableToCreate the String name for the table to be created | |
| 82 | * @param fromTable the String name of the original table | |
| 83 | * @return the SQL string for creating the specified table from the second | |
| 84 | * specified table | |
| 85 | */ | |
| 86 | String getCreateTableFromTableSql(String tableToCreate, String fromTable); | |
| 87 | ||
| 88 | /** | |
| 89 | * @param tableName the name of the table to be truncated | |
| 90 | * @return a String of SQL for truncating a table | |
| 91 | * @see <a href="http://en.wikipedia.org/wiki/Truncate_(SQL)">Truncate (SQL)</a> | |
| 92 | */ | |
| 93 | String getTruncateTableSql(String tableName); | |
| 94 | ||
| 95 | /** | |
| 96 | * @param receivingTable the name of the table receiving inserted data | |
| 97 | * @param fromTable the name of the originating table | |
| 98 | * @return an "INSERT INTO" SQL command | |
| 99 | */ | |
| 100 | String getInsertDataFromTableSql(String restoreTableName, String fromTableName); | |
| 101 | ||
| 102 | /** | |
| 103 | * @param tableName the table to drop | |
| 104 | * @return an SQL command for dropping the specified table | |
| 105 | */ | |
| 106 | String getDropTableSql(String tableName); | |
| 107 | ||
| 108 | /** | |
| 109 | * Returns a SQL expression that acts like nvl(exprToTest, exprToReplaceIfTestExprNull) on oracle. That is, | |
| 110 | * an expression that will return exprToTest does not evaluate to null, and will return exprToReplaceIfTestExprNull | |
| 111 | * if exprToTest does evaluate to null. NOTE: this method does not provide any protection against SQL injection | |
| 112 | * attacks, nor does it validate any of the parameters. | |
| 113 | * | |
| 114 | * @param exprToTest a SQL expression that will either evaluate to null or non-null | |
| 115 | * @param exprToReplaceIfTestExprNull the value to return if | |
| 116 | * @return a SQL expression that acts like nvl on oracle or ifnull() on MySQL | |
| 117 | */ | |
| 118 | String getIsNullFunction(String exprToTest, String exprToReplaceIfTestExprNull); | |
| 119 | ||
| 120 | /** | |
| 121 | * Escapes any special DB-specific characters from an input String, to help prevent SQL injection attacks. | |
| 122 | * TODO: This method should be replaced by the "prepared statement" functionality in the future. | |
| 123 | * | |
| 124 | * @param sqlString The String to escape. | |
| 125 | * @return The String from sqlString, but with all of its DB-specific special characters escaped. | |
| 126 | */ | |
| 127 | String escapeString(String sqlString); | |
| 128 | ||
| 129 | // Methods Imported from KualiDBPlatform | |
| 130 | ||
| 131 | /* | |
| 132 | * MySQL impl of this method copied to org.kuali.rice.core.database.platform.MySQLDatabasePlatform | |
| 133 | * No other impl exists in this legacy package (Derby impl returned null) | |
| 134 | */ | |
| 135 | public void applyLimit(Integer limit, Criteria criteria); | |
| 136 | } |