Example usage for org.apache.commons.lang NullArgumentException NullArgumentException

List of usage examples for org.apache.commons.lang NullArgumentException NullArgumentException

Introduction

In this page you can find the example usage for org.apache.commons.lang NullArgumentException NullArgumentException.

Prototype

public NullArgumentException(String argName) 

Source Link

Document

Instantiates with the given argument name.

Usage

From source file:org.normandra.orientdb.data.OrientDatabaseSession.java

@Override
public void delete(final EntityMeta meta, final Object element) throws NormandraException {
    if (null == meta) {
        throw new NullArgumentException("entity metadata");
    }//from  w ww. j  a v a2 s. c  om
    if (null == element) {
        throw new NullArgumentException("element");
    }

    try (final Transaction tx = this.beginTransaction()) {
        final Map<ColumnMeta, Object> datamap = new LinkedHashMap<>();
        for (final ColumnMeta column : meta.getPrimaryKeys()) {
            final ColumnAccessor accessor = meta.getAccessor(column);
            final Object value = accessor != null ? accessor.getValue(element, this) : null;
            if (value != null) {
                datamap.put(column, value);
            }
        }
        final OIdentifiable rid = this.findIdByMap(meta, datamap);
        if (rid != null) {
            this.database.delete(rid.getIdentity());
        }

        tx.success();

        final Object key = meta.getId().fromEntity(element);
        this.cache.remove(meta, key);
    } catch (final Exception e) {
        throw new NormandraException("Unable to delete orientdb document.", e);
    }
}

From source file:org.normandra.orientdb.data.OrientDatabaseSession.java

@Override
public boolean exists(final EntityMeta meta, final Object key) throws NormandraException {
    if (null == meta) {
        throw new NullArgumentException("entity meta");
    }// www .j a  v  a 2s  .co  m
    if (null == key) {
        return false;
    }

    try {
        return this.findIdByKey(meta, key) != null;
    } catch (final Exception e) {
        throw new NormandraException("Unable to query orientdb document.", e);
    }
}

From source file:org.normandra.orientdb.data.OrientDatabaseSession.java

@Override
public Object get(final EntityMeta meta, final Object key) throws NormandraException {
    if (null == meta) {
        throw new NullArgumentException("entity meta");
    }//from   ww  w.  j  a v a2s.  c o  m
    if (null == key) {
        return null;
    }

    final Object existing = this.cache.get(meta, key, Object.class);
    if (existing != null) {
        if (existing instanceof OrientNode) {
            return ((OrientNode) existing).getEntity();
        } else if (existing instanceof OrientEdge) {
            return ((OrientEdge) existing).getEntity();
        } else {
            return existing;
        }
    }

    try {
        final Map<ColumnMeta, Object> data = new LinkedHashMap<>();
        final OIdentifiable rid = this.findIdByKey(meta, key);
        final ODocument document = this.findDocument(rid);
        if (document != null) {
            data.putAll(OrientUtils.unpackValues(meta, document));
            if (meta.validate(data)) {
                final EntityBuilder builder = new EntityBuilder(this, new OrientDataFactory(this));
                final Object instance = builder.build(meta, data);
                this.cache.put(meta, key, instance);
                return instance;
            }
        }
    } catch (final Exception e) {
        throw new NormandraException("Unable to get orientdb document by key [" + key + "].", e);
    }

    // not found
    return null;
}

From source file:org.normandra.orientdb.data.OrientDatabaseSession.java

