Package wwutil.jsoda

Examples of wwutil.jsoda.Jsoda



    public static void main(String[] args)
        throws Exception
    {
        Jsoda       jsoda = new Jsoda(new BasicAWSCredentials(key, secret));

        // Register a custom AnnotationFieldHandler that implements the functionality of MyDataConverter.
        jsoda.registerData1Handler(MyDataConverter.class, new AnnotationFieldHandler() {
            // checkModel() is called when a model class is registered to see if the annotated fields confirm to this annotation's requirement.
            public void checkModel(Annotation fieldAnnotation, Field field, Map<String, Field> allFieldMap) throws ValidationException {
                if (field.getType() != String.class)
                    throw new ValidationException("The field must be String type.  Field: " + field.getName());
            }

            // handle() is called when a model object is stored
            public void handle(Annotation fieldAnnotation, Object object, Field field, Map<String, Field> allFieldMap) throws Exception {
                String      value = (String)field.get(object);
                if (value != null) {
                    String  trimValue = (value.length() > 4 ? value.substring(0, 4) : value);
                    field.set(object, trimValue);
                }
            }
        });

        // Register a custom AnnotationFieldHandler that implements the functionality of MyValidator
        jsoda.registerValidationHandler(MyValidator.class, new AnnotationFieldHandler() {
            // checkModel() is called when a model class is registered to see if the annotated fields confirm to this annotation's requirement.
            public void checkModel(Annotation fieldAnnotation, Field field, Map<String, Field> allFieldMap) throws ValidationException {
                if (field.getType() != String.class)
                    throw new ValidationException("The field must be String type.  Field: " + field.getName());
            }

            // handle() is called when a model object is stored
            public void handle(Annotation fieldAnnotation, Object object, Field field, Map<String, Field> allFieldMap) throws Exception {
                String      value = (String)field.get(object);
                if (value != null) {
                    if (value.startsWith("foobar"))
                        throw new ValidationException("Field cannot start with foobar.  Field: " + field.getName());
                }
            }
        });

        // Register a custom AnnotationFieldHandler that implements the functionality of MyDataJoiner
        // Note it's registered as stage 2 handler, to run after the stage 1 handlers.
        jsoda.registerData2Handler(MyDataJoiner.class, new AnnotationFieldHandler() {
            // checkModel() is called when a model class is registered to see if the annotated fields confirm to this annotation's requirement.
            public void checkModel(Annotation fieldAnnotation, Field field, Map<String, Field> allFieldMap) throws ValidationException {
                if (field.getType() != String.class)
                    throw new ValidationException("The field must be String type.  Field: " + field.getName());
            }

            // handle() is called when a model object is stored
            public void handle(Annotation fieldAnnotation, Object object, Field field, Map<String, Field> allFieldMap) throws Exception {
                // Join the values from field1, field2, and field3, and convert it to upper case.
                MyDataJoiner    ann = (MyDataJoiner)fieldAnnotation;
                Field           field1 = allFieldMap.get(ann.field1());
                Field           field2 = allFieldMap.get(ann.field2());
                Field           field3 = allFieldMap.get(ann.field3());
                String          value1 = field1.get(object).toString();
                String          value2 = field2.get(object).toString();
                String          value3 = field3.get(object).toString();
                String          result = (value1 + ": " + value2 + "/" + value3).toUpperCase();
                field.set(object, result);
            }
        });


        jsoda.registerModel(SampleCustom.class, DbType.SimpleDB);

        // Sample object to show how the fields are transformed via the custom annotations
        try {
            SampleCustom    obj = new SampleCustom(101, "this-long-long-name", "custom object");
            jsoda.preStoreSteps(obj);
            System.out.println(obj);
        } catch(Exception e) {
            System.out.println(e);
        }

        // Sample object to show how the custom validation is triggered.
        try {
            SampleCustom    obj = new SampleCustom(101, "this-long-long-name", "foobar custom object");
            jsoda.preStoreSteps(obj);
            System.out.println(obj);
        } catch(Exception e) {
            System.out.println(e);
        }
View Full Code Here


    public static void main(String[] args)
        throws Exception
    {
        // Create a Jsoda object with AWS credentials.
        // Jsoda is for tracking registration of models and general factory.
        Jsoda       jsoda = new Jsoda(new BasicAWSCredentials(key, secret));

        // Create the corresponding table in the database.  Only need to do this once.
        jsoda.createModelTable(SampleUser.class);

        // Get the Dao object specific to the SampleUser model class.
        Dao<SampleUser> dao = jsoda.dao(SampleUser.class);

        // Save some objects
        dao.put(new SampleUser(101, "Jack", 1));
        dao.put(new SampleUser(102, "Jill", 1));
        dao.put(new SampleUser(103, "Joe", 1));
View Full Code Here

    }

    public static void main(String[] args)
        throws Exception
    {
        Jsoda       jsoda = new Jsoda(new BasicAWSCredentials(key, secret));

        // Set up the DynamoDB endpoint to use service in the AWS east region.
        // Use http endpoint to skip setting up https client certificate.
        jsoda.setDbEndpoint(DbType.DynamoDB, dynUrl);

        // Uncomment the following to run delete.

        // Sample tables.
       
View Full Code Here


    public static void main(String[] args)
        throws Exception
    {
        Jsoda       jsoda = new Jsoda(new BasicAWSCredentials(key, secret));

        // Create the table corresponding to the model class.  Only need to do this once.
        jsoda.createModelTable(SampleProduct.class);


        // Save some objects
        Dao<SampleProduct>      dao = jsoda.dao(SampleProduct.class);
        dao.put(new SampleProduct("item1", "Red Shirt", "Premium red shirt", 29.95f));
        dao.put(new SampleProduct("item2", "Tophat", "Tophat for the cat", 90f));
        dao.put(new SampleProduct("item3", "Socks", null, 2.95f));
        dao.put(new SampleProduct("item4", "Steak", "Sizzling steak", 12.95f));
        dao.put(new SampleProduct("item5", null, "product with null name", 0.0f));


        // Create a query object specific to the SampleProduct model class.
        // No additional filtering condition means to get all the items.
        Query<SampleProduct>    query = jsoda.query(SampleProduct.class);

        // Run the count query to get back the count of the query.
        System.out.println("Number of objects: " + query.count());

        // Run the query to get all the items.
        for (SampleProduct product : query.run()) {
            System.out.println(product);
        }

        // Run a query to get all products whose price > 10
        Query<SampleProduct>    query2 = jsoda.query(SampleProduct.class).gt("price", 10);
        for (SampleProduct product : query2.run()) {
            System.out.println(product);
        }

        // Run a query to get the null name product.  Chaining style method calls.
        for (SampleProduct product : jsoda.query(SampleProduct.class)
                 .is_null("name")
                 .run()) {
            System.out.println(product);
        }

        // Run a query to get all products with name not null and price >= 29.95
        for (SampleProduct product : jsoda.query(SampleProduct.class)
                 .is_not_null("name")
                 .ge("price", 29.95f)
                 .run()) {
            System.out.println(product);
        }

        // Run a query to get all products whose price > 10 and order by price descending.
        for (SampleProduct product : jsoda.query(SampleProduct.class)
                 .gt("price", 10)
                 .order_by_desc("price")
                 .run()) {
            System.out.println(product);
        }
View Full Code Here

    public static void main(String[] args)
        throws Exception
    {
        // Create a Jsoda object with AWS credentials.
        Jsoda       jsoda = new Jsoda(new BasicAWSCredentials(key, secret));

        // Set up the DynamoDB endpoint to use service in the AWS east region.
        // Use http endpoint to skip setting up https client certificate.
        jsoda.setDbEndpoint(DbType.DynamoDB, dynUrl);

        System.out.println("\nSimpleDB Tables:");
        for (String table : jsoda.listNativeTables(DbType.SimpleDB)) {
            System.out.println("    " + table);
        }

        System.out.println("\nDynamoDB Tables:");
        for (String table : jsoda.listNativeTables(DbType.DynamoDB)) {
            System.out.println("    " + table);
        }

    }
View Full Code Here


    public static void main(String[] args)
        throws Exception
    {
        Jsoda       jsoda = new Jsoda(new BasicAWSCredentials(key, secret));

        // Create the table corresponding to the model class.  Only need to do this once.
        jsoda.createModelTable(SampleProduct2.class);


        // Save some objects
        Dao<SampleProduct2>      dao = jsoda.dao(SampleProduct2.class);
        dao.put(new SampleProduct2("item1", "Red Shirt", "Premium red shirt", "(415) 555-1212", "800-123-4567", 29.95f));
        dao.put(new SampleProduct2("item2", "Tophat", "Tophat for the cat", "(415) 555-1212", "800-789-ABCD", 90f));
        dao.put(new SampleProduct2("item3", "Socks", null, "(415) 555-1212", "800-555-1212", 2.95f));
        dao.put(new SampleProduct2("item4", "Steak", "Sizzling steak", "(415) 555-1212", "800-555-ab$d", 12.95f));
        dao.put(new SampleProduct2("item5", "Tophat", "product with null name", "(415) 555-1212", "800-123-4567", 0.0f));


        // Create a query object specific to the SampleProduct2 model class.
        // No additional filtering condition means to get all the items.
        Query<SampleProduct2>    query = jsoda.query(SampleProduct2.class);

        // Run the count query to get back the count of the query.
        System.out.println("Number of objects: " + query.count());

        // Run the query to get all the items.
        for (SampleProduct2 product : query.run()) {
            System.out.println(product);
        }

        // Run a query to get all products whose price > 10
        Query<SampleProduct2>    query2 = jsoda.query(SampleProduct2.class).gt("price", 10);
        for (SampleProduct2 product : query2.run()) {
            System.out.println(product);
        }

        // Run a query to get the null name product.  Chaining style method calls.
        for (SampleProduct2 product : jsoda.query(SampleProduct2.class)
                 .is_null("name")
                 .run()) {
            System.out.println(product);
        }

        // Run a query to get all products with name not null and price >= 29.95
        for (SampleProduct2 product : jsoda.query(SampleProduct2.class)
                 .is_not_null("name")
                 .ge("price", 29.95f)
                 .run()) {
            System.out.println(product);
        }

        // Run a query to get all products whose price > 10 and order by price descending.
        for (SampleProduct2 product : jsoda.query(SampleProduct2.class)
                 .gt("price", 10)
                 .order_by_desc("price")
                 .run()) {
            System.out.println(product);
        }
View Full Code Here


    public static void main(String[] args)
        throws Exception
    {
        Jsoda       jsoda = new Jsoda(new BasicAWSCredentials(key, secret));

        // Set up the DynamoDB endpoint to use service in the AWS east region.
        // Use http endpoint to skip setting up https client certificate.
        jsoda.setDbEndpoint(DbType.DynamoDB, dynUrl);

        System.out.println("SimpleDB tables (domains):");
        for (String dbname : jsoda.listNativeTables(DbType.SimpleDB)) {
            System.out.println(dbname);
        }
       
        System.out.println("DynamoDB tables:");
        for (String dbname : jsoda.listNativeTables(DbType.DynamoDB)) {
            System.out.println(dbname);
        }

        // Uncomment the following to run delete.
View Full Code Here

TOP

Related Classes of wwutil.jsoda.Jsoda

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.