Search in sources :

Example 1 with ModifiableRelation

use of de.lmu.ifi.dbs.elki.database.relation.ModifiableRelation in project elki by elki-project.

the class HashmapDatabase method insert.

@Override
public DBIDs insert(ObjectBundle objpackages) {
    if (objpackages.dataLength() == 0) {
        return DBIDUtil.EMPTYDBIDS;
    }
    // insert into db
    ArrayModifiableDBIDs newids = DBIDUtil.newArray(objpackages.dataLength());
    Relation<?>[] targets = alignColumns(objpackages);
    DBIDVar var = DBIDUtil.newVar();
    for (int j = 0; j < objpackages.dataLength(); j++) {
        // insert object
        if (!objpackages.assignDBID(j, var)) {
            var.set(DBIDUtil.generateSingleDBID());
        }
        if (ids.contains(var)) {
            throw new AbortException("Duplicate DBID conflict.");
        }
        ids.add(var);
        for (int i = 0; i < targets.length; i++) {
            if (!(targets[i] instanceof ModifiableRelation)) {
                throw new AbortException("Non-modifiable relations have been added to the database.");
            }
            @SuppressWarnings("unchecked") final ModifiableRelation<Object> relation = (ModifiableRelation<Object>) targets[i];
            relation.insert(var, objpackages.data(j, i));
        }
        newids.add(var);
    }
    // fire insertion event
    eventManager.fireObjectsInserted(newids);
    return newids;
}
Also used : ModifiableRelation(de.lmu.ifi.dbs.elki.database.relation.ModifiableRelation) Relation(de.lmu.ifi.dbs.elki.database.relation.Relation) MaterializedRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation) DBIDVar(de.lmu.ifi.dbs.elki.database.ids.DBIDVar) ModifiableRelation(de.lmu.ifi.dbs.elki.database.relation.ModifiableRelation) ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Aggregations

ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)1 DBIDVar (de.lmu.ifi.dbs.elki.database.ids.DBIDVar)1 MaterializedRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation)1 ModifiableRelation (de.lmu.ifi.dbs.elki.database.relation.ModifiableRelation)1 Relation (de.lmu.ifi.dbs.elki.database.relation.Relation)1 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)1