Package siena.jdbc.JdbcPersistenceManager

Examples of siena.jdbc.JdbcPersistenceManager.JdbcClassInfo


    }
  }
 
  public static <T> StringBuilder buildSqlSelect(Query<T> query) {
    Class<T> clazz = query.getQueriedClass();
    JdbcClassInfo info = JdbcClassInfo.getClassInfo(clazz);
    List<String> cols = new ArrayList<String>();

    List<Field> joinFields = JdbcMappingUtils.getJoinFields(query, info);
    if(joinFields==null){
      JdbcClassInfo.calculateColumnsAliases(info.allFields, cols, info.tableName, "");
     
      StringBuilder sql =
        new StringBuilder("SELECT " + Util.join(cols, ", ") + " FROM " + info.tableName);
     
      return sql;
    }

    // builds fields from primary class
    JdbcClassInfo.calculateColumnsAliases(info.allFields, cols, info.tableName, "");
    StringBuilder sql = new StringBuilder(" FROM " + info.tableName);
    int i=0;
    String alias;
    for(Field field: joinFields){
      JdbcClassInfo fieldInfo = JdbcClassInfo.getClassInfo(field.getType());
      if (!ClassInfo.isModel(field.getType())){
        throw new SienaException("Join not possible: Field "+field.getName()+" is not a relation field");
      }
      alias = fieldInfo.tableName + i++;
      fieldInfo.joinFieldAliases.put(field.getName(), alias);
View Full Code Here


  }


  public static <T> void appendSqlOrder(Query<T> query, StringBuilder sql) {
    Class<T> clazz = query.getQueriedClass();
    JdbcClassInfo info = JdbcClassInfo.getClassInfo(clazz);
    List<QueryOrder> orders = query.getOrders();
    List<QueryJoin> joins = query.getJoins();
    if(orders.isEmpty() && joins.isEmpty()) { return; }

    sql.append(" ORDER BY ");
    boolean first = true;
    for (QueryOrder order : orders) {
      if(!first) {
        sql.append(", ");
      }
      first = false;

      if(order.parentField==null){
        String[] columns = ClassInfo.getColumnNames(order.field, info.tableName);
        for (String column : columns) {
          sql.append(column+ (order.ascending? "" : " DESC"));
        }
      }else {
        try {
          JdbcClassInfo parentCi = JdbcClassInfo.getClassInfo(order.parentField.getType());
          Field subField = order.parentField.getType().getField(order.field.getName());
          // get columns using join field alias
          //String[] columns = ClassInfo.getColumnNames(subField, parentCi.tableName);
          String[] columns =
            ClassInfo.getColumnNames(
View Full Code Here

  public static void mapField(Object obj, Field field, ResultSet rs, String tableName, List<Field> joinFields) {
    Class<?> type = field.getType();
    //field.setAccessible(true);
    try {
      if(ClassInfo.isModel(type) && !ClassInfo.isEmbedded(field)) {
        JdbcClassInfo fieldClassInfo = JdbcClassInfo.getClassInfo(type);
       
        if(joinFields==null || joinFields.size()==0 || !joinFields.contains(field)){
          String[] fks = ClassInfo.getColumnNames(field, tableName);
          Object rel = Util.createObjectInstance(type);
          boolean none = false;
View Full Code Here

TOP

Related Classes of siena.jdbc.JdbcPersistenceManager.JdbcClassInfo

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.