/** * Create a new asset category. * * @param context * @param request * @return * @throws SiteWhereException */ public static AssetCategory createAssetCategory(IHBaseContext context, IAssetCategoryCreateRequest request) throws SiteWhereException { if (getAssetCategoryById(context, request.getId()) != null) { throw new SiteWhereSystemException(ErrorCode.AssetCategoryIdInUse, ErrorLevel.ERROR); } // Add new key to table. String id = KEY_BUILDER.getMap(context).useExistingId(request.getId()); // Use common logic so all backend implementations work the same. AssetCategory category = SiteWherePersistence.assetCategoryCreateLogic(request); Map<byte[], byte[]> qualifiers = new HashMap<byte[], byte[]>(); return HBaseUtils.createOrUpdate(context, context.getPayloadMarshaler(), ISiteWhereHBase.ASSETS_TABLE_NAME, category, id, KEY_BUILDER, qualifiers); }
@Override public IAssetCategory createAssetCategory(IAssetCategoryCreateRequest request) throws SiteWhereException { // Use common logic so all backend implementations work the same. AssetCategory category = SiteWherePersistence.assetCategoryCreateLogic(request); MongoCollection<Document> categories = getMongoClient().getAssetCategoriesCollection(getTenant()); Document created = MongoAssetCategory.toDocument(category); MongoPersistence.insert(categories, created, ErrorCode.AssetCategoryIdInUse); // Update cache with new data. if (getCacheProvider() != null) { getCacheProvider().getAssetCategoryCache().put(category.getId(), category); } return MongoAssetCategory.fromDocument(created); }