Package org.slim3.gen.datastore

Examples of org.slim3.gen.datastore.DataType


                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

         * Generates attribute meta fields.
         */
        public void generate() {
            for (AttributeMetaDesc attr : modelMetaDesc
                .getAttributeMetaDescList()) {
                DataType dataType = attr.getDataType();
                dataType.accept(this, attr);
            }
        }
View Full Code Here

        }

        @Override
        public Void visitCollectionType(final CollectionType collectionType,
                final AttributeMetaDesc attr) throws RuntimeException {
            DataType elementType = collectionType.getElementType();
            elementType.accept(
                new SimpleDataTypeVisitor<Void, Void, RuntimeException>() {

                    @Override
                    public Void visitStringType(StringType type, Void p)
                            throws RuntimeException {
                        printer.println("/** */");
                        if (attr.isLob() || attr.isUnindexed()) {
                            printer
                                .println(
                                    "public final %1$s<%2$s, %3$s> %4$s = new %1$s<%2$s, %3$s>(this, \"%5$s\", \"%4$s\", %6$s.class);",
                                    StringCollectionUnindexedAttributeMeta,
                                    modelMetaDesc.getModelClassName(),
                                    collectionType.getTypeName(),
                                    attr.getAttributeName(),
                                    attr.getName(),
                                    collectionType.getClassName());
                        } else {
                            printer
                                .println(
                                    "public final %1$s<%2$s, %3$s> %4$s = new %1$s<%2$s, %3$s>(this, \"%5$s\", \"%4$s\", %6$s.class);",
                                    StringCollectionAttributeMeta,
                                    modelMetaDesc.getModelClassName(),
                                    collectionType.getTypeName(),
                                    attr.getAttributeName(),
                                    attr.getName(),
                                    collectionType.getClassName());
                        }
                        printer.println();
                        return null;
                    }

                    @Override
                    public Void visitCoreReferenceType(
                            CoreReferenceType elementType, Void p)
                            throws RuntimeException {
                        printer.println("/** */");
                        if (attr.isLob() || attr.isUnindexed()) {
                            printer
                                .println(
                                    "public final %1$s<%2$s, %3$s, %4$s> %5$s = new %1$s<%2$s, %3$s, %4$s>(this, \"%6$s\", \"%5$s\", %7$s.class);",
                                    CollectionUnindexedAttributeMeta,
                                    modelMetaDesc.getModelClassName(),
                                    collectionType.getTypeName(),
                                    elementType.getTypeName(),
                                    attr.getAttributeName(),
                                    attr.getName(),
                                    collectionType.getClassName());
                        } else {
                            printer
                                .println(
                                    "public final %1$s<%2$s, %3$s, %4$s> %5$s = new %1$s<%2$s, %3$s, %4$s>(this, \"%6$s\", \"%5$s\", %7$s.class);",
                                    CollectionAttributeMeta,
                                    modelMetaDesc.getModelClassName(),
                                    collectionType.getTypeName(),
                                    elementType.getTypeName(),
                                    attr.getAttributeName(),
                                    attr.getName(),
                                    collectionType.getClassName());
                        }
                        printer.println();
View Full Code Here

            } else {
                printer.println("%1$s model = new %1$s();", modelMetaDesc
                    .getModelClassName());
                for (AttributeMetaDesc attr : modelMetaDesc
                    .getAttributeMetaDescList()) {
                    DataType dataType = attr.getDataType();
                    dataType.accept(this, attr);
                }
                printer.println("return model;");
            }
            printer.unindent();
            printer.println("}");
View Full Code Here

        }

        @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

        }

        @Override
        public Void visitListType(final ListType collectionType,
                final AttributeMetaDesc attr) throws RuntimeException {
            DataType elementType = collectionType.getElementType();
            Boolean handled =
                elementType.accept(
                    new SimpleDataTypeVisitor<Boolean, Void, RuntimeException>(
                        false) {

                        @Override
                        public Boolean visitCoreReferenceType(
View Full Code Here

        }

        @Override
        public Void visitLinkedListType(final LinkedListType collectionType,
                final AttributeMetaDesc attr) throws RuntimeException {
            DataType elementType = collectionType.getElementType();
            Boolean handled =
                elementType.accept(
                    new SimpleDataTypeVisitor<Boolean, Void, RuntimeException>(
                        false) {

                        @Override
                        public Boolean visitCoreReferenceType(
View Full Code Here

        }

        @Override
        public Void visitSetType(final SetType collectionType,
                final AttributeMetaDesc attr) throws RuntimeException {
            DataType elementType = collectionType.getElementType();
            Boolean handled =
                elementType.accept(
                    new SimpleDataTypeVisitor<Boolean, Void, RuntimeException>(
                        false) {

                        @Override
                        public Boolean visitCoreReferenceType(
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.