Package com.github.jmkgreen.morphia

Examples of com.github.jmkgreen.morphia.Datastore


                        mapr.getDatastoreProvider());
                ProxiedEntityReferenceList referencesAsProxy = (ProxiedEntityReferenceList) references;

                if (dbVal instanceof List) {
                    List<DBRef> refList = (List) dbVal;
                    Datastore dsi = mapr.getDatastoreProvider().get();
                    List<Key<Object>> keys = dsi.getKeysByRefs(refList);

                    if (keys.size() != refList.size()) {
                        String msg = "Some of the references could not be fetched for " + mf.getFullName() + ". "
                                + refList + " != " + keys;
                        if (!refAnn.ignoreMissing())
View Full Code Here


        Key key = mapr.refToKey(dbRef);
        Boolean cached = cache.exists(key);
        if (cached != null)
            return cached;

        Datastore dsi = mapr.getDatastoreProvider().get();

        DBCollection dbColl = dsi.getCollection(c);
        if (!dbColl.getName().equals(dbRef.getRef()))
            log.warning("Class " + c.getName() + " is stored in the '" + dbColl.getName()
                    + "' collection but a reference was found for this type to another collection, '" + dbRef.getRef()
                    + "'. The reference will be loaded using the class anyway. " + dbRef);
        boolean exists = (dsi.find(dbRef.getRef(), c).disableValidation().filter("_id", dbRef.getId()).asKeyList()
                .size() == 1);
        cache.notifyExists(key, exists);
        return exists;
    }
View Full Code Here

     *
     */
    private static final long serialVersionUID = 1L;

    public Datastore get() {
        final Datastore datastore = DatastoreHolder.getInstance().get();
        if (datastore == null) {
            throw new IllegalStateException(
                    "DatastoreHolder does not carry a Datastore.");
        }
        return datastore;
View Full Code Here

        // List<T> retrievedEntities = p.get().getByKeys(referenceObjClass,
        // (List) __getKeysAsList());

        // so we do it the lousy way: FIXME
        List<T> retrievedEntities = new ArrayList<T>(listOfKeys.size());
        Datastore ds = p.get();
        for (Key<?> k : listOfKeys) {
            retrievedEntities.add((T) ds.getByKey(referenceObjClass, k));
        }

        if (!ignoreMissing && (numberOfEntitiesExpected != retrievedEntities.size())) {
            throw new LazyReferenceFetchingException("During the lifetime of a proxy of type '"
                    + c.getClass().getSimpleName() + "', some referenced Entities of type '"
View Full Code Here

            ((Collection<T>) object).clear();
        }
    }

    private void syncKeys() {
        Datastore ds = p.get();

        listOfKeys.clear();
        for (Object e : ((Collection) object)) {
            listOfKeys.add(ds.getMapper().getKey(e));
        }
    }
View Full Code Here

            ((Map) object).clear();
        }
    }

    private void syncKeys() {
        Datastore ds = p.get();

        this.keyMap.clear();
        Map<Object, Object> map = (Map) object;
        for (Map.Entry<Object, Object> e : map.entrySet()) {
            keyMap.put(e.getKey(), ds.getMapper().getKey(e.getValue()));
        }
    }
View Full Code Here

                final List<String> l = FileUtils.readLines(f, "UTF-8");
                log.debug("tot line:" + l.size());


                final Datastore ds = MongoConnectionHelper.ds;

                log.debug("hasHeader: " + hasHeader);
                int lineCount = 0;
                int lineDouble = 0;
                for (String s : l) {

                    if (hasHeader) {
                        hasHeader = false;
                        continue;
                    }

                    final String[] columns = s.split(";");
                    List<Meteolog> check = ds.createQuery(Meteolog.class).field("time").equal(getDate("dd-MM-yyyy HH:mm", columns[1], log)).asList();

                    if (check != null && !check.isEmpty()) {
                        log.debug("data exist, continue");
                        lineDouble++;
                        continue;
                    }
                   
                    final Meteolog meteoLog = new Meteolog();
                    try {
                        meteoLog.setN(Integer.valueOf(columns[0]));
                    } catch (Exception e) {
                        log.error("line skipped " + lineCount, e);
                        continue;
                    }

                    try {
                        meteoLog.setTime(getDate("dd-MM-yyyy HH:mm", columns[1], log));
                    } catch (Exception e) {
                        log.error("line skipped" + lineCount, e);
                        continue;
                    }


                    try {
                        meteoLog.setInterval(Integer.valueOf(columns[2]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setIndoorHumidity(Double.valueOf(columns[3]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setIndoorTemperature(Double.valueOf(columns[4]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setOutdoorHumidity(Double.valueOf(columns[5]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setOutdoorTemperature(Double.valueOf(columns[6]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setAbsolutePressure(Double.valueOf(columns[7]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setWind(Double.valueOf(columns[8]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setGust(Double.valueOf(columns[9]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setDirection(columns[10]);
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setRelativePressure(Double.valueOf(columns[11]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setDewpoint(Double.valueOf(columns[12]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setWindChill(Double.valueOf(columns[13]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setHourRainfall(Double.valueOf(columns[14]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setDayRainfall(Double.valueOf(columns[15]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setWeekRainfall(Double.valueOf(columns[16]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setMonthRainfall(Double.valueOf(columns[17]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setTotalRainfall(Double.valueOf(columns[18]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setWindLevel(Double.valueOf(columns[19]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }


                    try {
                        meteoLog.setGustLevel(Double.valueOf(columns[20]));
                    } catch (Exception e) {
                        log.error("line " + lineCount, e);
                    }

                    ds.save(meteoLog, WriteConcern.NORMAL);
                    lineCount++;

                }

                log.debug("Tot line insert:" + lineCount);
View Full Code Here

     * @param reduce
     * @param log
     */
    protected static void runMapReduceMinMax(String file, String reduce, Logger log) {

        final Datastore ds = MongoConnectionHelper.ds;

        final String map = getJsFromFile(file, log);
        final MapreduceResults<MapReduceMinMax> mrRes = ds.mapReduce(MapreduceType.MERGE, ds.createQuery(Meteolog.class), map, reduce, null, null, MapReduceMinMax.class);

        log.debug(
                "mrRes --> count all:" + mrRes.createQuery().countAll());
        log.debug(
                "mrRes --> tot time: " + mrRes.getElapsedMillis());
View Full Code Here

     * @param reduce
     * @param log
     */
    protected static void runMapReduceHisotryMinMax(String file, String reduce, Logger log) {

        final Datastore ds = MongoConnectionHelper.ds;

        final String map = getJsFromFile(file, log);
        final MapreduceResults<MapReduceHistoryMinMax> mrRes = ds.mapReduce(MapreduceType.MERGE, ds.createQuery(Meteolog.class), map, reduce, null, null, MapReduceHistoryMinMax.class);

        log.debug("mrRes --> count all:" + mrRes.createQuery().countAll());
        log.debug("mrRes --> tot time: " + mrRes.getElapsedMillis());
    }
View Full Code Here

    /**
     *
     * @param log
     */
    public static void deleteCache(Logger log) {
        final Datastore ds = MongoConnectionHelper.ds;
        ds.getCollection(Cache.class).drop();
        MongoConnectionHelper.getGridCol().drop();
    }
View Full Code Here

TOP

Related Classes of com.github.jmkgreen.morphia.Datastore

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.