Package commonj.sdo

Examples of commonj.sdo.DataObject


         
          "DataObject customerType = scope.getDataFactory().create(\"commonj.sdo\", \"Type\");\n"+
          "customerType.set(\"uri\", \"http://example.com/customer\");\n"+
          "customerType.set(\"name\", \"Customer\");");
     
      DataObject customerType = scope.getDataFactory().create("commonj.sdo", "Type");
      customerType.set("uri", "http://example.com/customer");
      customerType.set("name", "Customer");
     
      commentary("Now we can create a model for the Properties for the Type\n"+
          "and set the name and Types of those Properties\n\n"+
          "DataObject custNumProperty = customerType.createDataObject(\"property\");\n"+
          "custNumProperty.set(\"name\", \"custNum\");\n"+
          "custNumProperty.set(\"type\", intType);"
      );
     
      DataObject custNumProperty = customerType.createDataObject("property");
      custNumProperty.set("name", "custNum");
      custNumProperty.set("type", intType);
     
      commentary("We continue in this manner until all the Types and their Properties are modelled");
      DataObject lastNameProperty = customerType.createDataObject("property");
      lastNameProperty.set("name", "lastName");
      lastNameProperty.set("type", stringType);
     
      DataObject firstNameProperty = customerType.createDataObject("property");
      firstNameProperty.set("name", "firstName");
      firstNameProperty.set("type", stringType);
     
      commentary("Now that our type is fully modelled we submit the model to the TypeHelper\n"+
          "The new Type instance is retuend to us,  but is also available for lookup within\n"+
          "the scope associated with the TypeHelper\n\n"+
          "Type t = typeHelper.define(customerType);");
      Type t = typeHelper.define(customerType);
     
      commentary("Here we see the newly created Type being accessed via the TypeHelper\n"+
          "along with a printout of the Type's Properties\n\n"+
          "Type testType = scope.getTypeHelper().getType(\"http://example.com/customer\", \"Customer\");");
     
      Type testType = scope.getTypeHelper().getType("http://example.com/customer", "Customer");
      List props = testType.getProperties();
      for (int i = 0; i < props.size(); i++) {
          System.out.println(props.get(i));
      }

      commentary("Now we can create an instance of the type using the DataFactory associated with the type scope\n\n"+
          "DataFactory factory = scope.getDataFactory();\n"+
          "DataObject customer1 = factory.create(\"http://example.com/customer\", \"Customer\");");

      DataFactory factory = scope.getDataFactory();
      DataObject customer1 = factory.create("http://example.com/customer", "Customer");
      customer1.setInt("custNum", 1);
      customer1.set("firstName", "John");
      customer1.set("lastName", "Adams");

      commentary("Here's an XML String representing a DataObject we have created with the new type");
      String xmlDocString = scope.getXMLHelper().save(customer1, CUSTOMER_NAMESPACE, "customer");
      System.out.println(xmlDocString);
View Full Code Here


        commentary(
            "First we create the type system using an XML Schema file and then create\n"+
            "A DataObject using an XML document for convenience");
       
        loadTypesFromXMLSchemaFile(scope, SampleInfrastructure.PO_XSD_RESOURCE);
        DataObject purchaseOrder = getDataObjectFromFile(scope, SampleInfrastructure.PO_XML_RESOURCE);



        commentary(
            "Accessing data from the purchase order using the DataObjects XPath style methods\n");
       

        System.out.println("First we use the simplest kind of path\n" +
            "purchaseOrder.getString(\"billTo/name\")\n" +
            "The purchase is to be paid for by .... " +
            purchaseOrder.getString("billTo/name"));
       
       
        System.out.println("\nThen we use indexing by integer starting from 1\n" +
            "purchaseOrder.getString(\"items/item[1]/productName\"\n" +
            "The first item in the order is a ... " +
            purchaseOrder.getString("items/item[1]/productName"));
       
      
        System.out.println("\nThe alternative style of indexing uses a . notation and starts from 0\n"+
            "purchaseOrder.getFloat(\"items/item.0/price\")\n" +
            "The price of this item is ... " +
            purchaseOrder.getFloat("items/item.0/price"));
       

        System.out.println("\nDataObjects can be looked up by supplying the value of one of the contained simple valued Properties\n"+
            "DataObject babyMonitorItem = purchaseOrder.getDataObject(\"items/item[productName=\\\"Baby Monitor\\\"]");
               
        DataObject babyMonitorItem = purchaseOrder.getDataObject("items/item[productName=\"Baby Monitor\"]");
        System.out.println("The price of the Baby Monitor is .... " +
        babyMonitorItem.getFloat("price"));
       
       
        System.out.println("\nA parent DataObject can be accessed with the .. notation\n"+
            "List onlyIfBuyingGrassSeed = purchaseOrder.getList(\"items/item[productName=GrassSeed]/../item\");");
        List onlyIfBuyingGrassSeed = purchaseOrder.getList("items/item[productName=GrassSeed]/../item");
