@Override public Customer createCustomerFromId(Long customerId) { Customer customer = customerId != null ? readCustomerById(customerId) : null; if (customer == null) { customer = customerDao.create(); if (customerId != null) { customer.setId(customerId); } else { customer.setId(findNextCustomerId()); } } return customer; }
@Override @Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER) public Customer registerCustomer(Customer customer, String password, String passwordConfirm) { customer.setRegistered(true); // When unencodedPassword is set the save() will encode it if (customer.getId() == null) { customer.setId(findNextCustomerId()); } customer.setUnencodedPassword(password); Customer retCustomer = saveCustomer(customer); createRegisteredCustomerRoles(retCustomer); HashMap<String, Object> vars = new HashMap<String, Object>(); vars.put("customer", retCustomer); sendEmail(customer.getEmailAddress(), getRegistrationEmailInfo(), vars); notifyPostRegisterListeners(retCustomer); return retCustomer; }
@Override public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); try { PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective(); Customer adminInstance = (Customer) Class.forName(entity.getType()[0]).newInstance(); adminInstance.setId(customerService.findNextCustomerId()); Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective); adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false); if (useEmailForLogin) { adminInstance.setUsername(adminInstance.getEmailAddress()); } Entity errorEntity = validateUniqueUsername(entity, adminInstance, true); if (errorEntity != null) { return errorEntity; } adminInstance = dynamicEntityDao.merge(adminInstance); customerService.createRegisteredCustomerRoles(adminInstance); Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null); return adminEntity; } catch (Exception e) { LOG.error("Unable to execute persistence activity", e); throw new ServiceException("Unable to add entity for " + entity.getType()[0], e); } }
protected void onHandleIntent(Intent intent) { Realm realm = null; try { realm = Realm.getDefaultInstance(); final List<Customer> customers = SampleCustomerData.getCustomers(); realm.executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) { for (Customer customer: customers){ customer.setId(customerPrimaryKey.getAndIncrement()); realm.insert(customer); } } }); } finally { if(realm != null) { realm.close(); } } }
public void addCustomer(final Customer customer) { final Realm insertRealm = Realm.getDefaultInstance(); insertRealm.executeTransactionAsync(new Realm.Transaction() { @Override public void execute(Realm backgroundRealm) { long id = customerPrimaryKey.incrementAndGet(); customer.setId(id); backgroundRealm.copyToRealm(customer); } }, new Realm.Transaction.OnSuccess() { @Override public void onSuccess() { Log.d(LOG_TAG, "Customer Added"); insertRealm.close(); } }, new Realm.Transaction.OnError() { @Override public void onError(Throwable error) { Log.d(LOG_TAG, error.getMessage()); insertRealm.close(); } }); }
@Override public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); try { PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective(); Customer adminInstance = (Customer) Class.forName(entity.getType()[0]).newInstance(); adminInstance.setId(customerService.findNextCustomerId()); Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective); adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false); if (customerService.readCustomerByUsername(adminInstance.getUsername()) != null) { Entity error = new Entity(); error.addValidationError("username", "nonUniqueUsernameError"); return error; } adminInstance = (Customer) dynamicEntityDao.merge(adminInstance); Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null); return adminEntity; } catch (Exception e) { LOG.error("Unable to execute persistence activity", e); throw new ServiceException("Unable to add entity for " + entity.getType()[0], e); } }