001    /**
002     * Copyright (c) 2000-present 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.PreparedStatement;
023    import java.sql.ResultSet;
024    
025    /**
026     * @author Igor Beslic
027     */
028    public class VerifyDB2 extends VerifyProcess {
029    
030            @Override
031            protected void doVerify() throws Exception {
032                    DB db = DBFactoryUtil.getDB();
033    
034                    String dbType = db.getType();
035    
036                    if (!dbType.equals(DB.TYPE_DB2)) {
037                            return;
038                    }
039    
040                    PreparedStatement ps = null;
041                    ResultSet rs = null;
042    
043                    try {
044                            StringBundler sb = new StringBundler(4);
045    
046                            sb.append("select tbname, name, coltype, length from ");
047                            sb.append("sysibm.syscolumns where tbcreator = (select distinct ");
048                            sb.append("current schema from sysibm.sysschemata) AND coltype = ");
049                            sb.append("'VARCHAR' and length = 500");
050    
051                            ps = connection.prepareStatement(sb.toString());
052    
053                            rs = ps.executeQuery();
054    
055                            while (rs.next()) {
056                                    String tableName = rs.getString(1);
057    
058                                    if (!isPortalTableName(tableName)) {
059                                            continue;
060                                    }
061    
062                                    String columnName = rs.getString(2);
063    
064                                    runSQL(
065                                            "alter table " + tableName + " alter column " + columnName +
066                                                    " set data type varchar(600)");
067                            }
068                    }
069                    finally {
070                            DataAccess.cleanUp(null, ps, rs);
071                    }
072            }
073    
074    }