예제 #1
0
  /**
   * Performs the foreign key DDL operations.
   *
   * @param datasource the datasource
   * @param ddlMode the DDL Mode
   * @param entity the entity to perform DDL against
   * @throws BatooException thrown in case of an underlying exception
   * @since $version
   * @author hceylan
   */
  public void performForeignKeysDdl(
      DataSource datasource, DDLMode ddlMode, EntityTypeImpl<?> entity) {
    if ((ddlMode == DDLMode.NONE)) {
      return;
    }

    MetamodelImpl.LOG.info(
        "Performing foreign key DDL operations for entiy {0}, mode {1}", entity.getName(), ddlMode);

    for (final EntityTable table : entity.getTables()) {
      // skip parent tables
      if (table.getEntity() != entity) {
        continue;
      }

      MetamodelImpl.LOG.info(
          "Performing foreign key DDL operations for table {0}, mode {1}",
          table.getQName(), ddlMode);

      for (final ForeignKey foreignKey : table.getForeignKeys()) {
        this.jdbcAdaptor.createForeignKey(datasource, foreignKey);
      }
    }

    for (final AssociationMapping<?, ?, ?> mapping : entity.getAssociations()) {
      final JoinTable table = mapping.getTable();
      // skip not applicable join tables
      if ((table == null) || (table.getEntity() != entity)) {
        continue;
      }

      MetamodelImpl.LOG.info(
          "Performing foreign key DDL operations for join table {0}, mode {1}",
          table.getQName(), ddlMode);

      for (final ForeignKey foreignKey : table.getForeignKeys()) {
        this.jdbcAdaptor.createForeignKey(datasource, foreignKey);
      }
    }

    for (final PluralMapping<?, ?, ?> mapping : entity.getMappingsPlural()) {
      if (!mapping.isAssociation()) {
        final AbstractTable table = (AbstractTable) mapping.getTable();
        MetamodelImpl.LOG.info(
            "Performing foreign key DDL operations for join table {0}, mode {1}",
            table.getQName(), ddlMode);

        for (final ForeignKey foreignKey : table.getForeignKeys()) {
          this.jdbcAdaptor.createForeignKey(datasource, foreignKey);
        }
      }
    }
  }
예제 #2
0
  /**
   * Performs the table DDL operations.
   *
   * @param datasource the datasource
   * @param ddlMode the DDL Mode
   * @param entity the entity to perform DDL against
   * @throws BatooException thrown in case of an underlying exception
   * @since $version
   * @author hceylan
   */
  public void performTablesDdl(DataSource datasource, DDLMode ddlMode, EntityTypeImpl<?> entity) {
    MetamodelImpl.LOG.info(
        "Performing DDL operations for entity {0}, mode {1}", entity.getName(), ddlMode);

    // create the entity tables
    for (final EntityTable table : entity.getTables()) {
      // if table belongs to parent then skip
      if (table.getEntity() != entity) {
        continue;
      }

      MetamodelImpl.LOG.info(
          "Performing DDL operations for {0}, mode {1}", table.getQName(), ddlMode);

      this.jdbcAdaptor.createOrUpdateTable(table, datasource, ddlMode);
    }

    // create the join tables
    for (final AssociationMapping<?, ?, ?> mapping : entity.getAssociations()) {
      final JoinTable table = mapping.getTable();

      // skip not applicable tables
      if ((table == null) || (table.getEntity() != entity)) {
        continue;
      }

      this.jdbcAdaptor.createOrUpdateTable(mapping.getTable(), datasource, ddlMode);
    }

    // create the join tables
    for (final PluralMapping<?, ?, ?> mapping : entity.getMappingsPlural()) {
      if (!mapping.isAssociation()) {
        final AbstractTable table = (AbstractTable) mapping.getTable();

        this.jdbcAdaptor.createOrUpdateTable(table, datasource, ddlMode);
      }
    }
  }