@Override
public List<Object> get(final EntityMeta meta, final Object... keys) throws NormandraException {
    if (null == meta) {
        throw new NullArgumentException("entity meta");
    }/*from w w w  .  j av  a2 s  .  co  m*/
    if (null == keys || keys.length <= 0) {
        return Collections.emptyList();
    }

    // query meta
    final Set<Object> keyset = new HashSet<>(Arrays.asList(keys));
    final Map<Object, Object> cached = this.cache.find(meta, Arrays.asList(keys), Object.class);
    final List<Object> cachedElements;
    keyset.removeAll(cached.keySet());
    try {
        cachedElements = cached.values().stream().map((x) -> {
            try {
                if (x instanceof OrientNode) {
                    return ((OrientNode) x).getEntity();
                } else if (x instanceof OrientEdge) {
                    return ((OrientEdge) x).getEntity();
                } else {
                    return x;
                }
            } catch (final NormandraException e) {
                throw new IllegalStateException("Unable to unpack entities.", e);
            }
        }).collect(Collectors.toList());
        if (keyset.isEmpty()) {
            return Collections.unmodifiableList(cachedElements);
        }
    } catch (final Exception e) {
        throw new NormandraException("Unable to map and unpack entities.", e);
    }

    // query ids for each entity meta
    final Map<Object, Map<ColumnMeta, Object>> entityData = new HashMap<>();
    for (final OIdentifiable rid : this.findIdByKeys(meta, keyset)) {
        final ODocument document = this.findDocument(rid);
        if (document != null) {
            final Map<ColumnMeta, Object> data = OrientUtils.unpackValues(meta, document);
            final Object key = meta.getId().toKey(data);
            if (key != null) {
                Map<ColumnMeta, Object> datamap = entityData.get(key);
                if (null == datamap) {
                    datamap = new LinkedHashMap<>();
                    entityData.put(key, datamap);
                }
                datamap.putAll(data);
            }
        }
    }

    // build entities
    final List<Object> result = new ArrayList<>(cachedElements);
    for (final Map.Entry<Object, Map<ColumnMeta, Object>> entry : entityData.entrySet()) {
        final Map<ColumnMeta, Object> data = entry.getValue();
        if (meta.validate(data)) {
            final EntityBuilder builder = new EntityBuilder(this, new OrientDataFactory(this));
            final Object instance = builder.build(meta, data);
            if (instance != null) {
                final Object key = meta.getId().fromData(data);
                this.cache.put(meta, key, instance);
                result.add(instance);
            }
        }
    }
    return Collections.unmodifiableList(result);
}

From source file:org.normandra.orientdb.data.OrientElementIdentity.java

public OrientElementIdentity(final EntityMeta entity) {
    if (null == entity) {
        throw new NullArgumentException("entity context");
    }/*from   w  ww .j  ava  2 s.  co  m*/
    this.entity = entity;
}

From source file:org.normandra.orientdb.graph.OrientEdge.java

public OrientEdge(final OrientGraph graph, final com.tinkerpop.blueprints.impls.orient.OrientEdge edge,
        final EntityMeta meta, final EntityReference<T> ref) {
    if (null == graph) {
        throw new NullArgumentException("graph");
    }//from w  w  w .jav  a 2  s .co  m
    if (null == edge) {
        throw new NullArgumentException("edge");
    }
    if (null == ref) {
        throw new NullArgumentException("reference");
    }
    this.graph = graph;
    this.edge = edge;
    this.meta = meta;
    this.data = ref;
}

From source file:org.normandra.orientdb.graph.OrientEdgeQuery.java

public OrientEdgeQuery(final OrientGraph db, final OrientSelfClosingQuery query) {
    if (null == db) {
        throw new NullArgumentException("database");
    }/*from   ww w.  ja  v a 2  s. c  o  m*/
    if (null == query) {
        throw new NullArgumentException("query");
    }
    this.graph = db;
    this.delegate = query;
}

From source file:org.normandra.orientdb.graph.OrientEntityReference.java

public OrientEntityReference(final OrientGraph graph, final EntityMeta meta, final OIdentifiable rid) {
    if (null == graph) {
        throw new NullArgumentException("graph");
    }/*from   w ww  . j ava 2  s  . c o m*/
    if (null == meta) {
        throw new NullArgumentException("entity meta");
    }
    if (null == rid) {
        throw new NullArgumentException("rid");
    }
    this.graph = graph;
    this.meta = meta;
    this.record = rid;
}

From source file:org.normandra.orientdb.graph.OrientNode.java

public OrientNode(final OrientGraph graph, final com.tinkerpop.blueprints.impls.orient.OrientVertex vertex,
        final EntityMeta meta, final EntityReference<T> ref) {
    if (null == graph) {
        throw new NullArgumentException("graph");
    }/*from  www . ja  va2 s .  c o  m*/
    if (null == vertex) {
        throw new NullArgumentException("vertex");
    }
    if (null == ref) {
        throw new NullArgumentException("reference");
    }
    this.graph = graph;
    this.vertex = vertex;
    this.meta = meta;
    this.data = ref;
}

From source file:org.normandra.orientdb.graph.OrientNode.java

@Override
public <E, N> boolean hasEdge(final Node<N> node, final E entity) throws NormandraException {
    if (null == node) {
        throw new NullArgumentException("node");
    }/*from  w  w  w. j  a  va 2 s . co  m*/
    if (!(node instanceof OrientNode)) {
        throw new IllegalArgumentException("Node not of type orientdb - found [" + node + "].");
    }
    if (null == entity) {
        return false;
    }

    final EntityMeta meta = this.graph.getMeta().getEdgeMeta(entity.getClass());
    if (null == meta) {
        return false;
    }

    final Object key = meta.getId().fromEntity(entity);
    return this.graph.exists(meta, key);
}