Package com.avaje.ebeaninternal.server.deploy.meta

Examples of com.avaje.ebeaninternal.server.deploy.meta.DeployTableJoin


   */
  private void readJoinTable(JoinTable joinTable, DeployBeanPropertyAssocMany<?> prop) {

    String intTableName = getFullTableName(joinTable);
    // set the intersection table
    DeployTableJoin intJoin = new DeployTableJoin();
    intJoin.setTable(intTableName);

    // add the source to intersection join columns
    intJoin.addJoinColumn(true, joinTable.joinColumns(), prop.getBeanTable());

    // set the intersection to dest table join columns
    DeployTableJoin destJoin = prop.getTableJoin();
    destJoin.addJoinColumn(false, joinTable.inverseJoinColumns(), prop.getBeanTable());

    intJoin.setType(SqlJoinType.OUTER);

    // reverse join from dest back to intersection
    DeployTableJoin inverseDest = destJoin.createInverse(intTableName);
    prop.setIntersectionJoin(intJoin);
    prop.setInverseJoin(inverseDest);
  }
View Full Code Here


   */
    private void manyToManyDefaultJoins(DeployBeanPropertyAssocMany<?> prop) {

      String intTableName = null;

      DeployTableJoin intJoin = prop.getIntersectionJoin();
      if (intJoin == null){
        intJoin = new DeployTableJoin();
        prop.setIntersectionJoin(intJoin);
      } else {
        // intersection table already defined (by @JoinTable)
        intTableName = intJoin.getTable();
      }

      BeanTable localTable = factory.getBeanTable(descriptor.getBeanType());
      BeanTable otherTable = factory.getBeanTable(prop.getTargetType());

      final String localTableName = localTable.getUnqualifiedBaseTable();
      final String otherTableName = otherTable.getUnqualifiedBaseTable();

      if (intTableName == null){
        // define intersection table name
        intTableName = getM2MJoinTableName(localTable, otherTable);

        intJoin.setTable(intTableName);
        intJoin.setType(SqlJoinType.OUTER);
      }

    DeployTableJoin destJoin = prop.getTableJoin();


      if (intJoin.hasJoinColumns() && destJoin.hasJoinColumns()){
        // already defined the foreign key columns etc
        return;
      }
      if (!intJoin.hasJoinColumns()){
        // define foreign key columns
      BeanProperty[] localIds = localTable.getIdProperties();
      for (int i = 0; i < localIds.length; i++) {
        // add the source to intersection join columns
        String fkCol = localTableName+"_"+localIds[i].getDbColumn();
        intJoin.addJoinColumn(new DeployTableJoinColumn(localIds[i].getDbColumn(), fkCol));
      }
      }

    if (!destJoin.hasJoinColumns()){
        // define inverse foreign key columns
      BeanProperty[] otherIds = otherTable.getIdProperties();
      for (int i = 0; i < otherIds.length; i++) {
        // set the intersection to dest table join columns
        final String fkCol = otherTableName+"_"+otherIds[i].getDbColumn();
        destJoin.addJoinColumn(new DeployTableJoinColumn(fkCol, otherIds[i].getDbColumn()));
      }
    }

    // reverse join from dest back to intersection
    DeployTableJoin inverseDest = destJoin.createInverse(intTableName);
    prop.setInverseJoin(inverseDest);
  }
View Full Code Here

   */
  public DeployTableJoin getTableJoin(String tableName) {

    String key = tableName.toLowerCase();

    DeployTableJoin tableJoin = (DeployTableJoin) tableJoinMap.get(key);
    if (tableJoin == null) {
      tableJoin = new DeployTableJoin();
      tableJoin.setTable(tableName);
      tableJoin.setType(SqlJoinType.INNER);
      descriptor.addTableJoin(tableJoin);

      tableJoinMap.put(key, tableJoin);
    }
    return tableJoin;
View Full Code Here

  /**
   * Set a the join alias for a assoc one property.
   */
  public void setBeanJoinType(DeployBeanPropertyAssocOne<?> beanProp, boolean outerJoin) {

    DeployTableJoin tableJoin = beanProp.getTableJoin();
    tableJoin.setType(outerJoin ? SqlJoinType.OUTER : SqlJoinType.INNER);
  }
View Full Code Here

        if (assocOne == null) {
          String msg = "Error with property " + prop.getFullBeanName() + ". Could not find a Relationship to table " + tableName
              + ". Perhaps you could use a @JoinColumn instead.";
          throw new RuntimeException(msg);
        }
        DeployTableJoin tableJoin = assocOne.getTableJoin();
        prop.setSecondaryTableJoin(tableJoin, assocOne.getName());
      }
    }
  }
View Full Code Here

    unidirectional.setName(beanTable.getBaseTable());

    info.setBeanJoinType(unidirectional, true);

    // define the TableJoin
    DeployTableJoin oneToManyJoin = oneToMany.getTableJoin();
    if (!oneToManyJoin.hasJoinColumns()) {
      throw new RuntimeException("No join columns");
    }

    // inverse of the oneToManyJoin
    DeployTableJoin unidirectionalJoin = unidirectional.getTableJoin();
    unidirectionalJoin.setColumns(oneToManyJoin.columns(), true);

  }
View Full Code Here

      String m = "Error on " + prop.getFullBeanName();
      m += ". mappedBy property [" + targetDesc + "." + mappedBy + "]is not a OneToOne?";
      throw new PersistenceException(m);
    }

    DeployTableJoin tableJoin = prop.getTableJoin();
    if (!tableJoin.hasJoinColumns()) {
      // define Join as the inverse of the mappedBy property
      DeployTableJoin otherTableJoin = mappedAssocOne.getTableJoin();
      otherTableJoin.copyWithoutType(tableJoin, true, tableJoin.getTable());
    }
  }
View Full Code Here

      throw new PersistenceException(m);
    }

    DeployBeanPropertyAssocOne<?> mappedAssocOne = (DeployBeanPropertyAssocOne<?>) mappedProp;

    DeployTableJoin tableJoin = prop.getTableJoin();
    if (!tableJoin.hasJoinColumns()) {
      // define Join as the inverse of the mappedBy property
      DeployTableJoin otherTableJoin = mappedAssocOne.getTableJoin();
      otherTableJoin.copyTo(tableJoin, true, tableJoin.getTable());
    }

  }
View Full Code Here

    // define the relationships/joins on this side as the
    // reverse of the other mappedBy side ...

    // DeployTableJoin mappedJoin = mappedAssocMany.getTableJoin();
    DeployTableJoin mappedIntJoin = mappedAssocMany.getIntersectionJoin();
    DeployTableJoin mappendInverseJoin = mappedAssocMany.getInverseJoin();

    String intTableName = mappedIntJoin.getTable();

    DeployTableJoin tableJoin = prop.getTableJoin();
    mappedIntJoin.copyTo(tableJoin, true, targetDesc.getBaseTable());

    DeployTableJoin intJoin = new DeployTableJoin();
    mappendInverseJoin.copyTo(intJoin, false, intTableName);
    prop.setIntersectionJoin(intJoin);

    DeployTableJoin inverseJoin = new DeployTableJoin();
    mappedIntJoin.copyTo(inverseJoin, false, intTableName);
    prop.setInverseJoin(inverseJoin);
  }
View Full Code Here

TOP

Related Classes of com.avaje.ebeaninternal.server.deploy.meta.DeployTableJoin

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.