Examples of EntityType


Examples of com.caucho.amber.type.EntityType

   */
  public void list(List<Object> list, AmberConnection aConn, long maxAge)
    throws SQLException
  {
    AmberType type = _query.getResultType(0);
    EntityType entityType = (EntityType) type;
    Class cl = entityType.getBeanClass();
   
    synchronized (this) {
      long now = Alarm.getCurrentTime();

      if (now < _loadTime + maxAge || _isLoading && _loadTime > 0) {
        int length = _values.size();

        for (int i = 0; i < length; i++) {
          Object key = _values.get(i);

          list.add(aConn.loadLazy(cl.getName(), entityType.getName(), (java.io.Serializable) key));
        }
        return;
      }

      _isLoading = true;
View Full Code Here

Examples of com.caucho.amber.type.EntityType

    if (select) {
      cb.append(_fromItem.getName());
      cb.append('.');
    }

    EntityType entityType = (EntityType) getTargetType();

    cb.append(entityType.getId().getColumns().get(0).getName());
  }
View Full Code Here

Examples of com.caucho.amber.type.EntityType

   * Creates a field-based schema.
   */
  public SchemaExpr createField(QueryParser parser, String name)
    throws QueryParseException
  {
    EntityType type = _expr.getTargetType();

    AmberField field = type.getField(name);

    if (field == null)
      throw parser.error(L.l("{0}: '{1}' is an unknown field.",
                             type.getBeanClass().getName(),
                             name));

    AmberExpr fieldExpr = _expr.createField(parser, name);

    if (fieldExpr instanceof ManyToOneExpr)
      return new ManyToOneSchemaExpr((ManyToOneExpr) fieldExpr, name);

    if (fieldExpr instanceof DependentEntityOneToOneExpr)
      return new OneToOneSchemaExpr((DependentEntityOneToOneExpr) fieldExpr,
                                    name);

    throw parser.error(L.l("{0}: '{1}' must be a collection or one-to-one relationship.",
                           type.getBeanClass().getName(),
                           name));
  }
View Full Code Here

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

Examples of com.caucho.amber.type.EntityType

      _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

Examples of com.caucho.amber.type.EntityType

      _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

Examples of com.caucho.amber.type.EntityType

    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

Examples of com.caucho.amber.type.EntityType

      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

Examples of com.caucho.amber.type.EntityType

        // 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

Examples of com.caucho.amber.type.EntityType

    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
TOP
Copyright © 2018 www.massapi.com. 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.