Package com.caucho.amber.field

Examples of com.caucho.amber.field.ManyToManyField


  }
 
  private void addOwningSide(EntityType targetType)
  {
    AmberPersistenceUnit persistenceUnit = _sourceType.getPersistenceUnit();
    ManyToManyField manyToManyField;

    manyToManyField
      = new ManyToManyField(_sourceType, _fieldName, getCascade());
   
    manyToManyField.setType(targetType);

    String sqlTable = _sourceType.getTable().getName() + "_" +
      targetType.getTable().getName();

    JoinTableConfig joinTableConfig = getJoinTable();

    AmberTable mapTable = null;

    ArrayList<ForeignColumn> sourceColumns = null;
    ArrayList<ForeignColumn> targetColumns = null;

    HashMap<String,JoinColumnConfig> joinColumnsConfig = null;
    HashMap<String,JoinColumnConfig> inverseJoinColumnsConfig = null;

    if (joinTableConfig != null) {
      String joinTableName = joinTableConfig.getName();

      joinColumnsConfig = joinTableConfig.getJoinColumnMap();
      inverseJoinColumnsConfig = joinTableConfig.getInverseJoinColumnMap();

      if (joinColumnsConfig != null
          && joinColumnsConfig.size() > 0)
        manyToManyField.setJoinColumns(true);

      if (inverseJoinColumnsConfig != null
          && inverseJoinColumnsConfig.size() > 0)
        manyToManyField.setInverseJoinColumns(true);
      if (! joinTableName.equals(""))
        sqlTable = joinTableName;
    }

    mapTable = persistenceUnit.createTable(sqlTable);

    sourceColumns
      = calculateColumns(_field, _fieldName, mapTable,
                         _sourceType.getTable().getName() + "_",
                         _sourceType, joinColumnsConfig);

    targetColumns
      = calculateColumns(_field, _fieldName, mapTable,
                         targetType.getTable().getName() + "_",
                         targetType,
                         inverseJoinColumnsConfig);
   

    manyToManyField.setAssociationTable(mapTable);
    manyToManyField.setTable(sqlTable);
    manyToManyField.setLazy(isFetchLazy());

    manyToManyField.setSourceLink(new LinkColumns(mapTable,
                                                  _sourceType.getTable(),
                                                  sourceColumns));

    manyToManyField.setTargetLink(new LinkColumns(mapTable,
                                                  targetType.getTable(),
                                                  targetColumns));

    _sourceType.addField(manyToManyField);
  }
