Examples of Contract


Examples of intrade.entities.Contract

    // stop here...
    if (contractsCP.contains("There is no data for download."))
      return true;

    PersistenceManager pm = PMF.get().getPersistenceManager();
    Contract c = pm.getObjectById(Contract.class, Contract.generateKeyFromID(contractid));
    Integer limit = c.getLastLineInsertedCSV();
    pm.close();

    if (limit == null)
      limit = 0;

    String[] entries = contractsCP.split("\n");

    if (entries.length > 2)
      print("Adding " + (entries.length - 1) + "entries, starting from " + limit + ", for contract " + contractid);

    ArrayList<ContractClosingPriceCSV> prices = new ArrayList<ContractClosingPriceCSV>();
    for (int i = limit; i < entries.length; i++) {
      if (entries[i].startsWith("Date"))
        continue;

      ContractClosingPriceCSV cp = parseContractClosingPriceCSV(entries[i], contractid);
      prices.add(cp);

      // Every 50 added prices, persist, update contract, and flush...

      if (i % 50 == 0) {
        pm = PMF.get().getPersistenceManager();
        pm.makePersistentAll(prices);
        Contract con = pm.getObjectById(Contract.class, Contract.generateKeyFromID(contractid));
        con.setLastLineInsertedCSV(i);
        pm.close();
        prices = new ArrayList<ContractClosingPriceCSV>();

      }

    }

    pm = PMF.get().getPersistenceManager();
    pm.makePersistentAll(prices);
    Contract con = pm.getObjectById(Contract.class, Contract.generateKeyFromID(contractid));
    con.setLastLineInsertedCSV(entries.length - 1);
    pm.close();

    return true;
  }
View Full Code Here

Examples of intrade.entities.Contract

      return true;

    }

    PersistenceManager pm = PMF.get().getPersistenceManager();
    Contract stored_con = pm.getObjectById(Contract.class, Contract.generateKeyFromID(contractid));

    Long now = (new Date()).getTime();
    if (fetchedTrades) {
      stored_con.setLastretrievedTrades(now);
    }

    pm.close();

    return true;
View Full Code Here

Examples of intrade.entities.Contract

    return true;
  }

  private Blob storeTradesfile(String id) {

    Contract c = null;

    PersistenceManager pm = PMF.get().getPersistenceManager();

    c = pm.getObjectById(Contract.class, Contract.generateKeyFromID(id));
    c.debug_setResponse(r);
    if (c.fetchTrades()) {
      print("Fetched Trades for contract " + id);
    }
    pm.close();

    return (c != null) ? c.getFileTrades() : null;

  }
View Full Code Here

Examples of intrade.entities.Contract

    }

    PersistenceManager pm = PMF.get().getPersistenceManager();
    pm.makePersistentAll(prices);
    Contract con = pm.getObjectById(Contract.class, Contract.generateKeyFromID(contractid));
    con.setLastUTCInsertedTrades(lastUTC);
    pm.close();

    return true;
  }
View Full Code Here

Examples of intrade.entities.Contract

      } else if (nd_name.equals("expiryPrice")) {
        contract_expiryPrice = nd.getTextContent();
      }
    }

    Contract con = new Contract(contract_id, eventid, contract_name, contract_symbol, contract_totalVolume,
        contract_ccy, contract_inRunning, contract_state, contract_tickSize, contract_tickValue, contract_type, start,
        end);

    if (contract_expiryDate != null) {
      con.setExpiryDate(Long.parseLong(contract_expiryDate));
    }

    if (contract_expiryPrice != null) {
      con.setExpiryPrice(Double.parseDouble(contract_expiryPrice));
    }

    return con;
  }
View Full Code Here

