Load the RTree Spatial Index Values

@param tableName
table name
@param geometryColumnName
geometry column name
@param idColumnName
id column name
349405
public void loadRTreeIndex(String tableName, String geometryColumnName,
			String idColumnName) {

		String sqlName = GeoPackageProperties.getProperty(SQL_PROPERTY,
				LOAD_PROPERTY);
		executeSQL(sqlName, tableName, geometryColumnName, idColumnName);
	}
121145
@Override
	public int update(GeometryColumnsSqlMm geometryColumns) throws SQLException {

		UpdateBuilder<GeometryColumnsSqlMm, TableColumnKey> ub = updateBuilder();
		ub.updateColumnValue(GeometryColumnsSqlMm.COLUMN_GEOMETRY_TYPE_NAME,
				geometryColumns.getGeometryTypeName());
		ub.updateColumnValue(GeometryColumnsSqlMm.COLUMN_SRS_ID,
				geometryColumns.getSrsId());
		// Don't update srs name since it is in another table

		ub.where()
				.eq(GeometryColumnsSqlMm.COLUMN_TABLE_NAME,
						geometryColumns.getTableName())
				.and()
				.eq(GeometryColumnsSqlMm.COLUMN_COLUMN_NAME,
						geometryColumns.getColumnName());

		PreparedUpdate<GeometryColumnsSqlMm> update = ub.prepare();
		int updated = update(update);

		return updated;
	}
566122
public static void deleteRTreeSpatialIndex(GeoPackageCore geoPackage,
			String table) {

		RTreeIndexCoreExtension rTreeIndexExtension = getRTreeIndexExtension(geoPackage);
		if (rTreeIndexExtension.has(table)) {
			rTreeIndexExtension.delete(table);
		}

	}
25138
@Override
    public void index(ByteBuffer key, ColumnFamily columnFamily) {
        Log.debug("Indexing row %s in index %s ", key, logName);
        lock.readLock().lock();
        try {
            if (rowService != null) {
                long timestamp = System.currentTimeMillis();
                rowService.index(key, columnFamily, timestamp);
            }
        } catch (RuntimeException e) {
            Log.error("Error while indexing row %s", key);
            throw e;
        } finally {
            lock.readLock().unlock();
        }
    }
848645
public void createDeleteTrigger(String tableName,
			String geometryColumnName, String idColumnName) {

		String sqlName = GeoPackageProperties.getProperty(TRIGGER_PROPERTY,
				TRIGGER_DELETE_NAME);
		executeSQL(sqlName, tableName, geometryColumnName, idColumnName);
	}
200664
private void loadPlanNodesFromJSONArrays(int stmtId, JSONArray jArray, Database db) {
        List<AbstractPlanNode> planNodes = new ArrayList<>();
        int size = jArray.length();

        try {
            for (int i = 0; i < size; i++) {
                JSONObject jobj = jArray.getJSONObject(i);
                String nodeTypeStr = jobj.getString("PLAN_NODE_TYPE");
                PlanNodeType nodeType = PlanNodeType.get(nodeTypeStr);
                AbstractPlanNode apn = nodeType.getPlanNodeClass().newInstance();
                apn.loadFromJSONObject(jobj, db);
                planNodes.add(apn);
            }

            //link children and parents
            for (int i = 0; i < size; i++) {
                JSONObject jobj = jArray.getJSONObject(i);
                if (jobj.has("CHILDREN_IDS")) {
                    AbstractPlanNode parent = planNodes.get(i);
                    JSONArray children = jobj.getJSONArray("CHILDREN_IDS");
                    for (int j = 0; j < children.length(); j++) {
                        AbstractPlanNode child = getNodeofId(children.getInt(j), planNodes);
                        parent.addAndLinkChild(child);
                    }
                }
            }
            m_planNodesListMap.put(stmtId,  planNodes);
        }
        catch (JSONException | InstantiationException | IllegalAccessException e) {
            System.err.println(e);
            e.printStackTrace();
        }
    }
