/* 115 */ ArrayList newNames = new ArrayList();
/* 116 */ JDBCFieldBridge[] fields = this.entity.getTableFields();
/* 117 */ String tableName = this.entity.getQualifiedTableName();
/* 118 */ for (int i = 0; i < fields.length; i++)
/* */ {
/* 120 */ JDBCFieldBridge field = fields[i];
/* 121 */ JDBCType jdbcType = field.getJDBCType();
/* 122 */ String[] columnNames = jdbcType.getColumnNames();
/* 123 */ String[] sqlTypes = jdbcType.getSQLTypes();
/* 124 */ boolean[] notNull = jdbcType.getNotNull();
/* */
/* 126 */ for (int j = 0; j < columnNames.length; j++)
/* */ {
/* 128 */ String name = columnNames[j];
/* 129 */ String ucName = name.toUpperCase();
/* */
/* 131 */ newNames.add(ucName);
/* */
/* 133 */ int oldIndex = oldNames.indexOf(ucName);
/* 134 */ if (oldIndex == -1)
/* */ {
/* 137 */ StringBuffer buf = new StringBuffer(sqlTypes[j]);
/* 138 */ if (notNull[j] != 0)
/* */ {
/* 140 */ buf.append(" NOT ").append("NULL");
/* */ }
/* 142 */ alterTable(this.entity.getDataSource(), this.entityMetaData.getTypeMapping().getAddColumnTemplate(), tableName, name, buf.toString());
/* */ }
/* */ else
/* */ {
/* 150 */ String type = (String)oldTypes.get(oldIndex);
/* 151 */ if ((!type.equals("CHAR")) && (!type.equals("VARCHAR"))) {
/* */ continue;
/* */ }
/* */ try
/* */ {
/* 156 */ String l = sqlTypes[j];
/* 157 */ l = l.substring(l.indexOf('(') + 1, l.length() - 1);
/* 158 */ Integer oldLength = (Integer)oldSizes.get(oldIndex);
/* 159 */ if (Integer.parseInt(l) > oldLength.intValue())
/* */ {
/* 161 */ alterTable(this.entity.getDataSource(), this.entityMetaData.getTypeMapping().getAlterColumnTemplate(), tableName, name, sqlTypes[j]);
/* */ }
/* */
/* */ }
/* */ catch (Exception e)
/* */ {
/* 168 */ this.log.warn("EXCEPTION ALTER :" + e.toString());
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */
/* 175 */ JDBCCMPFieldMetaData fieldMD = this.entity.getMetaData().getCMPFieldByName(field.getFieldName());
/* 176 */ if ((fieldMD == null) || (!fieldMD.isIndexed()))
/* */ continue;
/* 178 */ if (oldIndexes == null)
/* */ {
/* 180 */ oldIndexes = SQLUtil.getOldIndexes(this.entity.getQualifiedTableName(), this.entity.getDataSource());
/* 181 */ this.idxCount = oldIndexes.getIndexNames().size();
/* */ }
/* 183 */ if (hasIndex(oldIndexes, field))
/* */ continue;
/* 185 */ createCMPIndex(this.entity.getDataSource(), field, oldIndexes.getIndexNames());
/* */ }
/* */
/* 192 */ Iterator it = oldNames.iterator();
/* 193 */ while (it.hasNext())
/* */ {
/* 195 */ String name = (String)(String)it.next();
/* 196 */ if (!newNames.contains(name))
/* */ {
/* 198 */ alterTable(this.entity.getDataSource(), this.entityMetaData.getTypeMapping().getDropColumnTemplate(), tableName, name, "");
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */
/* 208 */ Set createdTables = getCreatedTables(this.manager);
/* */
/* 210 */ if ((this.entityMetaData.getCreateTable()) && (!createdTables.contains(this.entity.getEntityName())))
/* */ {
/* 212 */ DataSource dataSource = this.entity.getDataSource();
/* 213 */ createTable(dataSource, this.entity.getQualifiedTableName(), getEntityCreateTableSQL(dataSource));
/* */
/* 216 */ if (!tableExisted)
/* */ {
/* 218 */ createCMPIndices(dataSource, SQLUtil.getOldIndexes(this.entity.getQualifiedTableName(), this.entity.getDataSource()).getIndexNames());
/* */ }
/* 224 */ else if (this.log.isDebugEnabled())
/* */ {
/* 226 */ this.log.debug("Indices for table " + this.entity.getQualifiedTableName() + "not created as table existed");
/* */ }
/* */
/* 232 */ if (!tableExisted)
/* */ {
/* 234 */ issuePostCreateSQL(dataSource, this.entity.getMetaData().getDefaultTablePostCreateCmd(), this.entity.getQualifiedTableName());
/* */ }
/* */
/* 239 */ createdTables.add(this.entity.getEntityName());
/* */ }
/* */ else
/* */ {
/* 243 */ this.log.debug("Table not create as requested: " + this.entity.getQualifiedTableName());
/* */ }
/* */
/* 247 */ JDBCAbstractCMRFieldBridge[] cmrFields = this.entity.getCMRFields();
/* 248 */ for (int i = 0; i < cmrFields.length; i++)
/* */ {
/* 250 */ JDBCAbstractCMRFieldBridge cmrField = cmrFields[i];
/* 251 */ JDBCRelationMetaData relationMetaData = cmrField.getMetaData().getRelationMetaData();
/* */
/* 254 */ EntityBridge relatedEntity = cmrField.getRelatedEntity();
/* 255 */ if ((!relationMetaData.isTableMappingStyle()) || (!createdTables.contains(relatedEntity.getEntityName())))
/* */ continue;
/* 257 */ DataSource dataSource = relationMetaData.getDataSource();
/* */
/* 259 */ boolean relTableExisted = SQLUtil.tableExists(cmrField.getQualifiedTableName(), this.entity.getDataSource());
/* */
/* 261 */ if (relTableExisted)
/* */ {
/* 263 */ if (relationMetaData.getAlterTable())
/* */ {
/* 265 */ ArrayList oldNames = SQLUtil.getOldColumns(cmrField.getQualifiedTableName(), dataSource).getColumnNames();
/* 266 */ ArrayList newNames = new ArrayList();
/* 267 */ JDBCFieldBridge[] leftKeys = cmrField.getTableKeyFields();
/* 268 */ JDBCFieldBridge[] rightKeys = cmrField.getRelatedCMRField().getTableKeyFields();
/* 269 */ JDBCFieldBridge[] fields = new JDBCFieldBridge[leftKeys.length + rightKeys.length];
/* 270 */ System.arraycopy(leftKeys, 0, fields, 0, leftKeys.length);
/* 271 */ System.arraycopy(rightKeys, 0, fields, leftKeys.length, rightKeys.length);
/* */
/* 274 */ boolean different = false;
/* 275 */ for (int j = 0; j < fields.length; j++)
/* */ {
/* 277 */ JDBCFieldBridge field = fields[j];
/* */
/* 279 */ String name = field.getJDBCType().getColumnNames()[0].toUpperCase();
/* 280 */ newNames.add(name);
/* */
/* 282 */ if (oldNames.contains(name))
/* */ continue;
/* 284 */ different = true;