Package com.caucho.amber.type

Examples of com.caucho.amber.type.EntityType


      throw new IllegalArgumentException(L.l("{0}() operation can only be applied to an entity instance. If the argument is an entity, the corresponding class must be specified in the scope of a persistence unit.", operation));

    if (_persistenceUnit.isJPA()) {
      String className = entity.getClass().getName();

      EntityType entityType
        = (EntityType) _persistenceUnit.getEntityType(className);

      // jpa/0m08
      if (entityType == null) {
        throw new IllegalArgumentException(L.l("{0}() operation can only be applied to an entity instance. If the argument is an entity, the class '{1}' must be specified in the orm.xml or annotated with @Entity and must be in the scope of a persistence unit.", operation, className));
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

   * 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

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

    EntityType entityType = (EntityType) getTargetType();

    cb.append(entityType.getId().getColumns().get(0).getName());
  }
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

   * 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

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

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

    EntityResultConfig entityResult = entityResults.get(oldEntityResult);

    String className = entityResult.getEntityClass();

    EntityType entityType = _aConn.getPersistenceUnit().getEntityType(className);

    if (entityType == null)
      throw new IllegalStateException(L.l("Unable to locate entity '{0}' for native query.", className));

    int oldIndex = _currIndex;

    // jpa/0y15 _currIndex++;

    /* jpa/0y14
    EntityItem item = entityType.getHome().findItem(_aConn, rs, oldIndex);

    if (item == null)
      return null;

    Entity entity = item.getEntity();
    */

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

    ArrayList<FieldResultConfig> fieldResults
      = entityResult.getFieldResults();

    Entity entity = null;

    int consumed = 0;

    try {
      // jpa/0y14
      entity = (Entity) _aConn.load(className, rs.getObject(oldIndex));

      ArrayList<String> columnNameList = new ArrayList<String>();
      entityType.generateNativeColumnNames(columnNameList);
      String []columnNames = new String[columnNameList.size()];
      columnNameList.toArray(columnNames);
      entity.__caucho_load_native(rs, columnNames);

      // jpa/0y10
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.