IDEMPIERE-1901 Deprecate parent composite primary keys - leave management via table index

This commit is contained in:
Carlos Ruiz 2014-09-05 16:18:09 -05:00
parent 275ba19683
commit ea232497ef
7 changed files with 180 additions and 7 deletions

View File

@ -0,0 +1,47 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Sep 5, 2014 3:42:25 PM COT
-- IDEMPIERE-1901 Deprecate parent composite primary keys - leave management via table index
INSERT INTO AD_Column (SeqNoSelection,IsSyncDatabase,Version,AD_Column_ID,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsParent,FieldLength,IsSelectionColumn,IsKey,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsUpdateable,ColumnName,Description,DefaultValue,Help,Name,IsAllowCopy,Updated,CreatedBy,IsActive,Created,UpdatedBy,IsToolbarButton,IsAlwaysUpdateable,IsEncrypted,IsSecure,AD_Element_ID,AD_Reference_ID,AD_Table_ID,AD_Client_ID,AD_Org_ID,EntityType) VALUES (0,'N',0,211762,'Y','N','N',0,'N',1,'N','N','N','Y','f1e7a14f-8ab9-4b2e-9655-95d728ecdc18','Y','IsKey','This column is the key in this table','N','The key column must also be display sequence 0 in the field definition and may be hidden.','Key column','Y',TO_DATE('2014-09-05 15:42:25','YYYY-MM-DD HH24:MI:SS'),100,'Y',TO_DATE('2014-09-05 15:42:25','YYYY-MM-DD HH24:MI:SS'),100,'N','N','N','N',389,20,200085,0,0,'D')
;
-- Sep 5, 2014 3:42:31 PM COT
ALTER TABLE AD_TableIndex ADD IsKey CHAR(1) DEFAULT 'N' CHECK (IsKey IN ('Y','N')) NOT NULL
;
-- Sep 5, 2014 3:42:57 PM COT
INSERT INTO AD_Field (IsEncrypted,AD_Tab_ID,DisplayLength,IsSameLine,IsHeading,SeqNo,IsCentrallyMaintained,AD_Field_ID,IsReadOnly,Help,Description,Name,AD_Field_UU,IsDisplayed,IsFieldOnly,UpdatedBy,CreatedBy,Updated,IsActive,IsDisplayedGrid,SeqNoGrid,XPosition,AD_Client_ID,ColumnSpan,AD_Column_ID,EntityType,AD_Org_ID,Created) VALUES ('N',200096,1,'N','N',140,'Y',203443,'N','The key column must also be display sequence 0 in the field definition and may be hidden.','This column is the key in this table','Key column','606cdea6-8002-4c89-b507-bdeffd5acb2b','Y','N',100,100,TO_DATE('2014-09-05 15:42:57','YYYY-MM-DD HH24:MI:SS'),'Y','Y',110,2,0,2,211762,'D',0,TO_DATE('2014-09-05 15:42:57','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=90, ColumnSpan=1,Updated=TO_DATE('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202209
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=100, IsDisplayed='Y', XPosition=3, ColumnSpan=1,Updated=TO_DATE('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=203443
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=110,Updated=TO_DATE('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202250
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=120,Updated=TO_DATE('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202206
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=130,Updated=TO_DATE('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202210
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=140,Updated=TO_DATE('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202535
;
-- Sep 5, 2014 3:44:41 PM COT
UPDATE AD_Field SET DisplayLogic='@IsCreateConstraint@=''Y'' & @IsUnique@=''Y''',Updated=TO_DATE('2014-09-05 15:44:41','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=203443
;
SELECT register_migration_script('201409051545_IDEMPIERE-1901.sql') FROM dual
;

View File

@ -0,0 +1,44 @@
-- Sep 5, 2014 3:42:25 PM COT
-- IDEMPIERE-1901 Deprecate parent composite primary keys - leave management via table index
INSERT INTO AD_Column (SeqNoSelection,IsSyncDatabase,Version,AD_Column_ID,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsParent,FieldLength,IsSelectionColumn,IsKey,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsUpdateable,ColumnName,Description,DefaultValue,Help,Name,IsAllowCopy,Updated,CreatedBy,IsActive,Created,UpdatedBy,IsToolbarButton,IsAlwaysUpdateable,IsEncrypted,IsSecure,AD_Element_ID,AD_Reference_ID,AD_Table_ID,AD_Client_ID,AD_Org_ID,EntityType) VALUES (0,'N',0,211762,'Y','N','N',0,'N',1,'N','N','N','Y','f1e7a14f-8ab9-4b2e-9655-95d728ecdc18','Y','IsKey','This column is the key in this table','N','The key column must also be display sequence 0 in the field definition and may be hidden.','Key column','Y',TO_TIMESTAMP('2014-09-05 15:42:25','YYYY-MM-DD HH24:MI:SS'),100,'Y',TO_TIMESTAMP('2014-09-05 15:42:25','YYYY-MM-DD HH24:MI:SS'),100,'N','N','N','N',389,20,200085,0,0,'D')
;
-- Sep 5, 2014 3:42:31 PM COT
ALTER TABLE AD_TableIndex ADD COLUMN IsKey CHAR(1) DEFAULT 'N' CHECK (IsKey IN ('Y','N')) NOT NULL
;
-- Sep 5, 2014 3:42:57 PM COT
INSERT INTO AD_Field (IsEncrypted,AD_Tab_ID,DisplayLength,IsSameLine,IsHeading,SeqNo,IsCentrallyMaintained,AD_Field_ID,IsReadOnly,Help,Description,Name,AD_Field_UU,IsDisplayed,IsFieldOnly,UpdatedBy,CreatedBy,Updated,IsActive,IsDisplayedGrid,SeqNoGrid,XPosition,AD_Client_ID,ColumnSpan,AD_Column_ID,EntityType,AD_Org_ID,Created) VALUES ('N',200096,1,'N','N',140,'Y',203443,'N','The key column must also be display sequence 0 in the field definition and may be hidden.','This column is the key in this table','Key column','606cdea6-8002-4c89-b507-bdeffd5acb2b','Y','N',100,100,TO_TIMESTAMP('2014-09-05 15:42:57','YYYY-MM-DD HH24:MI:SS'),'Y','Y',110,2,0,2,211762,'D',0,TO_TIMESTAMP('2014-09-05 15:42:57','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=90, ColumnSpan=1,Updated=TO_TIMESTAMP('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202209
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=100, IsDisplayed='Y', XPosition=3, ColumnSpan=1,Updated=TO_TIMESTAMP('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=203443
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=110,Updated=TO_TIMESTAMP('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202250
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=120,Updated=TO_TIMESTAMP('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202206
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=130,Updated=TO_TIMESTAMP('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202210
;
-- Sep 5, 2014 3:43:29 PM COT
UPDATE AD_Field SET SeqNo=140,Updated=TO_TIMESTAMP('2014-09-05 15:43:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202535
;
-- Sep 5, 2014 3:44:41 PM COT
UPDATE AD_Field SET DisplayLogic='@IsCreateConstraint@=''Y'' & @IsUnique@=''Y''',Updated=TO_TIMESTAMP('2014-09-05 15:44:41','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=203443
;
SELECT register_migration_script('201409051545_IDEMPIERE-1901.sql') FROM dual
;

View File

@ -189,6 +189,19 @@ public interface I_AD_TableIndex
/** Get Create Constraint */ /** Get Create Constraint */
public boolean isCreateConstraint(); public boolean isCreateConstraint();
/** Column name IsKey */
public static final String COLUMNNAME_IsKey = "IsKey";
/** Set Key column.
* This column is the key in this table
*/
public void setIsKey (boolean IsKey);
/** Get Key column.
* This column is the key in this table
*/
public boolean isKey();
/** Column name IsUnique */ /** Column name IsUnique */
public static final String COLUMNNAME_IsUnique = "IsUnique"; public static final String COLUMNNAME_IsUnique = "IsUnique";
@ -220,6 +233,15 @@ public interface I_AD_TableIndex
/** Get Process Now */ /** Get Process Now */
public boolean isProcessing(); public boolean isProcessing();
/** Column name TableIndexDrop */
public static final String COLUMNNAME_TableIndexDrop = "TableIndexDrop";
/** Set Drop table index */
public void setTableIndexDrop (String TableIndexDrop);
/** Get Drop table index */
public String getTableIndexDrop();
/** Column name Updated */ /** Column name Updated */
public static final String COLUMNNAME_Updated = "Updated"; public static final String COLUMNNAME_Updated = "Updated";

View File

@ -24,11 +24,10 @@ import org.adempiere.exceptions.AdempiereException;
import org.compiere.util.Msg; import org.compiere.util.Msg;
public class MTableIndex extends X_AD_TableIndex { public class MTableIndex extends X_AD_TableIndex {
/** /**
* *
*/ */
private static final long serialVersionUID = 2672452678101398999L; private static final long serialVersionUID = 5312095272014146977L;
/** /**
* Get active indexes from table * Get active indexes from table
@ -168,7 +167,11 @@ public class MTableIndex extends X_AD_TableIndex {
} }
else if (isUnique()) else if (isUnique())
{ {
sql = new StringBuilder("ALTER TABLE " + getTableName() + " ADD CONSTRAINT " + getName() + " UNIQUE ("); sql = new StringBuilder("ALTER TABLE ").append(getTableName()).append(" ADD CONSTRAINT ").append(getName());
if (isKey())
sql.append(" PRIMARY KEY (");
else
sql.append(" UNIQUE (");
getColumns(false); getColumns(false);
for (int i = 0; i < m_columns.length; i++) for (int i = 0; i < m_columns.length; i++)
{ {
@ -201,6 +204,20 @@ public class MTableIndex extends X_AD_TableIndex {
return m_ddl; return m_ddl;
} }
/**
* Get SQL index create DDL
* @return SQL DDL
*/
public String getDropDDL()
{
String sql = null;
if (isCreateConstraint())
sql = "ALTER TABLE " + getAD_Table().getTableName() + " DROP CONSTRAINT " + getName() + " CASCADE";
else
sql = "DROP INDEX " + getName();
return sql;
}
/** /**
* String representation * String representation
* @return info * @return info

View File

@ -30,7 +30,7 @@ public class X_AD_TableIndex extends PO implements I_AD_TableIndex, I_Persistent
/** /**
* *
*/ */
private static final long serialVersionUID = 20131031L; private static final long serialVersionUID = 20140905L;
/** Standard Constructor */ /** Standard Constructor */
public X_AD_TableIndex (Properties ctx, int AD_TableIndex_ID, String trxName) public X_AD_TableIndex (Properties ctx, int AD_TableIndex_ID, String trxName)
@ -43,6 +43,8 @@ public class X_AD_TableIndex extends PO implements I_AD_TableIndex, I_Persistent
setEntityType (null); setEntityType (null);
// U // U
setIsCreateConstraint (false); setIsCreateConstraint (false);
// N
setIsKey (false);
// N // N
setIsUnique (false); setIsUnique (false);
// N // N
@ -243,6 +245,30 @@ public class X_AD_TableIndex extends PO implements I_AD_TableIndex, I_Persistent
return false; return false;
} }
/** Set Key column.
@param IsKey
This column is the key in this table
*/
public void setIsKey (boolean IsKey)
{
set_Value (COLUMNNAME_IsKey, Boolean.valueOf(IsKey));
}
/** Get Key column.
@return This column is the key in this table
*/
public boolean isKey ()
{
Object oo = get_Value(COLUMNNAME_IsKey);
if (oo != null)
{
if (oo instanceof Boolean)
return ((Boolean)oo).booleanValue();
return "Y".equals(oo);
}
return false;
}
/** Set Unique. /** Set Unique.
@param IsUnique Unique */ @param IsUnique Unique */
public void setIsUnique (boolean IsUnique) public void setIsUnique (boolean IsUnique)
@ -309,4 +335,18 @@ public class X_AD_TableIndex extends PO implements I_AD_TableIndex, I_Persistent
} }
return false; return false;
} }
/** Set Drop table index.
@param TableIndexDrop Drop table index */
public void setTableIndexDrop (String TableIndexDrop)
{
set_Value (COLUMNNAME_TableIndexDrop, TableIndexDrop);
}
/** Get Drop table index.
@return Drop table index */
public String getTableIndexDrop ()
{
return (String)get_Value(COLUMNNAME_TableIndexDrop);
}
} }

View File

@ -12,6 +12,8 @@
******************************************************************************/ ******************************************************************************/
package org.compiere.process; package org.compiere.process;
import java.math.BigDecimal;
import org.compiere.model.MTableIndex; import org.compiere.model.MTableIndex;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -30,8 +32,9 @@ public class TableIndexDrop extends SvrProcess {
MTableIndex index = new MTableIndex(getCtx(), p_AD_TableIndex_ID, get_TrxName()); MTableIndex index = new MTableIndex(getCtx(), p_AD_TableIndex_ID, get_TrxName());
log.info(index.toString()); log.info(index.toString());
String sql = "DROP INDEX " + index.getName(); String sql = index.getDropDDL();
int rvalue = DB.executeUpdateEx(sql, get_TrxName()); int rvalue = DB.executeUpdateEx(sql, get_TrxName());
addLog(0, null, new BigDecimal(rvalue), sql);
return rvalue + " - " + sql; return rvalue + " - " + sql;
} }

View File

@ -155,7 +155,7 @@ public class TableIndexValidate extends SvrProcess {
if (modified) if (modified)
{ {
String sql = "DROP INDEX " + index.getName(); String sql = index.getDropDDL();
int rvalue = DB.executeUpdate(sql, (Object[]) null, true, trxName); int rvalue = DB.executeUpdate(sql, (Object[]) null, true, trxName);
if (pi != null) if (pi != null)
pi.addLog(0, null, new BigDecimal(rvalue), sql); pi.addLog(0, null, new BigDecimal(rvalue), sql);