Package com.caucho.amber.type

Examples of com.caucho.amber.type.EntityType


   * Adds the from item.
   */
  public FromItem addFromItem(QueryParser parser, String id)
    throws QueryParseException
  {
    EntityType entityType = (EntityType) _id.getTargetType();
   
    return parser.addFromItem(entityType.getTable(), id);
  }
View Full Code Here


      _expr.generateSelect(cb);
      return;
    }

    if (type instanceof EntityType) {
      EntityType relatedType = (EntityType) type;
      cb.append(relatedType.getId().generateSelect(getTable()));
    }

    if (! fullSelect)
      return;

    FromItem item = _fromItem;

    // jpa/0l4b
    if (_rootItem != null) {
      EntityType parentType = (EntityType) type;

      while (parentType.getParentType() != null
             && parentType.getParentType() instanceof EntityType) {
        parentType = parentType.getParentType();
      }

      item = _rootItem;
    }
View Full Code Here

      _expr.generateSelect(cb);
      return;
    }

    if (type instanceof EntityType) {
      EntityType relatedType = (EntityType) type;
      cb.append(relatedType.getId().generateSelect(getTable()));
    }

    if (! fullSelect)
      return;

    FromItem item = _fromItem;

    // jpa/0l4b
    if (_rootItem != null) {
      EntityType parentType = (EntityType) type;

      while (parentType.getParentType() != null
             && parentType.getParentType() instanceof EntityType) {
        parentType = parentType.getParentType();
      }

      item = _rootItem;
    }
View Full Code Here

    super.init();

    _cacheTimeout = Long.MAX_VALUE / 2;
    _isTableReadOnly = true;
    for (FromItem item : _fromList) {
      EntityType type = item.getTableType();

      if (type != null) {
        long timeout = type.getCacheTimeout();

        if (timeout < _cacheTimeout)
          _cacheTimeout = timeout;

        if (! type.isReadOnly())
          _isTableReadOnly = false;
      }
      else {
        // XXX: kills the cache?
        _isTableReadOnly = false;
View Full Code Here

      if (item.getJoinExpr() != null && item.isOuterJoin()) {
        cb.append(" on ");
        item.getJoinExpr().generateJoin(cb);
      }

      EntityType entityType = item.getEntityType();

      // jpa/0l44, jpa/0l12
      /* XXX: jpa/0l47 move this to LoadExpr.generateSelect
      if (entityType != null) {
        AmberColumn discriminator = entityType.getDiscriminator();

        if (entityType instanceof SubEntityType &&
            discriminator != null) {
          // jpa/0l4b
          // XXX: needs to use parser.createTableName()
          FromItem discriminatorItem
            = new FromItem((EntityType) entityType,
                           discriminator.getTable(),
                           item.getName() + "_disc",
                           ++i);

          discriminatorItem.setQuery(this);

          _fromList.add(i, discriminatorItem);

          cb.append(", ");
          cb.append(discriminator.getTable().getName());
          cb.append(' ');
          cb.append(discriminatorItem.getName());
        }
      }
      */
    }

    // jpa/0l12
    // if (hasJoinExpr || _where != null) {

    boolean hasExpr = false;

    for (int i = 0; i < _fromList.size(); i++) {
      FromItem item = _fromList.get(i);

      AmberExpr expr = item.getJoinExpr();

      if (expr != null && ! item.isOuterJoin()) {
        if (hasExpr)
          cb.append(" and ");
        else {
          cb.append(" where ");
          hasExpr = true;
        }

        expr.generateJoin(cb);
      }

      EntityType entityType = item.getEntityType();

      // jpa/0l44
      if (entityType != null) {
        AmberColumn discriminator = entityType.getDiscriminator();

        // jpa/0l43
        if (entityType instanceof SubEntityType &&
            discriminator != null) {
          // jpa/0l12, jpa/0l4b

          if (item.getTable() == discriminator.getTable()) {
            if (hasExpr)
              cb.append(" and ");
            else {
              cb.append(" where ");
              hasExpr = true;
            }

            cb.append("(" + item.getName() + "." + discriminator.getName() + " = ");
            cb.append("'" + entityType.getDiscriminatorValue() + "')");
          }
        }
      }
    }

View Full Code Here

        // target entities and delete them recursively
        //
        // in theory, this could cause a loop, but we're ignoring that
        // case for now

        EntityType entityType = (EntityType) _sourceTable.getType();

        CharBuffer cb = new CharBuffer();

        cb.append("select ");
        cb.append(entityType.getId().generateSelect("o"));
        cb.append(" from " + sourceTable + " o");
        cb.append(" where ");

        ArrayList<ForeignColumn> columns = getColumns();

        for (int i = 0; i < columns.size(); i++) {
          if (i != 0)
            cb.append (" and ");

          cb.append(columns.get(i).getName() + "=?");
        }

        // See catch (Exception) below.
        sql = cb.toString();

        pstmt = aConn.prepareStatement(sql);

        entity.__caucho_setKey(pstmt, 1);

        ArrayList<Object> proxyList = new ArrayList<Object>();

        rs = pstmt.executeQuery();
        while (rs.next()) {
          proxyList.add(entityType.getHome().loadLazy(aConn, rs, 1));
        }
        rs.close();

        for (Object obj : proxyList) {
          entityType.getHome().getEntityFactory().delete(aConn, obj);
        }
      } // jpa/0i5e vs. jpa/0h25, jpa/0s2d
      else if ((! isJPA) || (isOwner && (_sourceTable.getType() == null))) {
        CharBuffer cb = new CharBuffer();
View Full Code Here

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

    EntityType targetType = persistenceUnit.getEntityType(targetClass);

    if (targetType == null)
      throw error(field,
                  L.l("targetEntity '{0}' is not an @Entity bean for {1}.  The targetEntity of a @ManyToMany collection must be an @Entity bean.",
                      targetClass.getName(),
View Full Code Here

        EntityItem value = valueRef.get();

        if (value == null)
          continue;

        EntityType entityRoot = value.getEntityHome().getEntityType();
        Object entityKey = key.getKey();

        for (int i = 0; i < size; i++) {
          if (completions.get(i).complete(entityRoot, entityKey, value)) {
            // XXX: delete
View Full Code Here

    return _dependencies;
  }

  protected boolean isEntityParent()
  {
    EntityType parentType = getEntityType().getParentType();

      // jpa/0gg0
    return ((parentType != null) && parentType.isEntity());
  }
View Full Code Here

  @Override
  public final void generate(JavaWriter out)
    throws IOException
  {
    try {
      EntityType parentType = getEntityType().getParentType();

      generateHeader(out, isEntityParent());

      generateInit(out);
View Full Code Here

TOP

Related Classes of com.caucho.amber.type.EntityType

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.