Пример #1
0
 /**
  * Manages the "database table to class name" transformation:
  *
  * <ul>
  *   <li>If a database table has a filled remark property, its content will be used
  *   <li>Otherwise, the database table name will be used
  * </ul>
  */
 @Override
 public String tableToClassName(TableIdentifier tableIdentifier) {
   String tableName = format(tableIdentifier.getName());
   if (TABLES_COMMENT.containsKey(tableName)) {
     return super.tableToClassName(new TableIdentifier(TABLES_COMMENT.get(tableName)));
   }
   return super.tableToClassName(tableIdentifier);
 }
Пример #2
0
 /**
  * Manages the "database field to property name" transformation:
  *
  * <ul>
  *   <li>If a database field has a filled remark property, its content will be used
  *   <li>Otherwise, the database field name will be used
  * </ul>
  */
 @Override
 public String columnToPropertyName(TableIdentifier table, String column) {
   String tableName = format(table.getName());
   String columnName = format(column);
   if (FIELDS_COMMENT.containsKey(tableName)) {
     Map<String, String> map = FIELDS_COMMENT.get(tableName);
     if (map.containsKey(columnName)) {
       return super.columnToPropertyName(table, map.get(columnName));
     }
   }
   return super.columnToPropertyName(table, column);
 }
Пример #3
0
  private PrimaryKeyInfo bindPrimaryKeyToProperties(
      Table table, RootClass rc, Set processed, Mapping mapping, DatabaseCollector collector) {
    SimpleValue id = null;
    String idPropertyname = null;

    PrimaryKeyInfo pki = new PrimaryKeyInfo();

    List keyColumns = null;
    if (table.getPrimaryKey() != null) {
      keyColumns = table.getPrimaryKey().getColumns();
    } else {
      log.debug("No primary key found for " + table + ", using all properties as the identifier.");
      keyColumns = new ArrayList();
      Iterator iter = table.getColumnIterator();
      while (iter.hasNext()) {
        Column col = (Column) iter.next();
        keyColumns.add(col);
      }
    }

    final TableIdentifier tableIdentifier = TableIdentifier.create(table);

    String tableIdentifierStrategyName = "assigned";

    boolean naturalId;

    if (keyColumns.size() > 1) {
      log.debug(
          "id strategy for " + rc.getEntityName() + " since it has a multiple column primary key");
      naturalId = true;

      id = handleCompositeKey(rc, processed, keyColumns, mapping);
      idPropertyname = revengStrategy.tableToIdentifierPropertyName(tableIdentifier);
      if (idPropertyname == null) {
        idPropertyname = "id";
      }
    } else {
      pki.suggestedStrategy = revengStrategy.getTableIdentifierStrategyName(tableIdentifier);
      String suggestedStrategy = pki.suggestedStrategy;
      if (suggestedStrategy == null) {
        suggestedStrategy =
            collector.getSuggestedIdentifierStrategy(
                tableIdentifier.getCatalog(),
                tableIdentifier.getSchema(),
                tableIdentifier.getName());
        if (suggestedStrategy == null) {
          suggestedStrategy = "assigned";
        }
        tableIdentifierStrategyName = suggestedStrategy;
      } else {
        tableIdentifierStrategyName = suggestedStrategy;
      }

      naturalId = "assigned".equals(tableIdentifierStrategyName);
      Column pkc = (Column) keyColumns.get(0);
      checkColumn(pkc);

      id = bindColumnToSimpleValue(table, pkc, mapping, !naturalId);

      idPropertyname = revengStrategy.tableToIdentifierPropertyName(tableIdentifier);
      if (idPropertyname == null) {
        idPropertyname = revengStrategy.columnToPropertyName(tableIdentifier, pkc.getName());
      }

      processed.add(pkc);
    }
    id.setIdentifierGeneratorStrategy(tableIdentifierStrategyName);
    pki.suggestedProperties = revengStrategy.getTableIdentifierProperties(tableIdentifier);
    id.setIdentifierGeneratorProperties(pki.suggestedProperties);
    if (naturalId) {
      id.setNullValue("undefined");
    }

    Property property =
        makeProperty(
            tableIdentifier, makeUnique(rc, idPropertyname), id, true, true, false, null, null);
    rc.setIdentifierProperty(property);
    rc.setIdentifier(id);

    return pki;
  }