Package org.slim3.gen.datastore

Examples of org.slim3.gen.datastore.DataType


        }

        @Override
        public Void visitArrayType(ArrayType type, final AttributeMetaDesc attr)
                throws RuntimeException {
            DataType componentType = type.getComponentType();
            boolean accepted =
                componentType.accept(
                    new SimpleDataTypeVisitor<Boolean, Void, RuntimeException>(
                        false) {

                        @Override
                        public Boolean visitPrimitiveByteType(
View Full Code Here


        public Void visitListType(ListType type, final AttributeMetaDesc attr)
                throws RuntimeException {
            if (attr.isLob()) {
                return super.visitCollectionType(type, attr);
            }
            DataType componentType = type.getElementType();
            boolean accepted =
                componentType.accept(
                    new SimpleDataTypeVisitor<Boolean, Void, RuntimeException>(
                        false) {

                        @Override
                        public Boolean visitEnumType(EnumType type, Void p)
View Full Code Here

        public Void visitCollectionType(CollectionType type,
                final AttributeMetaDesc attr) throws RuntimeException {
            if (attr.isLob()) {
                return super.visitCollectionType(type, attr);
            }
            DataType componentType = type.getElementType();
            boolean accepted =
                componentType.accept(
                    new SimpleDataTypeVisitor<Boolean, Void, RuntimeException>(
                        false) {

                        @Override
                        public Boolean visitEnumType(EnumType type, Void p)
View Full Code Here

                            continue;
                        }
                        if (attr.isPrimaryKey()) {
                            continue;
                        }
                        DataType dataType = attr.getDataType();
                        dataType.accept(this, attr);
                    }
                }
            }
            printer.unindent();
            printer.println("}");
View Full Code Here

                    valueExp = "m." + attr.getReadMethodName() + "()";
                    indent = 0;
                    JsonAnnotation ja = attr.getJson();
                    if (ja.isIgnore())
                        continue;
                    DataType dataType = attr.getDataType();
                    if(dataType instanceof InverseModelRefType && !ja.hasIgnore()){
                        continue;
                    }
                    String cn = ja.getCoderClassName();
                    coderExp = encoders.get(cn);
                    if (coderExp == null) {
                        String vn = "encoder" + encoders.size();
                        coderExp = vn;
                        printer.println("%s %s = new %1$s();", cn, vn);
                        encoders.put(cn, vn);
                    }
                    if (!(dataType instanceof CorePrimitiveType)
                        && ja.isIgnoreNull()) {
                        printer.print("if(%s != null", valueExp);
                        if (dataType instanceof TextType) {
                            printer.printWithoutIndent(
                                " && %s.getValue() != null",
                                valueExp);
                        } else if (dataType instanceof BlobType) {
                            printer.printWithoutIndent(
                                " && %s.getBytes() != null",
                                valueExp);
                        } else if (dataType instanceof ModelRefType) {
                            printer.printWithoutIndent(
                                " && %s.getKey() != null",
                                valueExp);
                        } else if (dataType instanceof InverseModelRefType) {
                            printer.printWithoutIndent(
                                " && getKey(m) != null"
                                );
                        }
                        printer.printlnWithoutIndent("){");
                        printer.indent();
                        indent++;
                    }
                    String name = ja.getAlias();
                    if (name.length() == 0) {
                        name = attr.getAttributeName();
                    }
                    printer.println(
                        "writer.setNextPropertyName(\"%1$s\");",
                        name);
                    dataType.accept(this, attr);
                    for (int i = 0; i < indent; i++) {
                        printer.unindent();
                        printer.println("}");
                    }
                }
View Full Code Here

        }

        @Override
        public Void visitCollectionType(CollectionType type, AttributeMetaDesc p)
                throws RuntimeException {
            DataType et = type.getElementType();
            if (!isSupportedForJson(et)) {
                printer.println("// %s is not supported.", et.getClassName());
                return null;
            }
            if (!p.getJson().isIgnoreNull()) {
                printer.println("if(%s == null){", valueExp);
                printer.indent();
                printer.println("writer.writeNull();");
                printer.unindent();
                printer.println("} else{");
                printer.indent();
                indent++;
            }
            printer.println("writer.beginArray();");
            printer.println("for(%s v : %s){", et.getClassName(), valueExp);
            printer.indent();
            ModelToJsonMethodGenerator gen =
                new ModelToJsonMethodGenerator(printer, coderExp, "v");
            et.accept(gen, p);
            for (int i = 0; i < gen.indent; i++) {
                printer.unindent();
                printer.println("}");
            }
            printer.unindent();
View Full Code Here

        }

        @Override
        public Void visitArrayType(ArrayType type, AttributeMetaDesc p)
                throws RuntimeException {
            DataType et = type.getComponentType();
            if (!isSupportedForJson(et)) {
                printer.println(
                    "// %s(%s) is not supported.",
                    et.getClassName(),
                    et.getTypeName());
                return null;
            }
            if (et.getClassName().equals("byte")) {
                if (!p.getJson().isIgnoreNull()) {
                    printer.println("if(%s == null){", valueExp);
                    printer.indent();
                    printer.println(
                        "%s.encode(writer, (%s)null);",
                        coderExp,
                        ShortBlob);
                    printer.unindent();
                    printer.println("} else{");
                    printer.indent();
                    indent++;
                }
                printer.println(
                    "%s.encode(writer, new %s(%s));",
                    coderExp,
                    ShortBlob,
                    valueExp);
            } else {
                if (!p.getJson().isIgnoreNull()) {
                    printer.println("if(%s == null){", valueExp);
                    printer.indent();
                    printer.println(
                        "%s.encode(writer, (%s));",
                        coderExp,
                        valueExp);
                    printer.unindent();
                    printer.println("} else{");
                    printer.indent();
                    indent++;
                }
                printer.println("writer.beginArray();");
                printer.println("for(%s v : %s){", et.getClassName(), valueExp);
                printer.indent();
                ModelToJsonMethodGenerator gen =
                    new ModelToJsonMethodGenerator(printer, coderExp, "v");
                et.accept(gen, p);
                for (int i = 0; i < gen.indent; i++) {
                    printer.unindent();
                    printer.println("}");
                }
                printer.unindent();
View Full Code Here

                for (AttributeMetaDesc attr : modelMetaDesc
                    .getAttributeMetaDescList()) {
                    JsonAnnotation ja = attr.getJson();
                    if (ja.isIgnore())
                        continue;
                    DataType dt = attr.getDataType();
                    if(dt instanceof InverseModelRefType)
                        continue;
                    String name = ja.getAlias();
                    if (name.length() == 0) {
                        name = attr.getAttributeName();
                    }
                    printer.println(
                        "reader = rootReader.newObjectReader(\"%s\");",
                        name);
                    String cn = ja.getCoderClassName();
                    coderExp = decoders.get(cn);
                    if (coderExp == null) {
                        String vn = "decoder" + decoders.size();
                        coderExp = vn;
                        printer.println("%s %s = new %1$s();", cn, vn);
                        decoders.put(cn, vn);
                    }
                    setterExp =
                        attr.getWriteMethodName() != null ? "m."
                            + attr.getWriteMethodName() : null;
                    getterExp =
                        attr.getReadMethodName() != null ? "m."
                            + attr.getReadMethodName()
                            + "()" : getDefaultValue(attr
                            .getDataType()
                            .getClassName());
                    dt.accept(this, attr);
                }
                printer.println("return m;");
            }
            printer.unindent();
            printer.println("}");
View Full Code Here

        @Override
        public Void visitCollectionType(CollectionType type, AttributeMetaDesc p)
                throws RuntimeException {
            if (setterExp == null)
                return null;
            DataType et = type.getElementType();
            if (!isSupportedForJson(et)) {
                return null;
            }
            String container = ArrayList;
            if (type instanceof SortedSetType) {
                container = TreeSet;
            } else if (type instanceof SetType) {
                container = HashSet;
            } else if (type instanceof LinkedListType) {
                container = LinkedList;
            }
            printer.println("{");
            printer.indent();
            printer.println(
                "%s<%s> elements = new %1$s<%2$s>();",
                container,
                et.getTypeName());
            printer.println(
                "%s r = rootReader.newArrayReader(\"%s\");",
                JsonArrayReader,
                p.getAttributeName());
            printer.println("if(r != null){");
            printer.indent();
            printer.println("reader = r;");
            printer.println("int n = r.length();");
            printer.println("for(int i = 0; i < n; i++){");
            printer.indent();
            printer.println("r.setIndex(i);");
            if (et instanceof ModelRefType) {
                printer.println(
                    "%s ref = new %1$s(%s.class);",
                    et.getTypeName(),
                    ((ModelRefType) et).getReferenceModelTypeName());
                type.getElementType().accept(
                    new JsonToModelMethodGenerator(
                        printer,
                        "ref",
                        "elements.add",
                        coderExp,
                        true),
                    p);
                printer.println("if(ref.getKey() != null){");
                printer.indent();
                printer.println("elements.add(ref);");
                printer.unindent();
                printer.println("}");
            } else {
                type.getElementType().accept(
                    new JsonToModelMethodGenerator(printer, "("
                        + et.getClassName()
                        + ")null", "elements.add", coderExp, true),
                    p);
            }
            printer.unindent();
            printer.println("}");
View Full Code Here

        @Override
        public Void visitArrayType(ArrayType type, AttributeMetaDesc p)
                throws RuntimeException {
            if (setterExp == null)
                return null;
            DataType et = type.getComponentType();
            if (!isSupportedForJson(et)) {
                printer.println(
                    "// %s(%s) is not supported.",
                    et.getClassName(),
                    et.getTypeName());
                return null;
            }
            if (et.getClassName().equals("byte")) {
                printer.println("if(%s != null){", getterExp);
                printer.indent();
                printer.println(
                    "%s(%s.decode(reader, new %s(%s)).getBytes());",
                    setterExp,
View Full Code Here

TOP

Related Classes of org.slim3.gen.datastore.DataType

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.