909988
@Override
    public <E> List<E> getColumnsById(String schemaName, String tableName, String pKeyColumnName,
            String inverseJoinColumnName, Object pKeyColumnValue, Class columnJavaType)
    {
        List<E> foreignKeys = new ArrayList<E>();

        URI uri = null;
        HttpResponse response = null;
        try
        {
            String q = "key=" + CouchDBUtils.appendQuotes(pKeyColumnValue);
            uri = new URI(CouchDBConstants.PROTOCOL, null, httpHost.getHostName(), httpHost.getPort(),
                    CouchDBConstants.URL_SEPARATOR + schemaName.toLowerCase() + CouchDBConstants.URL_SEPARATOR
                            + CouchDBConstants.DESIGN + tableName + CouchDBConstants.VIEW + pKeyColumnName, q, null);
            HttpGet get = new HttpGet(uri);
            get.addHeader("Accept", "application/json");
            response = httpClient.execute(get);

            InputStream content = response.getEntity().getContent();
            Reader reader = new InputStreamReader(content);
            JsonObject json = gson.fromJson(reader, JsonObject.class);

            JsonElement jsonElement = json.get("rows");

            if (jsonElement == null)
            {
                return foreignKeys;
            }

            JsonArray array = jsonElement.getAsJsonArray();
            for (JsonElement element : array)
            {
                JsonElement value = element.getAsJsonObject().get("value").getAsJsonObject().get(inverseJoinColumnName);
                if (value != null)
                {
                    foreignKeys.add((E) PropertyAccessorHelper.fromSourceToTargetClass(columnJavaType, String.class,
                            value.getAsString()));
                }
            }
        }
        catch (Exception e)
        {
            log.error("Error while fetching column by id {}, Caused by {}.", pKeyColumnValue, e);
            throw new KunderaException(e);
        }
        finally
        {
            closeContent(response);
        }
        return foreignKeys;
    }
1291461
private void loadIndexInMemory() throws Exception {
		long start = System.currentTimeMillis();
		System.out.println("Loading persistent index in memory.");

		DatabaseEntry foundKey = new DatabaseEntry();
		DatabaseEntry foundData = new DatabaseEntry();

		ForwardCursor cursor = null;
		if (useDiskOrderedCursor) { // disk ordered cursor
			DiskOrderedCursorConfig docc = new DiskOrderedCursorConfig();
			cursor = iidToVectorDB.openCursor(docc);
		} else {
			cursor = iidToVectorDB.openCursor(null, null);
		}

		int counter = 0;
		while (cursor.getNext(foundKey, foundData, null) == OperationStatus.SUCCESS
				&& counter < maxNumVectors) {
			TupleInput input = TupleBinding.entryToInput(foundData);
			double[] vector = new double[vectorLength];
			for (int i = 0; i < vectorLength; i++) {
				vector[i] = input.readDouble();
			}
			// update ram based index
			vectorsList.add(vector);
			counter++;
			if (counter % 1000 == 0) {
				System.out.println(counter + " vectors loaded in memory!");
			}
		}
		cursor.close();
		long end = System.currentTimeMillis();
		System.out.println(counter + " vectors loaded in " + (end - start) + " ms!");
	}
1199647
public void insertGeometry( String tableName, Geometry geometry, String epsg ) throws Exception {
        String epsgStr = "4326";
        if (epsg == null) {
            epsgStr = epsg;
        }

        GeometryColumn gc = getGeometryColumnsForTable(tableName);
        String sql = "INSERT INTO " + tableName + " (" + gc.geometryColumnName + ") VALUES (ST_GeomFromText(?, " + epsgStr + "))";

        execOnConnection(connection -> {
            try (IHMPreparedStatement pStmt = connection.prepareStatement(sql)) {
                pStmt.setString(1, geometry.toText());
                pStmt.executeUpdate();
            }
            return null;
        });

    }
655450
public void loadTable() {

        m_container.removeAllItems();
        List<I_CmsSearchIndex> indexes = m_manager.getAllElements();

        for (I_CmsSearchIndex index : indexes) {
            Item item = m_container.addItem(index);
            item.getItemProperty(TableProperty.Name).setValue(index.getName());
            item.getItemProperty(TableProperty.FieldConfig).setValue(index.getFieldConfiguration().getName());
            item.getItemProperty(TableProperty.Locale).setValue(index.getLocale().getDisplayName());
            item.getItemProperty(TableProperty.Project).setValue(index.getProject());
            item.getItemProperty(TableProperty.Rebuild).setValue(index.getRebuildMode());
        }
    }
