Esempio n. 1
0
  @Override
  public void complete() {
    AmberPersistenceUnit persistenceUnit = _sourceType.getPersistenceUnit();

    Class targetClass = getTargetClass();

    if (targetClass == null || void.class.equals(targetClass))
      throw error(
          _field,
          L.l(
              "Can't determine targetEntity for {0}.  @OneToMany properties must target @Entity beans.",
              _fieldName));

    AmberType targetType = persistenceUnit.createType(targetClass);

    if (targetType == null) {
      throw error(
          _field,
          L.l(
              "targetClass '{0}' is not a known element collection class for {1}.  The targetClass of a @ElementCollection must be a basic class.",
              targetClass.getName(), _fieldName));
    }

    /*
    if (_orderBy != null)
      calculateOrderBy(_orderBy);
    */

    addCollection(targetType);
  }
Esempio n. 2
0
  private void addCollection(AmberType targetType) {
    ElementCollectionField eltCollectionField;

    eltCollectionField = new ElementCollectionField(_sourceType, _fieldName);
    eltCollectionField.setType(targetType);
    eltCollectionField.setLazy(isFetchLazy());

    CollectionTableConfig collectionTableConfig = _collectionTable;

    AmberPersistenceUnit persistenceUnit = _sourceType.getPersistenceUnit();

    String sqlTable = collectionTableConfig.getName();
    AmberTable mapTable = persistenceUnit.createTable(sqlTable);

    HashMap<String, JoinColumnConfig> joinColumnsConfig = collectionTableConfig.getJoinColumnMap();

    ArrayList<ForeignColumn> sourceColumns = null;

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

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

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

    _sourceType.addField(eltCollectionField);
  }
Esempio n. 3
0
  private void introspectTypes() {
    Type retType;

    if (_field instanceof Field) retType = ((Field) _field).getGenericType();
    else retType = ((Method) _field).getGenericReturnType();

    ClassLoader loader = _sourceType.getPersistenceUnit().getTempClassLoader();

    JType type = JTypeWrapper.create(retType, loader);

    JType[] typeArgs = type.getActualTypeArguments();

    if (typeArgs.length > 0) setTargetClass(typeArgs[0].getRawType().getJavaClass());
  }