Search code examples
intuit-partner-platformquickbooks-online

What causes a lock on an entity table in QuickBooks Online API?


I'm trying to optimize my application to perform at maximum speed. I intended on having two threads each executing a batch request of sales receipts additions. I also intended on having two parallel threads each with a batch request of customer additions. I was wondering whether this is possible or would the API lock the sales receipt/customer table in QuickBooks thus only allowing one thread to perform.

From my research I know that there a three types of entities (Name list, transaction and supporting entities). So what are the causes of locks on these entities, ie what scenario's will cause a lock? Is there any documentation on this matter I couldn't seem to find any?

Thanks


Solution

  • Lock is applicable for Name entities(Vendor, Customer and Employee ). While creating a new name entity, service ensures that an unique name is getting inserted in cloud. So, it puts a lock across all names of these 3 entities.

    You can try this scenario using a decent payload.

    public static void main(String args[]) {
        PropertyConfigurator
                .configure("log4j.properties");
        Config.setProperty(Config.SERIALIZATION_REQUEST_FORMAT, "xml");
        Config.setProperty(Config.SERIALIZATION_RESPONSE_FORMAT, "xml");
    
        final Context platformContext = getPlatformContext("QBO");  
        final QBOV3ProdTest qbov3ProdTest = new QBOV3ProdTest(platformContext);
    
        Thread customerThread = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 15; i++) {
                    qbov3ProdTest.addCustomer();
                }
            }
        });
        customerThread.start();
    
        Thread vendorThread = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 15; i++) {
                    qbov3ProdTest.addVendor();
                }
            }
        });
        vendorThread.start();
    
    }
    
    private void addCustomer() {
        Customer customer = new Customer();
        customer.setDisplayName("TestCustomer-" + staticCount++);
        try {
            this.service.add(customer);
        } catch (FMSException e) {
            e.printStackTrace();
        }
    }
    
    private void addVendor() {
        Vendor vendor = new Vendor();
        vendor.setDisplayName("TestVendor-" + staticCount++);
        try {
            this.service.add(vendor);
        } catch (FMSException e) {
            e.printStackTrace();
        }
    }
    

    Service doesn't return a proper response. Wherever it fails, service returns 401. Please let me know if you can reproduce this behaviour while trying this use-case in your test QBO account.

    Thanks