Changeset 6976
- Timestamp:
- Oct 8, 2015, 8:20:56 AM (7 years ago)
- Location:
- branches/3.6-stable
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.6-stable/config/dist/mysql-queries.xml
r6330 r6976 28 28 --> 29 29 <predefined-queries> 30 <query id="DROP_NOT_NULL_CONSTRAINT" type="SQL"> 31 <sql> 32 ALTER TABLE [{1}] MODIFY [{2}] {3} NULL 33 </sql> 34 <description> 35 An SQL query that drops a NOT NULL contraint from column (2) with data type (3) 36 in a table (1). 37 </description> 38 </query> 30 39 31 40 </predefined-queries> -
branches/3.6-stable/src/core/net/sf/basedb/core/Update.java
r6941 r6976 1337 1337 1338 1338 // Drop NOT NULL on Annotations.value_id 1339 dropNotNullConstraint(session, "Annotations", "value_id" );1339 dropNotNullConstraint(session, "Annotations", "value_id", "int"); 1340 1340 1341 1341 // Drop UNIQUE constraint on Annotations.annotationset_id/annotationtype_id … … 1657 1657 TableInfo info = getTableInfo(session, tableName); 1658 1658 String indexName = info.findIndexName(null, new HashSet<String>(Arrays.asList(columnNames))); 1659 1659 1660 if (indexName != null) 1660 1661 { 1661 1662 DbEngine engine = HibernateUtil.getDbEngine(); 1663 1664 // Drop foreign keys using any of the column names in the index 1665 List<ForeignKeyInfo> dropped = new ArrayList<ForeignKeyInfo>(); 1666 if (engine.dropForeignKeysUsedInIndex()) 1667 { 1668 for (ForeignKeyInfo fk : info.getForeignKeys()) 1669 { 1670 for (String colName : columnNames) 1671 { 1672 if (fk.getFkColumns().contains(colName)) 1673 { 1674 dropped.add(fk); 1675 String fkSql = engine.getDropForeignKeySql(null, null, tableName, fk.getName()); 1676 query = HibernateUtil.createSqlQuery(session, fkSql); 1677 query.executeUpdate(); 1678 break; 1679 } 1680 } 1681 } 1682 } 1683 1662 1684 String sql = engine.getDropIndexSql(null, null, tableName, indexName, unique); 1663 1685 query = HibernateUtil.createSqlQuery(session, sql); 1664 1686 query.executeUpdate(); 1687 1688 // Re-created dropped foreign keys 1689 for (ForeignKeyInfo fk : dropped) 1690 { 1691 String fkSql = engine.getCreateForeignKeySql(null, null, tableName, fk.getName(), fk.getFkColumns(), fk.getRefName(), fk.getRefColumns()); 1692 query = HibernateUtil.createSqlQuery(session, fkSql); 1693 query.executeUpdate(); 1694 } 1695 1665 1696 } 1666 1697 // Only commit if we started a new transaction … … 1696 1727 } 1697 1728 1698 private static void dropNotNullConstraint(org.hibernate.Session session, String tableName, String columnName )1729 private static void dropNotNullConstraint(org.hibernate.Session session, String tableName, String columnName, String mySqlDataType) 1699 1730 { 1700 1731 org.hibernate.Transaction tx = null; … … 1705 1736 tx = session.getTransaction().isActive() ? null : HibernateUtil.newTransaction(session); 1706 1737 1707 query = HibernateUtil.getPredefinedSQLQuery(session, "DROP_NOT_NULL_CONSTRAINT", tableName, columnName );1738 query = HibernateUtil.getPredefinedSQLQuery(session, "DROP_NOT_NULL_CONSTRAINT", tableName, columnName, mySqlDataType); 1708 1739 query.executeUpdate(); 1709 1740 -
branches/3.6-stable/src/core/net/sf/basedb/core/dbengine/AbstractDbEngine.java
r6721 r6976 75 75 } 76 76 77 77 /** 78 @return FALSE 79 @since 3.6 80 */ 81 @Override 82 public boolean dropForeignKeysUsedInIndex() 83 { 84 return false; 85 } 86 78 87 /** 79 88 Return the SQL unmodified. -
branches/3.6-stable/src/core/net/sf/basedb/core/dbengine/DbEngine.java
r6880 r6976 123 123 */ 124 124 public String getDropIndexSql(String catalog, String schema, String table, String name, boolean unique); 125 126 /** 127 When dropping an index, must foreign keys that uses the same columns also be 128 dropped (before dropping the index)? Default is FALSE, but MySQL need TRUE. 129 @since 3.6 130 */ 131 public boolean dropForeignKeysUsedInIndex(); 125 132 126 133 /** -
branches/3.6-stable/src/core/net/sf/basedb/core/dbengine/MySQLEngine.java
r6684 r6976 114 114 sql.append(")"); 115 115 return sql.toString(); 116 } 117 118 /** 119 @return TRUE 120 @since 3.6 121 */ 122 @Override 123 public boolean dropForeignKeysUsedInIndex() 124 { 125 return true; 116 126 } 117 127
Note: See TracChangeset
for help on using the changeset viewer.