596102
public void getTablesAndIndexes(Map<String, StmtTargetTableScan> tablesRead,
            Collection<String> indexes)
    {
        for (AbstractPlanNode node : m_inlineNodes.values()) {
            node.getTablesAndIndexes(tablesRead, indexes);
        }
        for (AbstractPlanNode node : m_children) {
            node.getTablesAndIndexes(tablesRead, indexes);
        }
        getTablesAndIndexesFromSubqueries(tablesRead, indexes);
    }
397191
public void setGridTable(String keyAreaName, Rec gridTable, int index)
    {
        if (index == -1)
            index = m_iNextArrayIndex;  // Next available
        m_iNextArrayIndex = Math.max(m_iNextArrayIndex, index+1);
        if (gridTable == null) if (m_gridScreen != null)
            gridTable = m_gridScreen.getMainRecord();
        if (gridTable != null) if (m_gridScreen != null) if (gridTable != m_gridScreen.getMainRecord())
        {
            if (m_gridScreen.getMainRecord() instanceof QueryRecord)
            {
                int keyIndex = ((QueryRecord)m_gridScreen.getMainRecord()).setGridFile((Record)gridTable, keyAreaName);    // Sets the key order and gridtable (even if only one file)
                keyAreaName = gridTable.getKeyArea(keyIndex).getKeyName();
            }
        }
        m_iKeyAreaArray[index] = keyAreaName;
    }
1373370
public GeometryIndex populate(TableIndex tableIndex, long geomId,
			GeometryEnvelope envelope) {

		GeometryIndex geometryIndex = new GeometryIndex();
		geometryIndex.setTableIndex(tableIndex);
		geometryIndex.setGeomId(geomId);
		geometryIndex.setMinX(envelope.getMinX());
		geometryIndex.setMaxX(envelope.getMaxX());
		geometryIndex.setMinY(envelope.getMinY());
		geometryIndex.setMaxY(envelope.getMaxY());
		if (envelope.hasZ()) {
			geometryIndex.setMinZ(envelope.getMinZ());
			geometryIndex.setMaxZ(envelope.getMaxZ());
		}
		if (envelope.hasM()) {
			geometryIndex.setMinM(envelope.getMinM());
			geometryIndex.setMaxM(envelope.getMaxM());
		}
		return geometryIndex;
	}
