Example usage for com.mongodb BasicDBObject getBoolean

List of usage examples for com.mongodb BasicDBObject getBoolean

Introduction

In this page you can find the example usage for com.mongodb BasicDBObject getBoolean.

Prototype

public boolean getBoolean(final String key) 

Source Link

Document

Returns the value of a field as a boolean.

Usage

From source file:org.canedata.provider.mongodb.entity.MongoEntity.java

License:Apache License

/**
 * @param projection will be ignored in mongodb.
 *///w w w . j a  va 2  s . c o  m
public Number count(String projection) {
    if (logger.isDebug())
        logger.debug("Listing entities, Database is {0}, Collection is {1}, offset is {2}, count is {3}.",
                getSchema(), getName(), 0, 1);
    BasicDBObject options = new BasicDBObject();

    try {
        validateState();

        MongoExpressionFactory expFactory = new MongoExpressionFactory.Impl();

        IntentParser.parse(getIntent(), expFactory, null, null, null, null, options);

        BasicDBObject query = expFactory.toQuery();
        if (query == null || query.isEmpty())
            return getCollection().count();
        else
            return getCollection().count(query);
    } catch (AnalyzeBehaviourException abe) {
        if (logger.isDebug())
            logger.debug(abe, "Analyzing behaviour failure, cause by: {0}.", abe.getMessage());

        throw new RuntimeException(abe);
    } finally {
        if (!options.getBoolean(Options.RETAIN))
            getIntent().reset();
    }
}

From source file:org.canedata.provider.mongodb.entity.MongoEntity.java

License:Apache License

public List<Fields> distinct(String projection) {
    if (logger.isDebug())
        logger.debug("Distincting entities, Database is {0}, Collection is {1}, column is {2} ...", getSchema(),
                getName(), projection);//from w  w w  .ja  va2  s .co m
    List<Fields> rlt = new ArrayList<Fields>();
    BasicDBObject options = new BasicDBObject();

    try {
        validateState();

        MongoExpressionFactory expFactory = new MongoExpressionFactory.Impl();

        IntentParser.parse(getIntent(), expFactory, null, null, null, null, options);

        BasicDBObject query = expFactory.toQuery();

        List r = getCollection().distinct(projection, query);
        for (Object o : r) {
            BasicDBObject dbo = new BasicDBObject();
            dbo.put(projection, o);
            rlt.add(new MongoFields(this, getIntent(), projection, o));
        }
    } catch (AnalyzeBehaviourException abe) {
        if (logger.isDebug())
            logger.debug(abe, "Analyzing behaviour failure, cause by: {0}.", abe.getMessage());

        throw new RuntimeException(abe);
    } finally {
        if (!options.getBoolean(Options.RETAIN))
            getIntent().reset();
    }

    return rlt;
}

From source file:org.graylog2.system.stats.mongo.MongoProbe.java

License:Open Source License

private HostInfo createHostInfo() {
    final HostInfo hostInfo;
    final CommandResult hostInfoResult = adminDb.command("hostInfo");
    if (hostInfoResult.ok()) {
        final BasicDBObject systemMap = (BasicDBObject) hostInfoResult.get("system");
        final HostInfo.System system = HostInfo.System.create(new DateTime(systemMap.getDate("currentTime")),
                systemMap.getString("hostname"), systemMap.getInt("cpuAddrSize"),
                systemMap.getLong("memSizeMB"), systemMap.getInt("numCores"), systemMap.getString("cpuArch"),
                systemMap.getBoolean("numaEnabled"));
        final BasicDBObject osMap = (BasicDBObject) hostInfoResult.get("os");
        final HostInfo.Os os = HostInfo.Os.create(osMap.getString("type"), osMap.getString("name"),
                osMap.getString("version"));

        final BasicDBObject extraMap = (BasicDBObject) hostInfoResult.get("extra");
        final HostInfo.Extra extra = HostInfo.Extra.create(extraMap.getString("versionString"),
                extraMap.getString("libcVersion"), extraMap.getString("kernelVersion"),
                extraMap.getString("cpuFrequencyMHz"), extraMap.getString("cpuFeatures"),
                extraMap.getString("scheduler"), extraMap.getLong("pageSize", -1l),
                extraMap.getLong("numPages", -1l), extraMap.getLong("maxOpenFiles", -1l));

        hostInfo = HostInfo.create(system, os, extra);
    } else {//from ww  w  . j a v  a2  s  . co m
        hostInfo = null;
    }

    return hostInfo;
}

From source file:org.graylog2.system.stats.mongo.MongoProbe.java

License:Open Source License