View Full Code Here

            Command select = das.createCommand("SELECT firstName, lastName, loginID, password, id FROM customers where loginID = ?");

            select.setParameter(1, logonID);

            DataObject root = select.executeQuery();
            conn.close();

            Collection customers = root.getList("CustomerProfileData");
            CustomerProfileData customerProfileData = (CustomerProfileData) customers.iterator().next();

            return customerProfileData;
        } catch (Exception e) {
View Full Code Here

        try {
            DAS das = DAS.FACTORY.createDAS(createConfigStream(), getConnection());
            Command read = das.getCommand("all customers");

            // select.setDataObjectModel();
            DataObject root = read.executeQuery();

            // Create a new stockPurchase
            DataObject customer = root.createDataObject("customerProfileData");

            // THIS SEEMS TO BE THE ONLY WAY TO DO THIS .. NO WAY TO JUST ADD AN EXISTING CUSTOMER.
            customer.set("firstName", customerProfile.getFirstName());
            customer.set("lastName", customerProfile.getLastName());
            customer.set("address", customerProfile.getAddress());
            customer.set("email", customerProfile.getEmail());
            customer.set("loginID", customerProfile.getLoginID());
            customer.set("password", customerProfile.getPassword());

            das.applyChanges(root);
            return getCustomerProfile(customerProfile.getLoginID());

        } catch (Exception e) {
View Full Code Here

            DAS das = DAS.FACTORY.createDAS(mapping, conn);

            Command select = das.createCommand("SELECT accountNumber, accountType, balance FROM accounts where id = ?");
            select.setParameter(1, customerID);

            DataObject root = select.executeQuery();
            accountReport.getAccountSummaries().addAll(root.getList("AccountSummary"));

            // Get Stocks

            select = das.createCommand("SELECT Symbol, quantity, purchasePrice, purchaseDate, purchaseLotNumber  FROM stocks where id = ?");
            select.setParameter(1, customerID);

            // select.addConverter("STOCKS.PURCHASEDATE", DateConverter.class.getName());

            root = select.executeQuery();
            accountReport.getStockSummaries().addAll(root.getList("StockSummary"));

            conn.close();

            return accountReport;
        } catch (Exception e) {
View Full Code Here

            DAS das = DAS.FACTORY.createDAS(createConfigStream(), conn);

            Command select = das.createCommand("SELECT accountNumber, balance FROM accounts where accountNumber = ?");
            select.setParameter(1, account);

            DataObject root = select.executeQuery();
            Collection accounts = root.getList("AccountSummary");
            AccountSummary accountData = (AccountSummary) accounts.iterator().next();
            float newbalance = accountData.getBalance() + ammount;
            accountData.setBalance(newbalance);
            // update department set companyid = ? where department.name = ?
View Full Code Here

        try {
            DAS das = DAS.FACTORY.createDAS(createConfigStream(), getConnection());

            Command read = das.getCommand("stockbylotSelect");
            read.setParameter(1, purchaseLotNumber);// autoboxing :-)
            DataObject root = read.executeQuery();
            List stocks = root.getList("StockSummary");
            if (null != stocks && !stocks.isEmpty()) {
                StockSummary stock = (StockSummary) stocks.get(0);
                int newQuatity = Math.max(stock.getQuantity() - quantity, 0);
                if (newQuatity < 1) {
View Full Code Here

        DAS das = DAS.FACTORY.createDAS(createConfigStream(), conn);
        Command select = das.getCommand("get account");

        select.setParameter(1, wd.getAccountNumber());

        DataObject root = select.executeQuery();

        Collection accounts = root.getList("AccountSummary");
        AccountSummary account = (AccountSummary) accounts.iterator().next();
        float newbalance = account.getBalance() - wd.getAmount();
        account.setBalance(newbalance);
        // update department set companyid = ? where department.name = ?
View Full Code Here

            SQLException {

        DAS das = DAS.FACTORY.createDAS(createConfigStream(), createConnection());
        Command read = das.getCommand("all stocks");

        DataObject root = read.executeQuery();

        // Create a new stockPurchase
        DataObject stockPurchase = root.createDataObject("StockSummary");
        stockPurchase.set("id", new Integer(sp.getId()));
        stockPurchase.set("symbol", sp.getStock().getSymbol());
        stockPurchase.set("quantity", new Integer(sp.getStock().getQuantity()));
        stockPurchase.set("purchasePrice", new Float(11.00));
        // String type = stockPurchase.getType().getProperty("purchaseDate").getType().toString();
        stockPurchase.setDate("purchaseDate", new Date());

        das.applyChanges(root);
    }
View Full Code Here

        DAS das = DAS.FACTORY.createDAS(mapping, conn);
        Command select = das.createCommand("SELECT firstName, lastName, loginID, password, id FROM customers where loginID = ?");

        select.setParameter(1, logonID);

        DataObject root = select.executeQuery();
        conn.close();

        Collection customers = root.getList("CustomerProfileData");
        CustomerProfileData customerProfileData = (CustomerProfileData) customers.iterator().next();
        System.out.println(customerProfileData);
        System.out.flush();
        return customerProfileData;
View Full Code Here

TOP

Related Classes of commonj.sdo.DataObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.