summaryrefslogtreecommitdiffstats
blob: 3cc7d378935972176adb177e8e2f7c8a2aece0b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************************
 * Copyright (c) 2011, 2013 SunGard CSA LLC and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    SunGard CSA LLC - initial API and implementation and/or initial documentation
 *******************************************************************************/
package org.eclipse.stardust.engine.core.upgrade.jobs;

import java.util.Iterator;
import java.util.List;

import org.eclipse.stardust.common.CollectionUtils;
import org.eclipse.stardust.common.config.Version;
import org.eclipse.stardust.engine.core.persistence.jdbc.DBMSKey;
import org.eclipse.stardust.engine.core.persistence.jdbc.FieldDescriptor;
import org.eclipse.stardust.engine.core.persistence.jdbc.TypeDescriptor;
import org.eclipse.stardust.engine.core.runtime.beans.SchemaHelper;
import org.eclipse.stardust.engine.core.upgrade.framework.AlterTableInfo;
import org.eclipse.stardust.engine.core.upgrade.framework.DatabaseHelper;
import org.eclipse.stardust.engine.core.upgrade.framework.UpgradeException;
import org.eclipse.stardust.engine.core.upgrade.framework.AbstractTableInfo.FieldInfo;


/**
 * @author born
 * @version $Revision: $
 */
public class R4_9_0from4_7_0RuntimeJob extends DbmsAwareRuntimeUpgradeJob
{
   private static final Version VERSION = Version.createFixedVersion(4, 9, 0);
   
   private static final String LOG_ENTRY_TABLE_NAME = "log_entry";
   private static final String LOG_ENTRY_AI_COLUMN = "activityInstance"; 
   private static final String LOG_ENTRY_PI_COLUMN = "processInstance";

   R4_9_0from4_7_0RuntimeJob()
   {
      super(new DBMSKey[] { DBMSKey.ORACLE, DBMSKey.ORACLE9i, DBMSKey.DB2_UDB, DBMSKey.MYSQL,
            DBMSKey.DERBY, DBMSKey.POSTGRESQL, DBMSKey.SYBASE });
   }

   public Version getVersion()
   {
      return VERSION;
   }

   protected void upgradeSchema(boolean recover) throws UpgradeException
   {
      DBMSKey targetDBMS = item.getDbDescriptor().getDbmsKey();
      if(DBMSKey.ORACLE.equals(targetDBMS) || DBMSKey.ORACLE9i.equals(targetDBMS))
      {
         for (Iterator iter = SchemaHelper.getPersistentClasses(item.getDbDescriptor())
               .iterator(); iter.hasNext();)
         {
            Class type = (Class) iter.next();
            final TypeDescriptor typeDescriptor = TypeDescriptor.get(type);
   
            final List modifyColumnCandidates = CollectionUtils.newArrayList();
   
            List persistentFields = typeDescriptor.getPersistentFields();
            for (Iterator fieldIter = persistentFields.iterator(); fieldIter.hasNext();)
            {
               FieldDescriptor fieldDscr = (FieldDescriptor) fieldIter.next();
               Class fieldType = fieldDscr.getField().getType();
               int length = fieldDscr.getLength();
               if (String.class.isAssignableFrom(fieldType) && Integer.MAX_VALUE != length)
               {
                  modifyColumnCandidates.add(new FieldInfo(fieldDscr.getField().getName(),
                        String.class, length));
               }
            }
   
            if ( !modifyColumnCandidates.isEmpty())
            {
               DatabaseHelper.alterTable(item, new AlterTableInfo(typeDescriptor
                     .getTableName())
               {
                  public FieldInfo[] getModifiedFields()
                  {
                     return (FieldInfo[]) modifyColumnCandidates
                           .toArray(new FieldInfo[modifyColumnCandidates.size()]);
                  }
   
               }, this);
            }
         }
      }
      DatabaseHelper.alterTable(item, new AlterTableInfo(LOG_ENTRY_TABLE_NAME)
      {
         private final FieldInfo ACTIVITY_INSTANCE = new FieldInfo(
               LOG_ENTRY_AI_COLUMN, Long.TYPE, 0, false);
         private final FieldInfo PROCESS_INSTANCE = new FieldInfo(
               LOG_ENTRY_PI_COLUMN, Long.TYPE, 0, false);
         
         public IndexInfo[] getAddedIndexes()
         {
            return new IndexInfo[] {// 
                  new IndexInfo("log_entry_idx2", false, new FieldInfo[] { ACTIVITY_INSTANCE }),
                  new IndexInfo("log_entry_idx3", false, new FieldInfo[] { PROCESS_INSTANCE })};
         }
      }, this);
   }

   protected void migrateData(boolean recover) throws UpgradeException
   {
   }

   protected void finalizeSchema(boolean recover) throws UpgradeException
   {
   }

   @Override
   protected void printUpgradeSchemaInfo()
   {
      // TODO Auto-generated method stub
      
   }

   @Override
   protected void printMigrateDataInfo()
   {
      // TODO Auto-generated method stub
      
   }

   @Override
   protected void printFinalizeSchemaInfo()
   {
      // TODO Auto-generated method stub
      
   }
}