public MongoStats mongoStats() {
    final List<ServerAddress> serverAddresses = mongoClient.getServerAddressList();
    final List<HostAndPort> servers = Lists.newArrayListWithCapacity(serverAddresses.size());
    for (ServerAddress serverAddress : serverAddresses) {
        servers.add(HostAndPort.fromParts(serverAddress.getHost(), serverAddress.getPort()));
    }/*from  www.j  a  va2s.  co m*/

    final DatabaseStats dbStats;
    final CommandResult dbStatsResult = db.command("dbStats");
    if (dbStatsResult.ok()) {
        final BasicDBObject extentFreeListMap = (BasicDBObject) dbStatsResult.get("extentFreeList");
        final DatabaseStats.ExtentFreeList extentFreeList = DatabaseStats.ExtentFreeList
                .create(extentFreeListMap.getInt("num"), extentFreeListMap.getInt("totalSize"));

        final BasicDBObject dataFileVersionMap = (BasicDBObject) dbStatsResult.get("dataFileVersion");
        final DatabaseStats.DataFileVersion dataFileVersion = DatabaseStats.DataFileVersion
                .create(dataFileVersionMap.getInt("major"), dataFileVersionMap.getInt("minor"));

        dbStats = DatabaseStats.create(dbStatsResult.getString("db"), dbStatsResult.getLong("collections"),
                dbStatsResult.getLong("objects"), dbStatsResult.getDouble("avgObjSize"),
                dbStatsResult.getLong("dataSize"), dbStatsResult.getLong("storageSize"),
                dbStatsResult.getLong("numExtents"), dbStatsResult.getLong("indexes"),
                dbStatsResult.getLong("indexSize"), dbStatsResult.getLong("fileSize"),
                dbStatsResult.getLong("nsSizeMB"), extentFreeList, dataFileVersion);
    } else {
        dbStats = null;
    }

    final ServerStatus serverStatus;
    final CommandResult serverStatusResult = adminDb.command("serverStatus");
    if (serverStatusResult.ok()) {
        final BasicDBObject connectionsMap = (BasicDBObject) serverStatusResult.get("connections");
        final ServerStatus.Connections connections = ServerStatus.Connections.create(
                connectionsMap.getInt("current"), connectionsMap.getInt("available"),
                connectionsMap.getLong("totalCreated"));

        final BasicDBObject networkMap = (BasicDBObject) serverStatusResult.get("network");
        final ServerStatus.Network network = ServerStatus.Network.create(networkMap.getInt("bytesIn"),
                networkMap.getInt("bytesOut"), networkMap.getInt("numRequests"));

        final BasicDBObject memoryMap = (BasicDBObject) serverStatusResult.get("mem");
        final ServerStatus.Memory memory = ServerStatus.Memory.create(memoryMap.getInt("bits"),
                memoryMap.getInt("resident"), memoryMap.getInt("virtual"), memoryMap.getBoolean("supported"),
                memoryMap.getInt("mapped"), memoryMap.getInt("mappedWithJournal"));

        serverStatus = ServerStatus.create(serverStatusResult.getString("host"),
                serverStatusResult.getString("version"), serverStatusResult.getString("process"),
                serverStatusResult.getLong("pid"), serverStatusResult.getInt("uptime"),
                serverStatusResult.getLong("uptimeMillis"), serverStatusResult.getInt("uptimeEstimate"),
                new DateTime(serverStatusResult.getDate("localTime")), connections, network, memory);
    } else {
        serverStatus = null;
    }

    // TODO Collection stats? http://docs.mongodb.org/manual/reference/command/collStats/

    return MongoStats.create(servers, buildInfo, hostInfo, serverStatus, dbStats);
}

From source file:org.sdsai.dsds.mongo.MongoUtils.java

License:Open Source License

public static Object getPrimitive(final BasicDBObject dbo, final String fieldName, final Class<?> returnType)
        throws Exception {
    final boolean contained = dbo.containsField(fieldName);

    if (Boolean.TYPE.equals(returnType))
        return contained ? dbo.getBoolean(fieldName) : Boolean.FALSE;

    if (Short.TYPE.equals(returnType) || Byte.TYPE.equals(returnType) || Integer.TYPE.equals(returnType))
        return (Integer) (contained ? dbo.getInt(fieldName) : 0);

    if (Character.TYPE.equals(returnType))
        return (Character) ((dbo.get(fieldName) + "").charAt(0));

    if (Long.TYPE.equals(returnType))
        return (Long) (contained ? dbo.getLong(fieldName) : 0L);

    if (Float.TYPE.equals(returnType))
        return (Float) (contained ? Float.valueOf(dbo.get(fieldName) + "") : 0F);

    if (Double.TYPE.equals(returnType))
        return (Double) (contained ? dbo.getDouble(fieldName) : 0D);

    return null;//from   w w  w .j a  va2  s  .  c o  m
}

