Package weave.config.DataConfig

Examples of weave.config.DataConfig.DataEntityMetadata


            q_sqlKeyColumn,
            q_sqlColumn,
            SQLUtils.quoteSchemaTable(conn, sqlSchema, sqlTable)
          );

        DataEntityMetadata metaQuery = new DataEntityMetadata();
        // we don't search public metadata because that would be a separate sql query
        // and we only know the entityType.
        metaQuery.setPrivateValues(
            PrivateMetadata.CONNECTION, connectionName,
            PrivateMetadata.SQLQUERY, query
          );
        if (filteredValues != null)
        {
          String filteredQuery = buildFilteredQuery(conn, query, filteredValues.columnNames);
          metaQuery.setPrivateValues(PrivateMetadata.SQLQUERY, filteredQuery);
          // generate one query per unique filter value combination
          for (int iRow = 0; iRow < filteredValues.rows.length; iRow++)
          {
            ColumnInfo info = new ColumnInfo();
            columnInfoList.add(info);
           
            info.schema = sqlSchema;
            info.table = sqlTable;
            info.column = sqlColumnNames[iCol];
           
            info.sqlParamsArray = filteredValues.rows[iRow];
            info.sqlParamsStr = CSVParser.defaultParser.createCSVRow(info.sqlParamsArray, true);
            info.title = buildFilteredColumnTitle(configColumnNames[iCol], info.sqlParamsArray);
            info.query = filteredQuery;
            testQueryAndGetDataType(conn, info);
           
            if (configAppend)
            {
              // try to find a matching column using private metadata: connection, sqlQuery, and sqlParams
              metaQuery.setPrivateValues(PrivateMetadata.SQLPARAMS, info.sqlParamsStr);
              info.existingColumnId = ListUtils.getFirstSortedItem(
                  dataConfig.searchPrivateMetadata(metaQuery.privateMetadata, null),
                  DataConfig.NULL
                );
              if (info.existingColumnId != DataConfig.NULL)
                foundMatchingColumnIds = true;
            }
          }
        }
        else
        {
          ColumnInfo info = new ColumnInfo();
          columnInfoList.add(info);
         
          info.schema = sqlSchema;
          info.table = sqlTable;
          info.column = sqlColumnNames[iCol];
         
          info.title = configColumnNames[iCol];
          info.query = query;
          testQueryAndGetDataType(conn, info);
         
          if (configAppend)
          {
            // try to find a matching column using private metadata: connection and sqlQuery
            info.existingColumnId = ListUtils.getFirstSortedItem(
                dataConfig.searchPrivateMetadata(metaQuery.privateMetadata, null),
                DataConfig.NULL
              );
            if (info.existingColumnId != DataConfig.NULL)
              foundMatchingColumnIds = true;
          }
        }
      }
     
      // done generating column info
     
      // determine if columns should be appended to an existing table
      int existingTableId = DataConfig.NULL;
      if (foundMatchingColumnIds)
      {
        // get the set of all matching column ids
        Set<Integer> columnIds = new HashSet<Integer>();
        for (ColumnInfo info : columnInfoList)
          columnIds.add(info.existingColumnId);
        // find first matching parent table id
        for (Relationship r : dataConfig.getRelationships(columnIds))
        {
          String parentType = dataConfig.getEntityTypes(Arrays.asList(r.parentId)).get(r.parentId);
          if (Strings.equal(parentType, EntityType.TABLE))
          {
            existingTableId = r.parentId;
            break;
          }
        }
      }
     
      DataEntityMetadata tableInfo = tableImportInfo == null ? new DataEntityMetadata() : tableImportInfo;
      tableInfo.setPublicValues(PublicMetadata.ENTITYTYPE, EntityType.TABLE);
          tableInfo.setPrivateValues(
            PrivateMetadata.CONNECTION, connectionName,
            PrivateMetadata.SQLSCHEMA, sqlSchema,
            PrivateMetadata.SQLTABLE, sqlTable,
            PrivateMetadata.SQLKEYCOLUMN, sqlKeyColumn
          );
         
          if (existingTableId == DataConfig.NULL)
          {
            // only set title if creating a new table
            tableInfo.setPublicValues(PublicMetadata.TITLE, configDataTableName);
        table_id = dataConfig.newEntity(tableInfo, DataConfig.NULL, DataConfig.NULL);
          }
          else
          {
            table_id = existingTableId;
            // update private metadata only
            dataConfig.updateEntity(table_id, tableInfo);
          }
     
      for (int i = 0; i < columnInfoList.size(); i++)
      {
        ColumnInfo info = columnInfoList.get(i);
        DataEntityMetadata newMeta = new DataEntityMetadata();
       
        // only set title on new columns
        if (existingTableId == DataConfig.NULL || info.existingColumnId == DataConfig.NULL)
          newMeta.setPublicValues(PublicMetadata.TITLE, info.title);
         
        newMeta.setPublicValues(
          PublicMetadata.ENTITYTYPE, EntityType.COLUMN,
          PublicMetadata.KEYTYPE, keyType,
          PublicMetadata.DATATYPE, info.dataType,
          PublicMetadata.PROJECTION, info.projection
        );
        newMeta.setPrivateValues(
          PrivateMetadata.CONNECTION, connectionName,
          PrivateMetadata.SQLQUERY, info.query,
          PrivateMetadata.SQLSCHEMA, info.schema,
          PrivateMetadata.SQLTABLE, info.table,
          PrivateMetadata.SQLKEYCOLUMN, sqlKeyColumn,
          PrivateMetadata.SQLCOLUMN, info.column
        );
        if (filteredValues != null)
        {
          newMeta.setPrivateValues(
            PrivateMetadata.SQLPARAMS, info.sqlParamsStr,
            PrivateMetadata.SQLFILTERCOLUMNS, CSVParser.defaultParser.createCSVRow(ListUtils.getItems(sqlColumnNames, filterColumnIndices), true)
          );
        }
View Full Code Here


    finally
    {
      SQLUtils.cleanup(conn);
    }

        DataEntityMetadata tableInfo = new DataEntityMetadata();
        tableInfo.setPrivateValues(
          PrivateMetadata.IMPORTMETHOD, "importSHP",
          PrivateMetadata.FILENAME, CSVParser.defaultParser.createCSVRow(fileNameWithoutExtension, true),
          PrivateMetadata.KEYCOLUMN, CSVParser.defaultParser.createCSVRow(keyColumns, true),
          PrivateMetadata.CONNECTION, configConnectionName,
          PrivateMetadata.SQLSCHEMA, sqlSchema,
          PrivateMetadata.SQLTABLEPREFIX, sqlTablePrefix
        );
   
    if (importDBFData)
    {
     
      // get key column SQL code
      String keyColumnsString;
      if (keyColumns.length == 1)
      {
        keyColumnsString = keyColumns[0];
      }
      else
      {
        keyColumnsString = "CONCAT(";
        for (int i = 0; i < keyColumns.length; i++)
        {
          if (i > 0)
            keyColumnsString += ",";
          keyColumnsString += "CAST(" + keyColumns[i] + " AS CHAR)";
        }
        keyColumnsString += ")";
      }

      // add SQL statements to sqlconfig
      String[] columnNames = getSQLColumnNames(configConnectionName, password, sqlSchema, dbfTableName);
      tableId = addConfigDataTable(
          configTitle, configConnectionName,
          configKeyType, keyColumnsString, -1, columnNames, columnNames,
          sqlSchema, dbfTableName, false, null, tableInfo, append);
    }
    else
    {
      tableInfo.setPublicValues(
        PublicMetadata.ENTITYTYPE, EntityType.TABLE,
        PublicMetadata.TITLE, configTitle
      );
            tableId = dataConfig.newEntity(tableInfo, DataConfig.NULL, DataConfig.NULL);
    }

    try
    {
      // prepare metadata for existing column check
      DataEntityMetadata geomInfo = new DataEntityMetadata();
      // we don't search public metadata because that would require two sql queries
      geomInfo.setPrivateValues(
        PrivateMetadata.CONNECTION, configConnectionName,
        PrivateMetadata.SQLSCHEMA, sqlSchema,
        PrivateMetadata.SQLTABLEPREFIX, sqlTablePrefix
      );
     
      // check for existing geometry column using private metadata only
      int existingGeomId = ListUtils.getFirstSortedItem(
          dataConfig.searchPrivateMetadata(geomInfo.privateMetadata, null),
          DataConfig.NULL
        );
      if (existingGeomId != DataConfig.NULL)
      {
        // see if the existing geometry column has the same parent table
        boolean foundSameTableId = false;
        for (int parentId : dataConfig.getParentIds(existingGeomId))
          if (parentId == tableId)
            foundSameTableId = true;
        // if it does not have the same parent table, clear the existingGeomId
        // so a new column entity will be created under the new table
        if (!foundSameTableId)
          existingGeomId = DataConfig.NULL;
      }
     
      // set the new public metadata
      geomInfo.setPublicValues(
          PublicMetadata.ENTITYTYPE, EntityType.COLUMN,
          PublicMetadata.DATATYPE, DataType.GEOMETRY,
          PublicMetadata.KEYTYPE, configKeyType,
          PublicMetadata.PROJECTION, projectionSRS
      );
     
      if (existingGeomId == DataConfig.NULL)
      {
        // we only update the title if the column doesn't already exist
        geomInfo.setPublicValues(PublicMetadata.TITLE, configTitle);
        // create new column
        dataConfig.newEntity(geomInfo, tableId, 0);
      }
      else
      {
View Full Code Here

      for (int iRow = 1; iRow < rows.length; iRow++) // skip header row
        loader.addRow((Object[])rows[iRow]);
      loader.flush();
      SQLUtils.cleanup(conn);

            DataEntityMetadata tableInfo = new DataEntityMetadata();
            tableInfo.setPrivateValues(
              PrivateMetadata.IMPORTMETHOD, "importCSV",
              PrivateMetadata.FILENAME, csvFile,
              PrivateMetadata.KEYCOLUMN, csvKeyColumn
            );
      int table_id = addConfigDataTable(
View Full Code Here

      throw new RemoteException("SQL schema must be specified.");
    if (Strings.isEmpty(tableName))
      throw new RemoteException("SQL table must be specified.");
   
    String[] columnNames = getSQLColumnNames(connectionName, password, schemaName, tableName);
        DataEntityMetadata tableInfo = new DataEntityMetadata();
         tableInfo.setPrivateValues(PrivateMetadata.IMPORTMETHOD, "importSQL");
         int[] filterColumnIndices = null;
         if (filterColumnNames != null)
         {
           filterColumnIndices = new int[filterColumnNames.length];
           for (int i = 0; i < filterColumnNames.length; i++)
View Full Code Here

 
  public WeaveRecordList getRows(String keyType, String[] keysArray) throws RemoteException
  {
    DataConfig dataConfig = getDataConfig();
   
    DataEntityMetadata params = new DataEntityMetadata();
    params.setPublicValues(
        PublicMetadata.ENTITYTYPE, EntityType.COLUMN,
        PublicMetadata.KEYTYPE, keyType
      );
    List<Integer> columnIds = new ArrayList<Integer>( dataConfig.searchPublicMetadata(params.publicMetadata, null) );
View Full Code Here

          String tableName = resultSet.getString(OLD_METADATA_COLUMN_ID);
          String property = resultSet.getString(OLD_METADATA_COLUMN_PROPERTY);
          String value = resultSet.getString(OLD_METADATA_COLUMN_VALUE);
         
          if (!tableMetadataLookup.containsKey(tableName))
            tableMetadataLookup.put(tableName, new DataEntityMetadata());
          DataEntityMetadata metadata = tableMetadataLookup.get(tableName);
          // discard empty values
          if (value != null && value.length() != 0)
            metadata.publicMetadata.put(property, value);
        }
        SQLUtils.cleanup(resultSet);
      }
     
      progress.beginStep("Migrating to new config format", 0, 0, geomTotal + attrTotal);
     
      /////////////////////////////
      // migrate geometry collections
     
      resultSet = stmt.executeQuery(String.format("SELECT * FROM %s", quotedGeometryConfigTable));
            resultSet.setFetchSize(fetchSize);
      columnNames = SQLUtils.getColumnNamesFromResultSet(resultSet);
      while (resultSet.next())
      {
        Map<String,String> geomRecord = getRecord(resultSet, columnNames);
       
        // save name-to-keyType mapping for later
        String name = geomRecord.get(PublicMetadata_NAME);
        String keyType = geomRecord.get(PublicMetadata.KEYTYPE);
        geomKeyTypeLookup.put(name, keyType);
       
        // copy "name" to "title"
        geomRecord.put(PublicMetadata.TITLE, name);
        // set dataType appropriately
        geomRecord.put(PublicMetadata.DATATYPE, DataType.GEOMETRY);
        // rename "schema" to "sqlSchema"
        geomRecord.put(PrivateMetadata.SQLSCHEMA, geomRecord.remove(PrivateMetadata_SCHEMA));
        // rename "tablePrefix" to "sqlTablePrefix"
        geomRecord.put(PrivateMetadata.SQLTABLEPREFIX, geomRecord.remove(PrivateMetadata_TABLEPREFIX));
       
        // create an entity for the geometry column
        DataEntityMetadata geomMetadata = toColumnMetadata(geomRecord);
        int tableId = getTableId(name);
        dataConfig.newEntity(geomMetadata, tableId, order++);
       
        progress.tick();
        autoFlush();
      }
      SQLUtils.cleanup(resultSet);
     
      /////////////////////////////
      // migrate columns
     
      resultSet = stmt.executeQuery(String.format("SELECT * FROM %s", quotedDataConfigTable));
            resultSet.setFetchSize(fetchSize);
      columnNames = SQLUtils.getColumnNamesFromResultSet(resultSet);
      while (resultSet.next())
      {
        Map<String,String> columnRecord = getRecord(resultSet, columnNames);
       
        // if key type isn't specified but geometryCollection is, use the keyType of the geometry collection.
        String keyType = columnRecord.get(PublicMetadata.KEYTYPE);
        String geom = columnRecord.get(PublicMetadata_GEOMETRYCOLLECTION);
        if (Strings.isEmpty(keyType) && !Strings.isEmpty(geom))
          columnRecord.put(PublicMetadata.KEYTYPE, geomKeyTypeLookup.get(geom));
       
        // make sure title is set
        if (Strings.isEmpty(columnRecord.get(PublicMetadata.TITLE)))
        {
          String name = columnRecord.get(PublicMetadata_NAME);
          String year = columnRecord.get(PublicMetadata_YEAR);
          String title = Strings.isEmpty(year) ? name : String.format("%s (%s)", name, year);
          columnRecord.put(PublicMetadata.TITLE, title);
        }
       
        // get the id corresponding to the table
        String dataTableName = columnRecord.get(PublicMetadata_DATATABLE);
                if (dataTableName == null)
                {
                    throw new RemoteException("Datatable field missing on column " + columnRecord.toString());
                }
       
                // create the column entity as a child of the table
                DataEntityMetadata columnMetadata = toColumnMetadata(columnRecord);
                int tableId = getTableId(dataTableName);
        dataConfig.newEntity(columnMetadata, tableId, order++);
        progress.tick();
        autoFlush();
      }
View Full Code Here

      tableId = tableIdLookup.get(tableName);
    }
    else
    {
      // lazily create table metadata
      DataEntityMetadata metadata = tableMetadataLookup.get(tableName);
      if (metadata == null)
      {
        metadata = new DataEntityMetadata();
        metadata.setPublicValues(PublicMetadata.ENTITYTYPE, EntityType.TABLE);
      }
     
      // copy tableName to "title" property if missing
      if (metadata.publicMetadata.get(PublicMetadata.TITLE) == null) // use get() instead of containsKey() because value may be null
        metadata.publicMetadata.put(PublicMetadata.TITLE, tableName);
View Full Code Here

    return record;
  }
 
  private static DataEntityMetadata toColumnMetadata(Map<String,String> record)
  {
    DataEntityMetadata result = new DataEntityMetadata();
    for (String field : record.keySet())
    {
      String value = record.get(field);
      if (Strings.isEmpty(value))
        continue;
      if (fieldIsPrivate(field))
        result.privateMetadata.put(field, value);
      else
        result.publicMetadata.put(field, value);
    }
    result.setPublicValues(PublicMetadata.ENTITYTYPE, EntityType.COLUMN);
    return result;
  }
View Full Code Here

TOP

Related Classes of weave.config.DataConfig.DataEntityMetadata

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.