Package jodd.db.oom

Examples of jodd.db.oom.DbEntityDescriptor


  /**
   * Lookups for entity name and throws exception if entity name not found.
   */
  protected DbEntityDescriptor lookupName(String entityName) {
    DbEntityDescriptor ded = templateData.getDbOomManager().lookupName(entityName);
    if (ded == null) {
      throw new DbSqlBuilderException("Entity name not registered: " + entityName);
    }
    return ded;
  }
View Full Code Here


  /**
   * Lookups for entity name and throws an exception if entity type is invalid.
   */
  protected DbEntityDescriptor lookupType(Class entity) {
    DbEntityDescriptor ded = templateData.getDbOomManager().lookupType(entity);
    if (ded == null) {
      throw new DbSqlBuilderException("Invalid or not-persistent entity: " + entity.getName());
    }
    return ded;
  }
View Full Code Here

  /**
   * Lookups for table reference and optionally throws an exception if table reference not found.
   */
  protected DbEntityDescriptor lookupTableRef(String tableRef, boolean throwExceptionIfNotFound) {
    DbEntityDescriptor ded = templateData.getTableDescriptor(tableRef);
    if (ded == null) {
      if (throwExceptionIfNotFound) {
        throw new DbSqlBuilderException("Invalid table reference: " + tableRef);
      }
    }
View Full Code Here

  /**
   * Finds for table that contains column,
   */
  protected DbEntityDescriptor findColumnRef(String columnRef) {
    DbEntityDescriptor ded = templateData.findTableDescriptorByColumnRef(columnRef);
    if (ded == null) {
      throw new DbSqlBuilderException("Invalid column reference: " + columnRef);
    }
    return ded;
  }
View Full Code Here

  @Override
  public void process(StringBuilder out) {
    if (objectRef != null) {
      data = templateData.lookupObject(objectRef);
    }
    DbEntityDescriptor ded = lookupTableRef(tableRef);
    String table = resolveTable(tableRef, ded);
    DbEntityColumnDescriptor[] decList = ded.getColumnDescriptors();
    String typeName = StringUtil.uncapitalize(ded.getEntityName());

    int count = 0;
    out.append('(');
    for (DbEntityColumnDescriptor dec : decList) {
      if ((includeColumns == COLS_ONLY_IDS) && (dec.isId() == false)) {
View Full Code Here

    this.data = data;
  }

  @Override
  public void process(StringBuilder out) {
    DbEntityDescriptor ded = entityName != null ? lookupName(entityName) : lookupType(entityType);
    StringBuilder col = new StringBuilder();
    StringBuilder val = new StringBuilder();

    DbEntityColumnDescriptor[] decList = ded.getColumnDescriptors();
    String typeName = StringUtil.uncapitalize(ded.getEntityName());

    int size = 0;
    for (DbEntityColumnDescriptor dec : decList) {
      String property = dec.getPropertyName();
      Object value = BeanUtil.getDeclaredProperty(data, property);
      if (value == null) {
        continue;
      }
     
      if (size > 0) {
        col.append(',').append(' ');
        val.append(',').append(' ');
      }
      size++;
      col.append(dec.getColumnName());

      String propertyName = typeName + '.' + property;
      defineParameter(val, propertyName, value, dec);
    }

    out.append("insert into ").append(ded.getTableName()).append(" (")
        .append(col).append(") values (").append(val).append(')');
  }
View Full Code Here

  public void process(StringBuilder out) {
    if (isPreviousChunkOfType(CHUNK_TABLE)) {
      appendMissingSpace(out);
    }

    DbEntityDescriptor ded = tableRef != null ?
        lookupTableRef(tableRef) :
        lookupType(resolveClass(data));

    out.append(SET);

    DbEntityColumnDescriptor[] decList = ded.getColumnDescriptors();
    String typeName = StringUtil.uncapitalize(ded.getEntityName());
    //String table = resolveTable(tableRef, ded);

    int size = 0;
    for (DbEntityColumnDescriptor dec : decList) {
      String property = dec.getPropertyName();
View Full Code Here

      out.append(columnRef);
      return;
    }

    boolean useTableReference = true;
    DbEntityDescriptor ded = lookupTableRef(tableRef, false);
    if (ded == null) {
      useTableReference = false;
      ded = lookupName(tableRef);
    }

    if (columnRef == null) {
      DbEntityColumnDescriptor[] decList = ded.getColumnDescriptors();
      int count = 0;
      boolean withIds = (columnRefArr != null) && ArraysUtil.contains(columnRefArr, StringPool.PLUS);
      for (DbEntityColumnDescriptor dec : decList) {
        if ((includeColumns == COLS_ONLY_IDS) && (dec.isId() == false)) {
          continue;
        }
        if ((includeColumns == COLS_ALL_BUT_ID) && (dec.isId() == true)) {
          continue;
        }
        if ((includeColumns == COLS_NA_MULTI)
          && (!withIds || (dec.isId() == false))
          && (!ArraysUtil.contains(columnRefArr, dec.getPropertyName()))) {
          continue;
        }
        if (count > 0) {
          out.append(',').append(' ');
        }
        templateData.lastColumnDec = dec;

        if (useTableReference) {
          appendColumnName(out, ded, dec.getColumnName());
        } else {
          appendAlias(out, ded, dec.getColumnName());
        }
        count++;
      }
    } else {
      DbEntityColumnDescriptor dec = ded.findByPropertyName(columnRef);
      templateData.lastColumnDec = dec;
      String columnName = dec == null ? null : dec.getColumnName();
      //String columnName = ded.getColumnName(columnRef);
      if (columnName == null) {
        throw new DbSqlBuilderException("Invalid column reference: " + tableRef + '.' + columnRef);
View Full Code Here

   * Foreign key is created by concatenating foreign table name and column name.
   */
  public static DbSqlBuilder findForeign(Class entity, Object value) {
    String tableRef = createTableRefName(entity);
    DbOomManager dbOomManager = DbOomManager.getInstance();
    DbEntityDescriptor dedFk = dbOomManager.lookupType(value.getClass());

    String tableName = dbOomManager.getTableNames().convertTableNameToEntityName(dedFk.getTableName());
    String columnName = dbOomManager.getColumnNames().convertColumnNameToPropertyName(dedFk.getIdColumnName());

    String fkColumn = uncapitalize(tableName) + capitalize(columnName);
    Object idValue = BeanUtil.getProperty(value, dedFk.getIdPropertyName());
    return sql()._(SELECT).column(tableRef)._(FROM).table(entity, tableRef)._(WHERE).ref(tableRef, fkColumn)._(EQUALS).columnValue(idValue);
  }
View Full Code Here

  // ---------------------------------------------------------------- process

  @Override
  public void process(StringBuilder out) {

    DbEntityDescriptor ded;

    if (tableRef != null) {
      ded = lookupTableRef(tableRef);

      String tableName = resolveTable(tableRef, ded);

      out.append(tableName);
    } else {
      ded = findColumnRef(columnRef);
    }


    if (onlyId == true) {
      if (tableRef != null) {
        out.append('.');
      }
      out.append(ded.getIdColumnName());
    } else if (columnRef != null) {
      DbEntityColumnDescriptor dec = ded.findByPropertyName(columnRef);

      templateData.lastColumnDec = dec;

      String column = dec == null ? null : dec.getColumnName();
      //String column = ded.getColumnName(columnRef);
View Full Code Here

TOP

Related Classes of jodd.db.oom.DbEntityDescriptor

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.