Package com.caucho.amber.type

Examples of com.caucho.amber.type.EntityType


    _fromItem = _expr.bindSubPath(parser);

    if (_fromItem == null)
      throw new NullPointerException(_expr.getClass().getName() + " " + _expr);

    EntityType type = getEntityType();

    if (type.getSecondaryTables().size() > 0) {
      for (AmberField field : type.getFields()) {
        AmberTable subTable = field.getTable();

        if (subTable != null && subTable != type.getTable()) {
          LinkColumns link = subTable.getDependentIdLink();

          FromItem item = parser.createDependentFromItem(_fromItem, link);

          _subItems.add(item);
View Full Code Here


                             Map<AmberExpr, String> joinFetchMap)
    throws SQLException
  {
    // jpa/0h13, jpa/1160

    EntityType entityType = getEntityType();

    EntityItem item = entityType.getHome().findItem(aConn, rs, index);

    if (item == null)
      return null;

    int offset = entityType.getId().getKeyCount();

    Entity entity = item.getEntity();

    /* XXX: jpa/0s2c
    if (entityType.getDiscriminator() != null) {
View Full Code Here

        // jpa/1201: postgres 8.0.x/8.2.x compatibility
        if (getMetaData() instanceof PostgresMetaData) {
          item = _fromList.get(0);

          EntityType type = item.getEntityType();

          String targetId = type.getId().generateSelect(item.getName());

          cb.append(" FROM ");

          String tableName = item.getTable().getName();

          cb.append(tableName);
          cb.append(' ');
          cb.append(item.getName());

          isFirst = false;

          cb.append(" where ");

          cb.append(targetId);
          cb.append(" = ");
          cb.append(type.getId().generateSelect(item.getTable().getName()));
        }

        // jpa/1231, jpa/1202 vs jpa/1201 and jpa/1203
        if (_fromList.size() > 1
            && ! getMetaData().supportsUpdateTableList()) {
          // Postgres: jpa/1201 and Oracle: jpa/1203
          item = _fromList.get(1);

          EntityType type = item.getEntityType();

          String relatedId = type.getId().generateSelect(item.getName());

          if (isFirst) {
            isFirst = false;
            cb.append(" where ");
          }
          else
            cb.append(" and ");

          cb.append("exists (select ");

          cb.append(relatedId);

          cb.append(" from ");

          generateFromList(cb, true);

          // jpa/1231
          isFirst = true;
        }

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

          AmberExpr expr = item.getJoinExpr();

          if (expr != null && ! item.isOuterJoin()) {
            // jpa/1231
            if (isFirst) {
              isFirst = false;
              cb.append(" where ");
            }
            else
              cb.append(" and ");

            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 (isFirst) {
                  isFirst = false;
                  cb.append(" where ");
                }
                else
                  cb.append(" and ");

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

            AmberType targetType = pathExpr.getTargetType();

            // jpa/0w24
            if (targetType instanceof EntityType) {
              EntityType relatedType = (EntityType) targetType;
              EntityType parentType = relatedType;

              while (parentType.getParentType() != null) {
                if (parentType.getParentType() instanceof EntityType)
                  parentType = parentType.getParentType();
                else
                  break;
              }

              // jpa/0l4b
              if (parentType != relatedType) {
                FromItem child = pathExpr.getChildFromItem();

                AmberTable table = relatedType.getTable(); // parentType.getTable();
                ArrayList<LinkColumns> outgoingLinks = table.getOutgoingLinks();

                for (LinkColumns link : outgoingLinks) {
                  if (link.getTargetTable().equals(parentType.getTable())) {
                    rootItem = addFromItem((EntityType) parentType,
                                           parentType.getTable());

                    JoinExpr join = new ManyToOneJoinExpr(link, rootItem, child);

                    rootItem.setJoinExpr(join);
View Full Code Here

  private void parseSetValues(FromItem fromItem,
                              ArrayList<AmberExpr> fields,
                              ArrayList<AmberExpr> values)
    throws QueryParseException
  {
    EntityType entity = fromItem.getEntityType();

    int token = -1;

    do {
View Full Code Here

    if (! isIn) {
      AmberEntityHome home = _persistenceUnit.getHomeBySchema(name);

      if (home != null) {
        EntityType type = home.getEntityType();

        schema = new TableIdExpr(home.getEntityType(),
                                 type.getTable().getName());
      }
    }

    IdExpr id = null;
View Full Code Here

   * 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);
    /*
      else if (fieldExpr instanceof ManyToManyExpr)
      return new ManyToManySchemaExpr((ManyToManyExpr) fieldExpr);
    */
    else if (fieldExpr instanceof OneToManyExpr)
      return new OneToManySchemaExpr((OneToManyExpr) fieldExpr);
    throw parser.error(L.l("{0}: '{1}' must be a collection.",
                           type.getBeanClass().getName(),
                           name));
  }
View Full Code Here

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

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

    EntityType entityType = (EntityType) getTargetType();

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

   * 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

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.