private static void compareTypeField(Map fieldsDefault, Map fields) { for (Iterator i = fieldsDefault.keySet().iterator(); i.hasNext(); ) { Object o = i.next(); SQLField field = (SQLField) fieldsDefault.get(o); SQLField fieldDefault = (SQLField) fields.get(o); if (field != null && fieldDefault != null && field.getType() != fieldDefault.getType()) { System.err.println( "---------> Type different Table " + field.getTable() + " -- Field " + field.getName()); } } }
public static void fixUserCommon(int base) { if (Configuration.getInstance() == null) { Configuration.setInstance(ComptaPropsConfiguration.create()); } Configuration instance = Configuration.getInstance(); SQLTable tableSociete = Configuration.getInstance().getBase().getTable("SOCIETE_COMMON"); String baseName = tableSociete.getRow(base).getString("DATABASE_NAME"); instance.getBase().getDBSystemRoot().getRootsToMap().clear(); try { Set<String> s = new HashSet<String>(); s.add(baseName); instance.getBase().fetchTables(s); } catch (SQLException e) { throw new IllegalStateException("could not access societe base", e); } System.err.println("baseName" + baseName); instance.getSystemRoot().prependToRootPath("Common"); instance.getSystemRoot().prependToRootPath(baseName); SQLSchema baseSQL = instance.getBase().getSchema(baseName); DatabaseMetaData dbMetaDataSociete; try { dbMetaDataSociete = baseSQL.getBase().getDataSource().getConnection().getMetaData(); String[] type = new String[1]; type[0] = "TABLE"; ResultSet rs = dbMetaDataSociete.getTables("", baseSQL.getName(), "%", null); System.err.println("Start " + rs.getFetchSize()); int i = 0; while (rs.next()) { if (rs.getString("TABLE_TYPE") != null && rs.getString("TABLE_TYPE").equalsIgnoreCase("TABLE")) { // System.err.println("FIND TABLE"); // baseSQL.getTableNames(); final SQLTable table = baseSQL.getTable(rs.getString("TABLE_NAME")); Set<SQLField> s = table.getFields(); for (SQLField field : s) { if (field.getName().equalsIgnoreCase("ID_USER_COMMON_CREATE") || field.getName().equalsIgnoreCase("ID_USER_COMMON_MODIFY")) { Object o = field.getDefaultValue(); if (o == null || (o instanceof Integer && ((Integer) o) == 0)) { System.err.println("Bad default on " + field); baseSQL .getBase() .execute( "ALTER TABLE \"" + field.getTable().getSchema().getName() + "\".\"" + field.getTable().getName() + "\" ALTER COLUMN \"" + field.getName() + "\" SET DEFAULT 1;"); baseSQL .getBase() .execute( "UPDATE \"" + field.getTable().getSchema().getName() + "\".\"" + field.getTable().getName() + "\" SET \"" + field.getName() + "\"=1 WHERE \"" + field.getName() + "\"=0 OR \"" + field.getName() + "\" IS NULL;"); } } } } // System.err.println(i++ + " " + rs.getString("TABLE_TYPE")); } rs.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }