Package com.lingbobu.flashdb.common

Examples of com.lingbobu.flashdb.common.ColumnInfo


      int dataType = sqlType2DataType(columnSqlType);
      if (dataType == DataTypes.TYPE_OBJECT)
        throw new RuntimeException("Unsupport sql type "+columnSqlType+" for column '"+columnName+"'");

      columnIndexs.put(columnName, lcolumnInfos.size());
      lcolumnInfos.add(new ColumnInfo(columnName, dataType, isNullable));
    }
   
    ResultSet rstPrimaryKeys = dbMetaData.getPrimaryKeys(null, null, tableName);
    List<String> keyColumns = new ArrayList<String>();
    while (rstPrimaryKeys.next()) {
      String columnName = rstPrimaryKeys.getString("COLUMN_NAME");
      keyColumns.add(columnName);
    }
   
    if (nAutoIncrement >= 0) {
      if (keyColumns.size() != 1)
        throw new RuntimeException("AutoIncrement but no PrimaryKey");
      if (! keyColumns.get(0).equals(lcolumnInfos.get(nAutoIncrement).getName()))
        throw new RuntimeException("AutoIncrement only support on column of PrimaryKey");
    }
   
    // 将主键字段移到最前面
    ColumnInfo[] columnInfos = lcolumnInfos.toArray(new ColumnInfo[lcolumnInfos.size()]);
    for (int i=0; i < keyColumns.size(); i++) {
      String columnName = keyColumns.get(i);
      Integer columnIndex = columnIndexs.get(columnName);
      if (columnIndex == null)
        throw new RuntimeException("Unkown column '"+columnName+"' of PrimaryKey");
      int n = columnIndex.intValue();
      if (n == i) continue;
      else if (n < i)
        throw new RuntimeException("Error order of column '"+columnName+"' for PrimaryKey");
     
      ColumnInfo tmp = columnInfos[i];
      columnInfos[i] = columnInfos[n];
      columnInfos[n] = tmp;
      columnIndexs.put(columnInfos[i].getName(), i);
      columnIndexs.put(columnInfos[n].getName(), n);
    }
View Full Code Here


      this.dataSqlIsComplex = true;
    }
   
    this.columns = metaInfos.getColumns();
    this.isFirstColumnIsUnique = (metaInfos.getKeyColumnCount() == 1);
    ColumnInfo relateColumn = findColumn(joinFieldRelate, this.columns);
    if (relateColumn == null)
      throw new RuntimeException("Cann't found joinFieldRelate '"+joinFieldRelate+"' for table '"+ tableNameOrSql +"'.");
   
    this.joinFieldRelate = relateColumn.getName();
    this.isPrimaryKeyR = (isFirstColumnIsUnique && (relateColumn == this.columns[0]));
   
    if (loadData) {
      QueryResultSet qrsData = flashDatabase.executeQuery(dataSql, new Object[0]);
      this.key2rows = readKey2rows(qrsData, joinFieldRelate, isPrimaryKeyR);
View Full Code Here

  public PartInput[] getPartInputs() {
    // 计算各表的字段信息
    ResultSetMeta metaInfos = flashDatabase.getMetaInfos(mainTableOrSql);
    ColumnInfo[] mainColumns = metaInfos.getColumns();
    this.mainIsTableName = (mainTableOrSql.indexOf(' ') < 0);
    ColumnInfo mainKeyColumnInfo;
    int tablesOffset;
    if (mainIsTableName) {
      if (metaInfos.getKeyColumnCount() != 1)
        throw new RuntimeException("Main table '"+ mainTableOrSql +"' must single key field.");
      mainKeyColumnInfo = mainColumns[0];

      ConverterJoinTable mainJTable = new ConverterJoinTable(mainTableOrSql, mainKeyColumnInfo.getName(), mainKeyColumnInfo.getName(), false, flashDatabase, false, false);
      tables = new ConverterJoinTable[1+ joinTableInfos.length];
      tablesIsPrimaryKeyM = new boolean[tables.length];
      tables[0] = mainJTable;
      tablesIsPrimaryKeyM[0] = true;
      tablesOffset = 1;
    }
    else {
      mainKeyColumnInfo = null;
      tables = new ConverterJoinTable[joinTableInfos.length];
      tablesIsPrimaryKeyM = new boolean[tables.length];
      tablesOffset = 0;
    }
   
    for (int i=0; i < joinTableInfos.length; i++) {
      JoinTableInfo joinTableInfo = joinTableInfos[i];
      ColumnInfo joinFieldMain = ConverterJoinTable.findColumn(joinTableInfo.joinFieldMain, mainColumns);
      if (joinFieldMain == null)
        throw new RuntimeException("Cann't found joinFieldMain '"+joinTableInfo.joinFieldMain+"' for table '"+ joinTableInfo.tableName +"'.");

      ConverterJoinTable joinTable = new ConverterJoinTable(joinTableInfo.tableName, joinFieldMain.getName(), joinTableInfo.joinFieldRelate
          , (joinFieldMain.getDataType() & DataTypes.TYPE_ARRAY) > 0
          , flashDatabase, false, false);

      tables[tablesOffset+ i] = joinTable;
      tablesIsPrimaryKeyM[tablesOffset+ i] = (joinFieldMain == mainKeyColumnInfo);
    }
View Full Code Here

TOP

Related Classes of com.lingbobu.flashdb.common.ColumnInfo

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.