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.DBManagerUtil;
019    import com.liferay.portal.kernel.dao.db.DBType;
020    import com.liferay.portal.kernel.util.LoggingTimer;
021    import com.liferay.portal.kernel.util.StringBundler;
022    
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 = DBManagerUtil.getDB();
034    
035                    if (db.getDBType() != DBType.DB2) {
036                            return;
037                    }
038    
039                    verifyDB2();
040            }
041    
042            protected void verifyDB2() throws Exception {
043                    try (LoggingTimer loggingTimer = new LoggingTimer()) {
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                            try (PreparedStatement ps = connection.prepareStatement(
052                                            sb.toString());
053                                    ResultSet 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 " +
066                                                            columnName + " set data type varchar(600)");
067                                    }
068                            }
069                    }
070            }
071    
072    }