001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.verify;
016    
017    import com.liferay.portal.kernel.dao.db.DB;
018    import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
019    import com.liferay.portal.kernel.dao.jdbc.DataAccess;
020    import com.liferay.portal.kernel.util.StringBundler;
021    
022    import java.sql.Connection;
023    import java.sql.PreparedStatement;
024    import java.sql.ResultSet;
025    
026    /**
027     * @author Igor Beslic
028     */
029    public class VerifyDB2 extends VerifyProcess {
030    
031            @Override
032            protected void doVerify() throws Exception {
033                    DB db = DBFactoryUtil.getDB();
034    
035                    String dbType = db.getType();
036    
037                    if (!dbType.equals(DB.TYPE_DB2)) {
038                            return;
039                    }
040    
041                    Connection con = null;
042                    PreparedStatement ps = null;
043                    ResultSet rs = null;
044    
045                    try {
046                            con = DataAccess.getUpgradeOptimizedConnection();
047    
048                            StringBundler sb = new StringBundler(4);
049    
050                            sb.append("select tbname, name, coltype, length from ");
051                            sb.append("sysibm.syscolumns where tbcreator = (select distinct ");
052                            sb.append("current schema from sysibm.sysschemata) AND coltype = ");
053                            sb.append("'VARCHAR' and length = 500");
054    
055                            ps = con.prepareStatement(sb.toString());
056    
057                            rs = ps.executeQuery();
058    
059                            while (rs.next()) {
060                                    String tableName = rs.getString(1);
061    
062                                    if (!isPortalTableName(tableName)) {
063                                            continue;
064                                    }
065    
066                                    String columnName = rs.getString(2);
067    
068                                    runSQL(
069                                            "alter table " + tableName + " alter column " + columnName +
070                                                    " set data type varchar(600)");
071                            }
072                    }
073                    finally {
074                            DataAccess.cleanUp(con, ps, rs);
075                    }
076            }
077    
078    }