List of usage examples for org.apache.commons.lang NullArgumentException NullArgumentException
public NullArgumentException(String argName)
Instantiates with the given argument name.
From source file:org.chililog.server.data.Controller.java
/** * Saves the user into mongoDB//from www .j a v a2s. com * * @param db * MongoDb connection * @param businessObject * Business object to save * @throws ChiliLogException * if there is an error during saving */ public void save(DB db, BO businessObject) throws ChiliLogException { if (db == null) { throw new NullArgumentException("db"); } if (businessObject == null) { throw new NullArgumentException("businessObject"); } try { DBObject obj = businessObject.toDBObject(); DBCollection coll = db.getCollection(this.getDBCollectionName()); if (businessObject.isExistingRecord()) { long recordVersion = businessObject.getDocumentVersion(); obj.put(BO.DOCUMENT_VERSION_FIELD_NAME, recordVersion + 1); BasicDBObject query = new BasicDBObject(); query.put(BO.DOCUMENT_ID_FIELD_NAME, obj.get(BO.DOCUMENT_ID_FIELD_NAME)); query.put(BO.DOCUMENT_VERSION_FIELD_NAME, recordVersion); coll.update(query, obj, false, false, this.getDBWriteConern()); } else { obj.put(BO.DOCUMENT_VERSION_FIELD_NAME, (long) 1); coll.insert(obj); } } catch (MongoException ex) { throw new ChiliLogException(ex, Strings.MONGODB_SAVE_ERROR, ex.getMessage()); } }
From source file:org.chililog.server.data.Controller.java
/** * Removes the specified business object form mongoDB * /* w w w . j a v a 2s .c o m*/ * @param db * MongoDb connection * @param businessObject * business object to remove from the database * @throws ChiliLogException * if there is any error during deleting */ public void remove(DB db, BO businessObject) throws ChiliLogException { if (db == null) { throw new NullArgumentException("db"); } if (businessObject == null) { throw new NullArgumentException("businessObject"); } try { DBCollection coll = db.getCollection(this.getDBCollectionName()); if (businessObject.isExistingRecord()) { DBObject obj = new BasicDBObject(); obj.put(BO.DOCUMENT_ID_FIELD_NAME, businessObject.getDocumentID()); coll.remove(obj); } } catch (MongoException ex) { throw new ChiliLogException(ex, Strings.MONGODB_REMOVE_ERROR, ex.getMessage()); } }
From source file:org.chililog.server.data.RepositoryEntryController.java
/** * Find matching entries// w w w . jav a 2s . co m * * @param db * Database connection * @param criteria * Criteria to filter resultset. Fields, conditions and orderby are used. * @return List of matching entries */ public ArrayList<DBObject> executeFindQuery(DB db, RepositoryEntryListCriteria criteria) throws ChiliLogException { try { if (db == null) { throw new NullArgumentException("db"); } if (criteria == null) { throw new NullArgumentException("criteria"); } DBCollection coll = db.getCollection(this.getDBCollectionName()); int recordsPerPage = criteria.getRecordsPerPage(); int skipDocumentCount = (criteria.getStartPage() - 1) * recordsPerPage; DBObject fields = criteria.getFieldsDbObject(); DBObject conditions = criteria.getConditionsDbObject(); DBObject orderBy = criteria.getOrderByDbObject(); DBCursor cur = coll.find(conditions, fields).skip(skipDocumentCount).limit(recordsPerPage) .sort(orderBy); ArrayList<DBObject> list = new ArrayList<DBObject>(); while (cur.hasNext()) { DBObject dbo = cur.next(); list.add(dbo); } // Do page count by executing query again if (criteria.getDoPageCount()) { int documentCount = coll.find(conditions).count(); criteria.calculatePageCount(documentCount); } return list; } catch (Exception ex) { throw new ChiliLogException(ex, Strings.MONGODB_QUERY_ERROR, ex.getMessage()); } }
From source file:org.chililog.server.data.RepositoryEntryController.java
/** * Count of number of entries that matches the condition * //from w w w. j a v a 2s .com * @param db * Database connection * @param criteria * Criteria to filter resultset. Condition is used. * @return Number of matching entries */ public int executeCountQuery(DB db, RepositoryEntryListCriteria criteria) throws ChiliLogException { try { if (db == null) { throw new NullArgumentException("db"); } if (criteria == null) { throw new NullArgumentException("criteria"); } DBCollection coll = db.getCollection(this.getDBCollectionName()); DBObject conditions = criteria.getConditionsDbObject(); return coll.find(conditions).count(); } catch (Exception ex) { throw new ChiliLogException(ex, Strings.MONGODB_QUERY_ERROR, ex.getMessage()); } }
From source file:org.chililog.server.data.RepositoryEntryController.java
/** * Count of number of entries that matches the condition * //from w ww . ja v a 2s. c om * @param db * Database connection * @param criteria * Criteria to filter resultset. Fields and Conditions is used. * @return List of distinct values for the nominated field. */ @SuppressWarnings("rawtypes") public List executeDistinctQuery(DB db, RepositoryEntryListCriteria criteria) throws ChiliLogException { try { if (db == null) { throw new NullArgumentException("db"); } if (criteria == null) { throw new NullArgumentException("criteria"); } DBCollection coll = db.getCollection(this.getDBCollectionName()); DBObject fields = criteria.getFieldsDbObject(); if (fields == null || fields.keySet().isEmpty()) { throw new IllegalArgumentException("Field is required for a 'distinct' query."); } String fieldName = null; for (String n : fields.keySet()) { fieldName = n; break; } DBObject conditions = criteria.getConditionsDbObject(); return coll.distinct(fieldName, conditions); } catch (Exception ex) { throw new ChiliLogException(ex, Strings.MONGODB_QUERY_ERROR, ex.getMessage()); } }
From source file:org.chililog.server.data.RepositoryEntryController.java
/** * Count of number of entries that matches the condition * // w ww . j av a 2s. c o m * @param db * Database connection * @param criteria * Criteria to filter resultset. Fields, Conditions, Initial, ReduceFunction and FinalizeFunction are * used. * @return Specified fields and aggregation counter. */ public DBObject executeGroupQuery(DB db, RepositoryEntryListCriteria criteria) throws ChiliLogException { try { if (db == null) { throw new NullArgumentException("db"); } if (criteria == null) { throw new NullArgumentException("criteria"); } DBCollection coll = db.getCollection(this.getDBCollectionName()); DBObject fields = criteria.getFieldsDbObject(); DBObject conditions = criteria.getConditionsDbObject(); DBObject initial = criteria.getIntialDbObject(); return coll.group(fields, conditions, initial, criteria.getReduceFunction(), criteria.getFinalizeFunction()); } catch (Exception ex) { throw new ChiliLogException(ex, Strings.MONGODB_QUERY_ERROR, ex.getMessage()); } }
From source file:org.chililog.server.engine.parsers.EntryParser.java
/** * <p>//from w ww . j a v a2 s . c o m * Basic constructor * </p> * * @param repoInfo * Repository (for reporting errors) * @param repoParserInfo * Parser information that we need * @throws ChiliLogException */ public EntryParser(RepositoryConfigBO repoInfo, RepositoryParserConfigBO repoParserInfo) { if (repoInfo == null) { throw new NullArgumentException("repoInfo is null"); } if (repoParserInfo == null) { throw new NullArgumentException("repoParserInfo is null"); } _repoName = repoInfo.getName(); _repoParserInfo = repoParserInfo; _maxKeywords = repoInfo.getStorageMaxKeywords(); if (repoParserInfo.getMaxKeywords() != RepositoryParserConfigBO.MAX_KEYWORDS_INHERITED) { _maxKeywords = repoParserInfo.getMaxKeywords(); } // Get our regular expression ready for matching source and host if (_repoParserInfo.getAppliesTo() == AppliesTo.AllowFilteredCSV) { if (!StringUtils.isBlank(_repoParserInfo.getAppliesToSourceFilter())) { _sourceCSV = _repoParserInfo.getAppliesToSourceFilter().split(","); for (int i = 0; i < _sourceCSV.length; i++) { _sourceCSV[i] = _sourceCSV[i].trim(); } } if (!StringUtils.isBlank(_repoParserInfo.getAppliesToHostFilter())) { _hostCSV = _repoParserInfo.getAppliesToHostFilter().split(","); for (int i = 0; i < _hostCSV.length; i++) { _hostCSV[i] = _hostCSV[i].trim(); } } } else if (_repoParserInfo.getAppliesTo() == AppliesTo.AllowFilteredRegularExpression) { if (!StringUtils.isBlank(_repoParserInfo.getAppliesToSourceFilter())) { _sourcePattern = Pattern.compile(_repoParserInfo.getAppliesToSourceFilter()); } if (!StringUtils.isBlank(_repoParserInfo.getAppliesToHostFilter())) { _hostPattern = Pattern.compile(_repoParserInfo.getAppliesToHostFilter()); } } // Dates for parsing timestamp _dateFormat = RepositoryEntryMqMessage.getDateFormatter(); // Tokenizer for keyword extraction _tokenizer = TextTokenizer.getInstance(); return; }
From source file:org.chililog.server.engine.parsers.EntryParserFactory.java
/** * Instances the correct entry parser// w w w .ja va2 s . co m * * @param repoInfo * Repository meta data * @param repoParserInfo * Parser meta data * @return Entry parser * @throws ChiliLogException */ public static EntryParser getParser(RepositoryConfigBO repoInfo, RepositoryParserConfigBO repoParserInfo) throws ChiliLogException { if (repoParserInfo == null) { throw new NullArgumentException("repoParserInfo"); } try { String className = repoParserInfo.getClassName(); if (className.equals(_delimitedEntryParserClassName)) { return new DelimitedEntryParser(repoInfo, repoParserInfo); } else if (className.equals(_regexEntryParserClassName)) { return new RegexEntryParser(repoInfo, repoParserInfo); } else if (className.equals(_jsonEntryParserClassName)) { return new JsonEntryParser(repoInfo, repoParserInfo); } // Use reflection to instance it Class<?> cls = ClassUtils.getClass(className); return (EntryParser) ConstructorUtils.invokeConstructor(cls, new Object[] { repoInfo, repoParserInfo }); } catch (Exception ex) { throw new ChiliLogException(ex, Strings.PARSER_FACTORY_ERROR, repoParserInfo.getName(), repoInfo.getName(), ex.getMessage()); } }
From source file:org.chililog.server.engine.Repository.java
/** * Constructor specifying the information needed to create a repository * /*from w w w . j a v a 2s . c o m*/ * @param repoInfo * Repository meta data */ public Repository(RepositoryConfigBO repoInfo) { if (repoInfo == null) { throw new NullArgumentException("repoInfo cannot be null"); } _repoConfig = repoInfo; _status = Status.OFFLINE; return; }
From source file:org.chililog.server.engine.Repository.java
/** * Updates the repository information/*from ww w. ja v a 2 s . c o m*/ * * @param repoConfig * new repository configuration * @throws ChiliLogException */ public void setRepoConfig(RepositoryConfigBO repoConfig) throws ChiliLogException { if (repoConfig == null) { throw new NullArgumentException("repoConfig cannot be null"); } if (_status != Status.OFFLINE) { throw new ChiliLogException(Strings.REPOSITORY_INFO_UPDATE_ERROR, _repoConfig.getName()); } _repoConfig = repoConfig; }