private Application saveApplication(Application application) throws DatastoreException { Mutator mutator = Pelops.createMutator(schemaName); mutator.writeColumns( "applications", application.getBareJid(), mutator.newColumnList( mutator.newColumn(Bytes.fromUTF8("appId"), Bytes.fromUTF8(application.getAppId())), mutator.newColumn( Bytes.fromUTF8("platformId"), Bytes.fromUTF8(application.getPlatform())), mutator.newColumn(Bytes.fromUTF8("name"), Bytes.fromUTF8(application.getName())), mutator.newColumn( Bytes.fromUTF8("accountId"), Bytes.fromUTF8(application.getAccountId())), mutator.newColumn( Bytes.fromUTF8("permissions"), Bytes.fromUTF8(application.getPermissions())))); try { mutator.execute(ConsistencyLevel.ONE); log.debug("Application [%s] stored successfully", application); } catch (Exception e) { log.error(e.getMessage(), e); throw new DatastoreException(String.format("Could not create application [%s]", application)); } return application; }
@Override public Application updateApplication(Application application) throws DatastoreException { log.debug("Updating application: [%s]", application); if (getApplication(application.getBareJid()) == null) { log.error("Application [%s] does not exist", application); throw new ApplicationNotFoundException(); } return saveApplication(application); }
@Override public Application storeApplication(Application application) throws DatastoreException { log.debug("Storing application: [%s]", application); if (getApplication(application.getBareJid()) != null) { log.error("Application [%s] already exists", application); throw new ApplicationAlreadyExistsException(); } return saveApplication(application); }