From source file:pl.nask.hsn2.os.ObjectStore.java

License:Open Source License

private Builder getBuilder(String key, BasicDBObject objectFound) {
    Object value = objectFound.get(key);
    Builder builder = Attribute.newBuilder().setName(key);

    if (value instanceof Integer || key.equalsIgnoreCase("depth")) {
        builder.setType(Type.INT).setDataInt(objectFound.getInt(key));
    } else if (value instanceof Long) {
        builder.setType(Type.OBJECT).setDataObject(objectFound.getLong(key));
    } else if (value instanceof BasicDBObject) {

        BasicDBObject mongoObj = (BasicDBObject) value;
        if (mongoObj.get("type").equals("TIME")) {
            builder.setType(Type.TIME).setDataTime(mongoObj.getLong("time"));
        } else if (mongoObj.get("type").equals("BYTES")) {
            builder.setType(Type.BYTES).setDataBytes(Reference.newBuilder().setKey(mongoObj.getLong("key"))
                    .setStore(mongoObj.getInt("store")).build());
        }/*from   w  ww.  j  a va2s . c o m*/
    } else if (value instanceof Boolean) {
        builder.setType(Type.BOOL).setDataBool(objectFound.getBoolean(key));
    } else {
        builder.setType(Type.STRING).setDataString(objectFound.getString(key));
    }
    return builder;
}

From source file:tango.parameter.BooleanParameter.java

License:Open Source License

@Override
public void dbGet(BasicDBObject DBO) {
    //System.out.println("Boolean:"+id);
    //System.out.println("DBO:"+DBO.get(id));
    if (DBO.containsField(id))
        setSelected(DBO.getBoolean(id));
}

From source file:tango.parameter.KeyParameter.java

License:Open Source License

@Override
public void dbGet(BasicDBObject DBO) {
    Object sd = DBO.get(id);/*  w w  w  .j a  v  a 2s .c o m*/
    if (sd != null) {
        BasicDBObject subDBO = (BasicDBObject) sd;
        key.setText(subDBO.getString("name"));
        checkbox.setSelected(subDBO.getBoolean("do"));
        type = subDBO.getInt("type", 0);
    }
}

From source file:Vistas.PanelFoto.java

@Override
public void rellenarCampos(BasicDBObject obj, int posi, int l) {
    if (obj.getString("nombre") == null) {
        Nombre.setText("-");
    } else {/*from  www. j av  a2 s  . co m*/
        Nombre.setText(obj.getString("nombre"));
    }
    if (obj.getString("marca") == null) {
        Marca.setText("-");
    } else {
        Marca.setText(obj.getString("marca"));
    }
    if (obj.getString("modelo") == null) {
        Modelo.setText("-");
    } else {
        Modelo.setText(obj.getString("modelo"));
    }
    if (obj.getString("Flash") == null) {
        Flash.setText("-");
    } else if (obj.getBoolean("Flash")) {
        Flash.setText("Si");
    } else {
        Flash.setText("No");
    }
    if (obj.getString("Photoshop") == null) {
        Photoshop.setText("-");
    } else if (obj.getBoolean("Photoshop")) {
        Photoshop.setText("Si");
    } else {
        Photoshop.setText("No");
    }
    if (obj.getString("fecha") == null) {
        Fecha.setText("-");
    } else {
        DateFormat dateFormatHora = new SimpleDateFormat("HH:mm");
        DateFormat dateFormatFecha = new SimpleDateFormat("dd/MM/yyyy");
        Date fechaTime = obj.getDate("fecha");
        String fecha = dateFormatFecha.format(fechaTime);
        String hora = dateFormatHora.format(fechaTime);
        Fecha.setText(fecha + " - " + hora);
    }

    BufferedImage originalImage = null;
    if (obj.getString("ruta") == null) {
        Foto.setText("-");
    } else {
        try {
            File f = new File(obj.getString("ruta") + "\\" + obj.getString("nombre"));
            if (f.isFile()) {
                originalImage = ImageIO.read(f);
                Image scaledImage = originalImage.getScaledInstance(250, 200, Image.SCALE_SMOOTH);
                ImageIcon icon = new ImageIcon(scaledImage);
                Foto.setIcon(icon);
            } else {
                Foto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagen/imageNotFound-2.jpg")));
            }
        } catch (IOException ex) {
            Logger.getLogger(PanelFoto.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    pos.setText((posi + 1) + "/" + (l));

}