Examples of intrade.entities.Contract

  private long storeContracts(Node contract, String eventid, Long start, Long end) {

    long now = (new Date()).getTime();

    Contract con = parseContract(contract, eventid, start, end);

    PersistenceManager pm = PMF.get().getPersistenceManager();
    Contract stored_contract = null;

    try {
      stored_contract = pm.getObjectById(Contract.class, Contract.generateKeyFromID(con.getId()));
    } catch (Exception e) {
      stored_contract = null;
View Full Code Here

Examples of org.apache.ojb.broker.Contract

    }

    public void testInsertAfterDelete() throws Exception
    {
        final String contractPk = "The Contract_" + System.currentTimeMillis();
        Contract obj1 = new Contract();
        Contract obj2 = new Contract();

        obj1.setPk(contractPk);
        obj1.setContractValue2(1);

        obj2.setPk(contractPk);
        obj2.setContractValue2(2);
        try
        {
            // 1. Insert object
            Transaction tx = odmg.newTransaction();
            tx.begin();
            /*
            arminw:
            seems to have problems when within a tx a object
            was stored/deleted.
            Without obj1 test pass
            TODO: fix this
            */
            //database.makePersistent(obj1);
            database.makePersistent(obj2);
            //database.deletePersistent(obj1);
            /*
             thma: I checked this, and don't see a problem here.
            obj1 and obj2 have the same Identity. Thus the
            calls database.makePersistent(obj1); and database.makePersistent(obj2);
            will only register one instance to the transaction.
            The second call does not add a second instance, but just marks the
            existing instance as dirty a second time.
            So it's no wonder why after deletePersistent(obj1); no contract is found.
            Works as designed.
            The Lesson to learn: never let business objects have the same primary key values!
             * */
            tx.commit();
            Collection result = getContract(contractPk, odmg);
            assertEquals("We should found exact one contract", 1, result.size());
            obj2 = (Contract) result.iterator().next();
            if (obj2 == null)
            {
                fail("Contract not found");
            }
            else if (obj2.getContractValue2() != 2)
            {
                fail("Wrong contract found");
            }

            // 2. Delete, then insert object with the same identity
View Full Code Here

Examples of org.apache.tuscany.sca.assembly.Contract

            public SampleImplementation build(final Context ec) {
                final SampleImplementation impl = ImplUtil.implementation(clazz.getName());
                impl.clazz = clazz;
                impl.setUnresolved(false);
                for(final Builder<Contract> b: contracts) {
                    Contract c = b.build(ec);
                    if(c instanceof Service)
                        impl.getServices().add((Service)c);
                    else
                        impl.getReferences().add((Reference)c);
                }
View Full Code Here

Examples of org.apache.tuscany.sca.assembly.Contract

    private void initInvocationChains() {
        chains = new ArrayList<InvocationChain>();
        InterfaceContract sourceContract = wireSource.getInterfaceContract();
        InterfaceContract targetContract = wireTarget.getInterfaceContract();

        Contract source = wireSource.getContract();
        if (source instanceof RuntimeComponentReference) {
            // It's the reference wire
            RuntimeComponentReference reference = (RuntimeComponentReference)wireSource.getContract();
            Binding refBinding = wireSource.getBinding();
            for (Operation operation : sourceContract.getInterface().getOperations()) {
View Full Code Here

Examples of org.apache.tuscany.sca.assembly.Contract

        ComponentService componentService = null;
        ComponentReference componentReference = null;
        ComponentProperty componentProperty = null;
        CompositeService compositeService = null;
        CompositeReference compositeReference = null;
        Contract contract = null;
        Wire wire = null;
        Callback callback = null;
        QName name = null;

        // Read the composite document
        while (reader.hasNext()) {
            int event = reader.getEventType();
            switch (event) {
                case START_ELEMENT:
                    name = reader.getName();

                    if (COMPOSITE_QNAME.equals(name)) {

                        // Read a <composite>
                        composite = assemblyFactory.createComposite();
                        composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
                        if(isSet(reader, AUTOWIRE)) {
                            composite.setAutowire(getBoolean(reader, AUTOWIRE));
                        }
                        composite.setLocal(getBoolean(reader, LOCAL));
                        composite.setConstrainingType(readConstrainingType(reader));
                        policyProcessor.readPolicies(composite, reader);

                    } else if (INCLUDE_QNAME.equals(name)) {

                        // Read an <include>
                        include = assemblyFactory.createComposite();
                        include.setName(getQName(reader, "name"));
                        include.setUnresolved(true);
                        composite.getIncludes().add(include);

                    } else if (SERVICE_QNAME.equals(name)) {
                        if (component != null) {

                            // Read a <component><service>
                            componentService = assemblyFactory.createComponentService();
                            contract = componentService;
                            componentService.setName(getString(reader, NAME));
                            component.getServices().add(componentService);
                            policyProcessor.readPolicies(contract, reader);
                        } else {

                            // Read a <composite><service>
                            compositeService = assemblyFactory.createCompositeService();
                            contract = compositeService;
                            compositeService.setName(getString(reader, NAME));

                            String promoted = getString(reader, PROMOTE);
                            String promotedComponentName;
                            String promotedServiceName;
                            int s = promoted.indexOf('/');
                            if (s == -1) {
                                promotedComponentName = promoted;
                                promotedServiceName = null;
                            } else {
                                promotedComponentName = promoted.substring(0, s);
                                promotedServiceName = promoted.substring(s + 1);
                            }

                            Component promotedComponent = assemblyFactory.createComponent();
                            promotedComponent.setUnresolved(true);
                            promotedComponent.setName(promotedComponentName);
                            compositeService.setPromotedComponent(promotedComponent);

                            ComponentService promotedService = assemblyFactory.createComponentService();
                            promotedService.setUnresolved(true);
                            promotedService.setName(promotedServiceName);
                            compositeService.setPromotedService(promotedService);

                            composite.getServices().add(compositeService);
                            policyProcessor.readPolicies(contract, reader);
                        }

                    } else if (REFERENCE_QNAME.equals(name)) {
                        if (component != null) {
                            // Read a <component><reference>
                            componentReference = assemblyFactory.createComponentReference();
                            contract = componentReference;
                            componentReference.setName(getString(reader, NAME));
                            readMultiplicity(componentReference, reader);
                            if (isSet(reader, AUTOWIRE)) {
                                componentReference.setAutowire(getBoolean(reader, AUTOWIRE));
                            }
                            readTargets(componentReference, reader);
                            componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                            component.getReferences().add(componentReference);
                            policyProcessor.readPolicies(contract, reader);
                        } else {
                            // Read a <composite><reference>
                            compositeReference = assemblyFactory.createCompositeReference();
                            contract = compositeReference;
                            compositeReference.setName(getString(reader, NAME));
                            readMultiplicity(compositeReference, reader);
                            readTargets(compositeReference, reader);
                            String promote = reader.getAttributeValue(null, Constants.PROMOTE);
                            if (promote != null) {
                                for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) {
                                    ComponentReference promotedReference =
                                        assemblyFactory.createComponentReference();
                                    promotedReference.setUnresolved(true);
                                    promotedReference.setName(tokens.nextToken());
                                    compositeReference.getPromotedReferences().add(promotedReference);
                                }
                            }
                            compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                            composite.getReferences().add(compositeReference);
                            policyProcessor.readPolicies(contract, reader);
                        }

                    } else if (PROPERTY_QNAME.equals(name)) {
                        if (component != null) {

                            // Read a <component><property>
                            componentProperty = assemblyFactory.createComponentProperty();
                            property = componentProperty;
                            componentProperty.setSource(getString(reader, SOURCE));
                            componentProperty.setFile(getString(reader, FILE));
                            policyProcessor.readPolicies(property, reader);
                            readAbstractProperty(componentProperty, reader);
                           
                            // Read the property value
                            Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
                            property.setValue(value);
                           
                            component.getProperties().add(componentProperty);
                        } else {

                            // Read a <composite><property>
                            property = assemblyFactory.createProperty();
                            policyProcessor.readPolicies(property, reader);
                            readAbstractProperty(property, reader);
                           
                            // Read the property value
                            Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
                            property.setValue(value);
                           
                            composite.getProperties().add(property);
                        }

                    } else if (COMPONENT_QNAME.equals(name)) {

                        // Read a <component>
                        component = assemblyFactory.createComponent();
                        component.setName(getString(reader, NAME));
                        if (isSet(reader, AUTOWIRE)) {
                            component.setAutowire(getBoolean(reader, AUTOWIRE));
                        }
                        if (isSet(reader, URI)) {
                            component.setURI(getString(reader, URI));
                        }
                        component.setConstrainingType(readConstrainingType(reader));
                        composite.getComponents().add(component);
                        policyProcessor.readPolicies(component, reader);

                    } else if (WIRE_QNAME.equals(name)) {

                        // Read a <wire>
                        wire = assemblyFactory.createWire();
                        ComponentReference source = assemblyFactory.createComponentReference();
                        source.setUnresolved(true);
                        source.setName(getString(reader, SOURCE));
                        wire.setSource(source);

                        ComponentService target = assemblyFactory.createComponentService();
                        target.setUnresolved(true);
                        target.setName(getString(reader, TARGET));
                        wire.setTarget(target);

                        composite.getWires().add(wire);
                        policyProcessor.readPolicies(wire, reader);

                    } else if (CALLBACK_QNAME.equals(name)) {

                        // Read a <callback>
                        callback = assemblyFactory.createCallback();
                        contract.setCallback(callback);
                        policyProcessor.readPolicies(callback, reader);

                    } else if (OPERATION_QNAME.equals(name)) {

                        // Read an <operation>
                        ConfiguredOperation operation = assemblyFactory.createConfiguredOperation();
                        operation.setName(getString(reader, NAME));
                        operation.setUnresolved(true);
                        if (callback != null) {
                            policyProcessor.readPolicies(operation, reader);
                        } else {
                            policyProcessor.readPolicies(operation, reader);
                        }
                       
                        OperationsConfigurator opConfigurator = null;
                        if ( compositeService != null ) {
                            opConfigurator = compositeService;
                        } else if ( componentService != null ) {
                            opConfigurator = componentService;
                        } else if ( compositeReference != null ) {
                            opConfigurator = compositeReference;
                        } else if ( componentReference != null ) {
                            opConfigurator = componentReference;
                        }
                       
                        opConfigurator.getConfiguredOperations().add(operation);
                    } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {

                        // Read an implementation.composite
                        Composite implementation = assemblyFactory.createComposite();
                        implementation.setName(getQName(reader, NAME));
                        implementation.setUnresolved(true);
                        component.setImplementation(implementation);
                        policyProcessor.readPolicies(implementation, reader);
                    } else {

                        // Read an extension element
                        Object extension = extensionProcessor.read(reader);
                        if (extension != null) {
                            if (extension instanceof InterfaceContract) {

                                // <service><interface> and
                                // <reference><interface>
                                if (contract != null) {
                                    contract.setInterfaceContract((InterfaceContract)extension);
                                } else {
                                    if (name.getNamespaceURI().equals(SCA10_NS)) {
                                        throw new ContributionReadException(
                                                                            "Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
                                    } else {
                                        composite.getExtensions().add(extension);
                                    }
                                }

                            } else if (extension instanceof Binding) {
                                // <service><binding> and
                                // <reference><binding>
                                if (callback != null) {
                                    callback.getBindings().add((Binding)extension);
                                } else {
                                    if (contract != null) {
                                        contract.getBindings().add((Binding)extension);
                                    } else {
                                        if (name.getNamespaceURI().equals(SCA10_NS)) {
                                            throw new ContributionReadException(
                                                                                "Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
                                        } else {
                                            composite.getExtensions().add(extension);
                                        }
                                    }
                                }

                            } else if (extension instanceof Implementation) {

                                // <component><implementation>
                                if (component != null) {
                                    component.setImplementation((Implementation)extension);
                                } else {
                                    if (name.getNamespaceURI().equals(SCA10_NS)) {
                                        throw new ContributionReadException(
                                                                            "Unexpected <implementation> element found. It should appear inside a <component> element");
                                    } else {
                                        composite.getExtensions().add(extension);
                                    }
                                }
                            } else {

                                // Add the extension element to the current
                                // element
                                if (callback != null) {
                                    callback.getExtensions().add(extension);
                                } else if (contract != null) {
                                    contract.getExtensions().add(extension);
                                } else if (property != null) {
                                    property.getExtensions().add(extension);
                                } else if (component != null) {
                                    component.getExtensions().add(extension);
                                } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.