1240835
function(table, feature, i){
    if (feature.geometry && feature.geometry.coordinates && feature.geometry.coordinates.length ){
      feature.geometry.crs = {"type":"name","properties":{"name":"EPSG:4326"}};
      //return 'insert into "'+table+'" (feature, geom) VALUES (\''+JSON.stringify(feature).replace(/'/g, "")+'\', ST_GeomFromGeoJSON(\''+JSON.stringify(feature.geometry)+'\'));' ;
      return 'insert into "'+table+'" (feature) VALUES (\''+JSON.stringify(feature).replace(/'/g, "")+'\');' ;
    } else {
      return 'insert into "'+table+'" (feature) VALUES (\''+JSON.stringify(feature).replace(/'/g, "")+'\');' ;
    }
  }
9050
@Override
  protected void bulkLoad(List<E> spatialObjects) {
    if(!initialized) {
      initialize(spatialObjects.get(0));
    }

    StringBuilder msg = getLogger().isDebuggingFine() ? new StringBuilder() : null;

    // Tiny tree that fits into a single page
    if(spatialObjects.size() <= leafCapacity) {
      N root = createNewLeafNode();
      root.setPageID(getRootID());
      writeNode(root);
      createRoot(root, spatialObjects);
      setHeight(1);
      if(msg != null) {
        msg.append("\n  numNodes = 1");
      }
    }
    // root is directory node
    else {
      N root = createNewDirectoryNode();
      root.setPageID(getRootID());
      writeNode(root);

      // create leaf nodes
      List<E> nodes = createBulkLeafNodes(spatialObjects);

      int numNodes = nodes.size();
      if(msg != null) {
        msg.append("\n  numLeafNodes = ").append(numNodes);
      }
      setHeight(1);

      // create directory nodes
      while(nodes.size() > (dirCapacity - 1)) {
        nodes = createBulkDirectoryNodes(nodes);
        numNodes += nodes.size();
        setHeight(getHeight() + 1);
      }

      // create root
      createRoot(root, nodes);
      numNodes++;
      setHeight(getHeight() + 1);
      if(msg != null) {
        msg.append("\n  numNodes = ").append(numNodes);
      }
    }
    if(msg != null) {
      msg.append("\n  height = ").append(getHeight());
      msg.append("\n  root ").append(getRoot());
      getLogger().debugFine(msg.toString());
    }
  }
246154
private static void nodesTable(Statement st,
                                   TableLocation nodesName,
                                   double tolerance, boolean isH2, int srid) throws SQLException {
        LOGGER.info("Creating the nodes table...");
        // Creating nodes table by removing copies from the pts table.
        if (tolerance > 0) {
            if(isH2){
            st.execute("CREATE TABLE " + nodesName + "(" +
                    "NODE_ID SERIAL PRIMARY KEY, " +
                    "THE_GEOM POINT, " +
                    "EXP POLYGON" +
                    ") AS " +
                    "SELECT NULL, A.THE_GEOM, A.AREA FROM "+ PTS_TABLE + " as A," + PTS_TABLE +" as B " +
                    "WHERE A.AREA && B.AREA " +
                    "GROUP BY A.ID " +
                    "HAVING A.ID=MIN(B.ID);");
            }
            else{
               st.execute("CREATE TABLE " + nodesName + "(" +
                    "NODE_ID SERIAL PRIMARY KEY, " +
                    "THE_GEOM GEOMETRY(POINT, " + srid+"), "+
                    "EXP GEOMETRY(POLYGON," +srid+")"+
                    ") " );
                st.execute( "INSERT INTO "+nodesName +" (SELECT (row_number() over())::int , c.the_geom, c.area FROM (SELECT  A.THE_GEOM, A.AREA FROM "+ PTS_TABLE +" as  A, "+ PTS_TABLE +" as B " +
                    "WHERE A.AREA && B.AREA " +
                    "GROUP BY A.ID " +
                    "HAVING A.ID=MIN(B.ID)) as c);"); 
            }
        } else {
            
            if(isH2){
               // If the tolerance is zero, we can create the NODES table
            // by using = rather than &&.
            st.execute("CREATE TABLE " + nodesName + "(" +
                    "NODE_ID SERIAL PRIMARY KEY, " +
                    "THE_GEOM POINT" +
                    ") AS " +
                    "SELECT NULL, A.THE_GEOM FROM "+ PTS_TABLE + " as A," + PTS_TABLE + " as B " +
                    "WHERE A.THE_GEOM && B.THE_GEOM AND A.THE_GEOM=B.THE_GEOM " +
                    "GROUP BY A.ID " +
                    "HAVING A.ID=MIN(B.ID);"); 
            }
            else{
            // If the tolerance is zero, we can create the NODES table
            // by using = rather than &&.
            st.execute("CREATE TABLE " + nodesName + "(" +
                    "NODE_ID SERIAL PRIMARY KEY, " +
                    "THE_GEOM GEOMETRY(POINT, "+srid+")" +
                    ") " );            
            st.execute("INSERT INTO "+nodesName +" (SELECT (row_number() over())::int , c.the_geom FROM (SELECT A.THE_GEOM FROM "+ PTS_TABLE + " as A," + PTS_TABLE + " as B " +
                    "WHERE A.THE_GEOM && B.THE_GEOM AND A.THE_GEOM=B.THE_GEOM " +
                    "GROUP BY A.ID " +
                    "HAVING A.ID=MIN(B.ID)) as c);");
            }
        }
    }
421223
public TableIndex getTableIndex() {

		TableIndex tableIndex = null;
		try {
			if (tableIndexDao.isTableExists()) {
				tableIndex = tableIndexDao.queryForId(tableName);
			}
		} catch (SQLException e) {
			throw new GeoPackageException(
					"Failed to query for Table Index for GeoPackage: "
							+ geoPackage.getName() + ", Table Name: "
							+ tableName + ", Column Name: " + columnName, e);
		}
		return tableIndex;
	}