Package com.amazonaws.services.simpledb.model

Examples of com.amazonaws.services.simpledb.model.ReplaceableAttribute


    }
   
    @Test
    public void putAttributes() {
        final List<ReplaceableAttribute> replaceableAttributes = Arrays.asList(new ReplaceableAttribute[] {
            new ReplaceableAttribute("NAME1", "VALUE1", true)});
        final UpdateCondition updateCondition = new UpdateCondition("NAME1", "VALUE1", true);
       
        template.send("direct:start", new Processor() {
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.PutAttributes);
View Full Code Here


    }
   
    @Test
    public void putAttributesItemNameIsRequired() {
        final List<ReplaceableAttribute> replaceableAttributes = Arrays.asList(new ReplaceableAttribute[] {
            new ReplaceableAttribute("NAME1", "VALUE1", true)});
        final UpdateCondition updateCondition = new UpdateCondition("NAME1", "VALUE1", true);
       
        Exchange exchange = template.send("direct:start", new Processor() {
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.PutAttributes);
View Full Code Here

    }
   
    @Test
    public void putAttributes() {
        final List<ReplaceableAttribute> replaceableAttributes = Arrays.asList(new ReplaceableAttribute[] {
            new ReplaceableAttribute("NAME1", "VALUE1", true)});
        final UpdateCondition updateCondition = new UpdateCondition("NAME1", "VALUE1", true);
       
        template.send("direct:start-sdb", new Processor() {
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.PutAttributes);
View Full Code Here

    }
   
    @Test
    public void putAttributesItemNameIsRequired() {
        final List<ReplaceableAttribute> replaceableAttributes = Arrays.asList(new ReplaceableAttribute[] {
            new ReplaceableAttribute("NAME1", "VALUE1", true)});
        final UpdateCondition updateCondition = new UpdateCondition("NAME1", "VALUE1", true);
       
        Exchange exchange = template.send("direct:start-sdb", new Processor() {
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.PutAttributes);
View Full Code Here

         
          sdbClient.putAttributes(
              new PutAttributesRequest()
                .withItemName("exist")
                .withDomainName(domainName)
                .withAttributes(new ReplaceableAttribute("name", "value", true)));
         
          Assert.assertNotNull(DomainHelper.findItemById(sdbClient, domainName, "exist"));
        }
        finally {
          sdbClient.deleteDomain(new DeleteDomainRequest().withDomainName(domainName));
View Full Code Here

          for(int i = 0; i < 3; i++) {
              sdbClient.putAttributes(
                  new PutAttributesRequest()
                    .withItemName("thing" + i)
                    .withDomainName(domainName)
                    .withAttributes(new ReplaceableAttribute("name", "value", true)));           
          }

          List<Item> items = DomainHelper.listAllItems(sdbClient, domainName);
          Assert.assertEquals(3, items.size());
        }
View Full Code Here

          for(int i = 0; i < 10; i++) {
              sdbClient.putAttributes(
                  new PutAttributesRequest()
                    .withItemName("thing" + i)
                    .withDomainName(domainName)
                    .withAttributes(new ReplaceableAttribute("name", "value", true)));           
          }
         
          SelectResult result = DomainHelper.selectItems(sdbClient, String.format("select * from `%s` LIMIT 3", domainName), null);
          Assert.assertEquals(3, result.getItems().size());
          Assert.assertNotNull(result.getNextToken());
View Full Code Here

          for(int i = 0; i < 10; i++) {
              sdbClient.putAttributes(
                  new PutAttributesRequest()
                    .withItemName("thing" + i)                   
                    .withDomainName(domainName)
                    .withAttributes(new ReplaceableAttribute("name", "value", true)));           
          }
         
          SelectResult result = DomainHelper.selectItems(sdbClient, domainName, "name = 'value' LIMIT 3", null);
          Assert.assertEquals(3, result.getItems().size());
          Assert.assertNotNull(result.getNextToken());
View Full Code Here

//        Item item = DomainHelper.findItemById(this.em.getSimpleDb(), domainName, id);
        // now set attributes
        List<ReplaceableAttribute> attsToPut = new ArrayList<ReplaceableAttribute>();
        List<Attribute> attsToDelete = new ArrayList<Attribute>();
        if (ai.getDiscriminatorValue() != null) {
            attsToPut.add(new ReplaceableAttribute(EntityManagerFactoryImpl.DTYPE, ai.getDiscriminatorValue(), true));
        }

        LazyInterceptor interceptor = null;
        if (o instanceof Factory) {
            Factory factory = (Factory) o;
            /*for (Callback callback2 : factory.getCallbacks()) {
                if(logger.isLoggable(Level.FINER)) logger.finer("callback=" + callback2);
                if (callback2 instanceof LazyInterceptor) {
                    interceptor = (LazyInterceptor) callback2;
                }
            }*/
            interceptor = (LazyInterceptor) factory.getCallback(0);
        }

        Collection<Method> getters = ai.getGetters();
        for (Method getter : getters) {
          Object ob;
          try
          {
            ob = getter.invoke(o);
          }
          catch (Exception e)
          {
            throw new PersistenceException("Failed invoking getter: " + getter, e);
          }
         
            String columnName = NamingHelper.getColumnName(getter);
            if (ob == null) {
                attsToDelete.add(new Attribute(columnName, null));
                continue;
            }
            if (getter.getAnnotation(ManyToOne.class) != null) {
                // store the id of this object
                String id2 = em.getId(ob);
                attsToPut.add(new ReplaceableAttribute(columnName, id2, true));
            } else if (getter.getAnnotation(OneToMany.class) != null) {
                // FORCING BI-DIRECTIONAL RIGHT NOW SO JUST IGNORE
            } else if (getter.getAnnotation(Lob.class) != null) {
                // store in s3
                AmazonS3 s3 = null;
                // todo: need to make sure we only store to S3 if it's changed, too slow.
                logger.fine("putting lob to s3");
                long start3 = System.currentTimeMillis();
                s3 = em.getS3Service();
                String bucketName = em.getS3BucketName();
                String s3ObjectId = em.s3ObjectId(id, getter);

                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream(bos);
                out.writeObject(ob);
                byte[] contentBytes = bos.toByteArray();
                out.close();
                InputStream input = new ByteArrayInputStream(contentBytes);
               
                s3.putObject(bucketName, s3ObjectId, input, null);
               
                em.statsS3Put(System.currentTimeMillis() - start3);
                logger.finer("setting lobkeyattribute=" + columnName + " - " + s3ObjectId);
                attsToPut.add(new ReplaceableAttribute(columnName, s3ObjectId, true));
            } else if (getter.getAnnotation(Enumerated.class) != null) {
                Enumerated enumerated = getter.getAnnotation(Enumerated.class);
                Class retType = getter.getReturnType();
                EnumType enumType = enumerated.value();
                String toSet = null;
                if (enumType == EnumType.STRING) {
                    toSet = ob.toString();
                } else { // ordinal
                    Object[] enumConstants = retType.getEnumConstants();
                    for (int i = 0; i < enumConstants.length; i++) {
                        Object enumConstant = enumConstants[i];
                        if (enumConstant.toString().equals(ob.toString())) {
                            toSet = Integer.toString(i);
                            break;
                        }
                    }
                }
                if (toSet == null) {
                    // should never happen
                    throw new PersistenceException("Enum value is null, couldn't find ordinal match: " + ob);
                }
                attsToPut.add(new ReplaceableAttribute(columnName, toSet, true));
            }
            else if(getter.getAnnotation(Id.class) != null)
            {
              continue;
            }
            else {
                String toSet = ob != null ? em.padOrConvertIfRequired(ob) : "";
                // todo: throw an exception if this is going to exceed maximum size, suggest using @Lob
                attsToPut.add(new ReplaceableAttribute(columnName, toSet, true));
            }
        }

        // Now finally send it for storage (If have attributes to add)
        long start2 = System.currentTimeMillis();
View Full Code Here

    private void putNewValue(String domainName, List<Item> items, String dtype, String newClassName) throws AmazonClientException {
        AmazonSimpleDB db = factory.getSimpleDb();
        for (Item item : items) {
            List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();

            atts.add(new ReplaceableAttribute(dtype, newClassName, true));
            db.putAttributes(new PutAttributesRequest(domainName, item.getName(), atts));
        }
    }
View Full Code Here

TOP

Related Classes of com.amazonaws.services.simpledb.model.ReplaceableAttribute

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.