Package org.slim3.gen.desc

Examples of org.slim3.gen.desc.DaoDesc


     *            the prnter
     */
    protected void printIncrementVersionMethod(final Printer printer) {
        printer.println("@Override");
        printer.println("protected void incrementVersion(Object model) {");
        final AttributeMetaDesc attr =
            modelMetaDesc.getVersionAttributeMetaDesc();
        if (attr != null) {
            printer.println(
                "    %1$s m = (%1$s) model;",
                modelMetaDesc.getModelClassName());
            DataType dataType = attr.getDataType();
            dataType.accept(
                new SimpleDataTypeVisitor<Void, Void, RuntimeException>() {

                    @Override
                    protected Void defaultAction(DataType type, Void p)
                            throws RuntimeException {
                        printer
                            .println(
                                "    throw new IllegalStateException(\"The version property of the model(%1$s) is not defined.\");",
                                modelMetaDesc.getModelClassName());
                        return null;
                    }

                    @Override
                    public Void visitPrimitiveLongType(PrimitiveLongType type,
                            Void p) throws RuntimeException {
                        printer.println(
                            "    m.%1$s(m.%2$s() + 1L);",
                            attr.getWriteMethodName(),
                            attr.getReadMethodName());
                        return null;
                    }

                    @Override
                    public Void visitLongType(LongType type, Void p)
                            throws RuntimeException {
                        printer
                            .println(
                                "    long version = m.%1$s() != null ? m.%1$s().longValue() : 0L;",
                                attr.getReadMethodName());
                        printer.println(
                            "    m.%1$s(Long.valueOf(version + 1L));",
                            attr.getWriteMethodName());
                        return null;
                    }

                },
                null);
View Full Code Here


     */
    protected void printGetKeyMethod(final Printer printer) {
        printer.println("@Override");
        printer
            .println("protected com.google.appengine.api.datastore.Key getKey(Object model) {");
        final AttributeMetaDesc attr = modelMetaDesc.getKeyAttributeMetaDesc();
        if (attr == null) {
            printer
                .println(
                    "    throw new IllegalStateException(\"The key property of the model(%1$s) is not defined.\");",
                    modelMetaDesc.getModelClassName());
        } else {
            printer.println(
                "    %1$s m = (%1$s) model;",
                modelMetaDesc.getModelClassName());
            printer.println("    return m.%1$s();", attr.getReadMethodName());
        }
        printer.println("}");
        printer.println();
    }
View Full Code Here

     */
    protected void printSetKeyMethod(final Printer printer) {
        printer.println("@Override");
        printer
            .println("protected void setKey(Object model, com.google.appengine.api.datastore.Key key) {");
        final AttributeMetaDesc attr = modelMetaDesc.getKeyAttributeMetaDesc();
        if (attr == null) {
            printer
                .println(
                    "    throw new IllegalStateException(\"The key property of the model(%1$s) is not defined.\");",
                    modelMetaDesc.getModelClassName());
        } else {
            printer.println("    validateKey(key);");
            printer.println(
                "    %1$s m = (%1$s) model;",
                modelMetaDesc.getModelClassName());
            printer.println("    m.%1$s(key);", attr.getWriteMethodName());
        }
        printer.println("}");
        printer.println();
    }
View Full Code Here

            throw new IllegalStateException(MessageFormatter.getMessage(
                MessageCode.SLIM3GEN0009,
                daoClassNameProperty));
        }

        DaoDesc daoDesc = createDaoDesc();

        JavaFile javaFile = createJavaFile(daoDesc);
        Generator generator = createDaoGenerator(daoDesc);
        generateJavaFile(generator, javaFile);

        JavaFile testCaseJavaFile = createTestCaseJavaFile(daoDesc);
        Generator testCaseGenerator = createDaoTestCaseGenerator(daoDesc);
        generateJavaFile(testCaseGenerator, testCaseJavaFile);

        getProject().setNewProperty(
            daoClassNameProperty,
            daoDesc.getQualifiedName());
    }
View Full Code Here

        String basePackageName = getBasePackageName();
        String modelPackageName = basePackageName + "." + Constants.MODEL_PACKAGE;
        String daoPackageName = basePackageName + "." + Constants.DAO_PACKAGE;
        String daoSimpleClassName = modelDef.modelRelativeClassName + Constants.DAO_SUFFIX;

        DaoDesc daoDesc = new DaoDesc();
        ClassNameBuilder classNameBuilder = new ClassNameBuilder();
        classNameBuilder.append(daoPackageName);
        classNameBuilder.append(daoSimpleClassName);
        daoDesc.setPackageName(classNameBuilder.getPackageName());
        daoDesc.setSimpleName(classNameBuilder.getSimpleName());
        daoDesc.setModelClassName(modelPackageName + "." + modelDef.modelRelativeClassName);
        daoDesc.setTestCaseSuperclassName(testCaseSuperclassName);

        return daoDesc;
    }
View Full Code Here

     *
     * @throws Exception
     */
    @Before
    public void setUp() throws Exception{
        DaoDesc desc = new DaoDesc();
        desc.setPackageName("slim3.dao");
        desc.setSimpleName("SampleDao");
        desc.setModelClassName("slim3.model.Sample");
        desc.setTestCaseSuperclassName(ClassConstants.AppEngineTestCase);

        generator = new DaoGenerator(desc);
        printer = new ConsolePrinter();
    }
View Full Code Here

     *
     * @throws Exception
     */
    @Before
    public void setUp() throws Exception{
        DaoDesc desc = new DaoDesc();
        desc.setPackageName("slim3.dao");
        desc.setSimpleName("SampleDao");
        desc.setModelClassName("slim3.model.Sample");
        desc.setTestCaseSuperclassName(ClassConstants.AppEngineTestCase);

        generator = new DaoTestCaseGenerator(desc);
        printer = new ConsolePrinter();
    }
View Full Code Here

    public void testCreateDaoDesc() throws Exception{
        GenDaoTask task = new GenDaoTask();
        task.setModelDefinition("Hoge");
        task.setPackageName("slim3");

        DaoDesc daoDesc = task.createDaoDesc();
        assertThat(daoDesc.getSimpleName(), is("HogeDao"));
        assertThat(daoDesc.getPackageName(), is("slim3.dao"));
        assertThat(daoDesc.getModelClassName(), is("slim3.model.Hoge"));
    }
View Full Code Here

    public void testCreateDaoDescWithSuperClass() throws Exception{
        GenDaoTask task = new GenDaoTask();
        task.setModelDefinition("Hoge extends Foo");
        task.setPackageName("slim3");

        DaoDesc daoDesc = task.createDaoDesc();
        assertThat(daoDesc.getSimpleName(), is("HogeDao"));
        assertThat(daoDesc.getPackageName(), is("slim3.dao"));
        assertThat(daoDesc.getModelClassName(), is("slim3.model.Hoge"));
    }
View Full Code Here

        protected TypeDeclaration toTypeDeclaration(DeclaredType declaredType) {
            TypeDeclaration typeDeclaration = declaredType.getDeclaration();
            if (typeDeclaration != null) {
                return typeDeclaration;
            }
            throw new UnknownDeclarationException(
                env,
                declaration,
                declaredType);
        }
View Full Code Here

TOP

Related Classes of org.slim3.gen.desc.DaoDesc

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.