View Full Code Here


      */
  }

  private void addDependentSide(EntityType targetType)
  {
    ManyToManyField sourceField
      = (ManyToManyField) targetType.getField(getMappedBy());

    if (sourceField == null)
      throw error(_field, L.l("Unable to find the associated field in '{0}' for a @ManyToMany relationship from '{1}'",
                              targetType.getName(), _fieldName));

    ManyToManyField manyToManyField;

    manyToManyField = new ManyToManyField(_sourceType,
                                          _fieldName,
                                          sourceField,
                                          getCascade());
    manyToManyField.setType(targetType);
    _sourceType.addField(manyToManyField);

    // jpa/0i5-
    // Update column names for bidirectional many-to-many

    if (! sourceField.hasJoinColumns()) {
      LinkColumns sourceLink = sourceField.getSourceLink();
      ArrayList<ForeignColumn> columns = sourceLink.getColumns();
      for (ForeignColumn column : columns) {
        String columnName = column.getName();
        columnName = columnName.substring(columnName.indexOf('_'));
        columnName = toSqlName(manyToManyField.getName()) + columnName;
        column.setName(columnName);
      }
    }

    if (! sourceField.hasInverseJoinColumns()) {
View Full Code Here

    _sourceType.addField(oneToMany);
  }

  private void oneToManyUnidirectional(EntityType targetType)
  {
    ManyToManyField manyToManyField;

    manyToManyField = new ManyToManyField(_sourceType, _fieldName,
                                          getCascade());
    manyToManyField.setType(targetType);

    String sqlTable = _sourceType.getTable().getName() + "_" + targetType.getTable().getName();

    JoinTable joinTableAnn = _field.getAnnotation(javax.persistence.JoinTable.class);

    JoinTableConfig joinTableConfig = getJoinTable();

    AmberTable mapTable = null;

    ArrayList<ForeignColumn> sourceColumns = null;
    ArrayList<ForeignColumn> targetColumns = null;
    AmberPersistenceUnit persistenceUnit = _sourceType.getPersistenceUnit();

    if (joinTableConfig != null) {
      HashMap<String, JoinColumnConfig> joinColumnsConfig = null;
      HashMap<String, JoinColumnConfig> inverseJoinColumnsConfig = null;

      if (! joinTableConfig.getName().equals(""))
        sqlTable = joinTableConfig.getName();

      joinColumnsConfig = joinTableConfig.getJoinColumnMap();
      inverseJoinColumnsConfig = joinTableConfig.getInverseJoinColumnMap();
      mapTable = persistenceUnit.createTable(sqlTable);

      sourceColumns
        = calculateColumns(_field, _fieldName, mapTable,
                           _sourceType.getTable().getName() + "_",
                           _sourceType,
                           joinColumnsConfig);

      targetColumns = calculateColumns(_field, _fieldName, mapTable,
                                       targetType.getTable().getName() + "_",
                                       targetType,
                                       inverseJoinColumnsConfig);
    }
    else {
      mapTable = persistenceUnit.createTable(sqlTable);

      sourceColumns = calculateColumns(mapTable,
                                       _sourceType.getTable().getName() + "_",
                                       _sourceType);

      targetColumns
        = calculateColumns(mapTable,
                           // jpa/0j40
                           toSqlName(_fieldName) + "_",
                           targetType);
    }

    manyToManyField.setAssociationTable(mapTable);
    manyToManyField.setTable(sqlTable);

    manyToManyField.setSourceLink(new LinkColumns(mapTable,
                                                  _sourceType.getTable(),
                                                  sourceColumns));

    manyToManyField.setTargetLink(new LinkColumns(mapTable,
                                                  targetType.getTable(),
                                                  targetColumns));
      /*
      if (mapKey != null) {

View Full Code Here

    _sourceType.addField(oneToMany);
  }

  private void oneToManyUnidirectional(EntityType targetType)
  {
    ManyToManyField manyToManyField;

    manyToManyField = new ManyToManyField(_sourceType, _fieldName,
            getCascade());
    manyToManyField.setType(targetType);

    String sqlTable = _sourceType.getTable().getName() + "_" + targetType.getTable().getName();

    JoinTable joinTableAnn = _field.getAnnotation(javax.persistence.JoinTable.class);

    JoinTableConfig joinTableConfig = getJoinTable();

    AmberTable mapTable = null;

    ArrayList<ForeignColumn> sourceColumns = null;
    ArrayList<ForeignColumn> targetColumns = null;
    AmberPersistenceUnit persistenceUnit = _sourceType.getPersistenceUnit();

    if (joinTableConfig != null) {
      HashMap<String, JoinColumnConfig> joinColumnsConfig = null;
      HashMap<String, JoinColumnConfig> inverseJoinColumnsConfig = null;

      if (! joinTableConfig.getName().equals(""))
  sqlTable = joinTableConfig.getName();

      joinColumnsConfig = joinTableConfig.getJoinColumnMap();
      inverseJoinColumnsConfig = joinTableConfig.getInverseJoinColumnMap();
      mapTable = persistenceUnit.createTable(sqlTable);

      sourceColumns
  = calculateColumns(_field, _fieldName, mapTable,
         _sourceType.getTable().getName() + "_",
         _sourceType,
         joinColumnsConfig);

      targetColumns = calculateColumns(_field, _fieldName, mapTable,
               targetType.getTable().getName() + "_",
               targetType,
               inverseJoinColumnsConfig);
    }
    else {
      mapTable = persistenceUnit.createTable(sqlTable);

      sourceColumns = calculateColumns(mapTable,
               _sourceType.getTable().getName() + "_",
               _sourceType);

      targetColumns
  = calculateColumns(mapTable,
         // jpa/0j40
         toSqlName(_fieldName) + "_",
         targetType);
    }

    manyToManyField.setAssociationTable(mapTable);
    manyToManyField.setTable(sqlTable);

    manyToManyField.setSourceLink(new LinkColumns(mapTable,
              _sourceType.getTable(),
              sourceColumns));

    manyToManyField.setTargetLink(new LinkColumns(mapTable,
              targetType.getTable(),
              targetColumns));
      /*
      if (mapKey != null) {

View Full Code Here

  }
 
  private void addOwningSide(EntityType targetType)
  {
    AmberPersistenceUnit persistenceUnit = _sourceType.getPersistenceUnit();
    ManyToManyField manyToManyField;

    manyToManyField
      = new ManyToManyField(_sourceType, _fieldName, getCascade());
   
    manyToManyField.setType(targetType);

    String sqlTable = _sourceType.getTable().getName() + "_" +
      targetType.getTable().getName();

    JoinTableConfig joinTableConfig = getJoinTable();

    AmberTable mapTable = null;

    ArrayList<ForeignColumn> sourceColumns = null;
    ArrayList<ForeignColumn> targetColumns = null;

    HashMap<String,JoinColumnConfig> joinColumnsConfig = null;
    HashMap<String,JoinColumnConfig> inverseJoinColumnsConfig = null;

    if (joinTableConfig != null) {
      String joinTableName = joinTableConfig.getName();

      joinColumnsConfig = joinTableConfig.getJoinColumnMap();
      inverseJoinColumnsConfig = joinTableConfig.getInverseJoinColumnMap();

      if (joinColumnsConfig != null
    && joinColumnsConfig.size() > 0)
  manyToManyField.setJoinColumns(true);

      if (inverseJoinColumnsConfig != null
    && inverseJoinColumnsConfig.size() > 0)
  manyToManyField.setInverseJoinColumns(true);
      if (! joinTableName.equals(""))
  sqlTable = joinTableName;
    }

    mapTable = persistenceUnit.createTable(sqlTable);

    sourceColumns
      = calculateColumns(_field, _fieldName, mapTable,
       _sourceType.getTable().getName() + "_",
       _sourceType, joinColumnsConfig);

    targetColumns
      = calculateColumns(_field, _fieldName, mapTable,
       targetType.getTable().getName() + "_",
       targetType,
       inverseJoinColumnsConfig);
   

    manyToManyField.setAssociationTable(mapTable);
    manyToManyField.setTable(sqlTable);
    manyToManyField.setLazy(isFetchLazy());

    manyToManyField.setSourceLink(new LinkColumns(mapTable,
                                                  _sourceType.getTable(),
                                                  sourceColumns));

    manyToManyField.setTargetLink(new LinkColumns(mapTable,
                                                  targetType.getTable(),
                                                  targetColumns));

    _sourceType.addField(manyToManyField);
  }
View Full Code Here

      */
  }

  private void addDependentSide(EntityType targetType)
  {
    ManyToManyField sourceField
      = (ManyToManyField) targetType.getField(getMappedBy());

    if (sourceField == null)
      throw error(_field, L.l("Unable to find the associated field in '{0}' for a @ManyToMany relationship from '{1}'",
            targetType.getName(), _fieldName));

    ManyToManyField manyToManyField;

    manyToManyField = new ManyToManyField(_sourceType,
            _fieldName,
            sourceField,
            getCascade());
    manyToManyField.setType(targetType);
    _sourceType.addField(manyToManyField);

    // jpa/0i5-
    // Update column names for bidirectional many-to-many

    if (! sourceField.hasJoinColumns()) {
      LinkColumns sourceLink = sourceField.getSourceLink();
      ArrayList<ForeignColumn> columns = sourceLink.getColumns();
      for (ForeignColumn column : columns) {
  String columnName = column.getName();
  columnName = columnName.substring(columnName.indexOf('_'));
  columnName = toSqlName(manyToManyField.getName()) + columnName;
  column.setName(columnName);
      }
    }

    if (! sourceField.hasInverseJoinColumns()) {
View Full Code Here

TOP

Related Classes of com.caucho.amber.field.ManyToManyField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.