コード例 #1
0
        private void GenerateMapper(JavaMapperConfig javaMapperConfig)
        {
            initDefault();

            string rootDir = javaMapperConfig.MapperDirectory;

            if (false == Directory.Exists(rootDir))
            {
                Directory.CreateDirectory(rootDir);
            }
            string mapperDir = rootDir;
            string result    = String.Empty;

            Action action = () =>
            {
                result = mapperTemplate.Run(instance =>
                {
                    instance.Model = javaMapperConfig;
                });
                Console.WriteLine(result);


                string filePath = mapperDir + Path.DirectorySeparatorChar + javaMapperConfig.MapperName + ".xml";
                if (false == Directory.Exists(mapperDir))
                {
                    Directory.CreateDirectory(mapperDir);
                }
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.WriteAllText(filePath, result, new UTF8Encoding(false));
            };


            if (javaMapperConfig.SplitReadWrite)
            {
                if (javaMapperConfig.DaoConfig.ForRead)
                {
                    mapperDir = rootDir + "\\read";
                    javaMapperConfig.ForRead  = true;
                    javaMapperConfig.ForWrite = false;

                    action();
                }
                if (javaMapperConfig.DaoConfig.ForWrite)
                {
                    mapperDir = rootDir + "\\write";
                    javaMapperConfig.ForWrite = true;
                    javaMapperConfig.ForRead  = false;
                    action();
                }
            }
            else
            {
                action();
            }
        }
コード例 #2
0
        public void GenerateDao(JavaDaoConfig javaDaoConfig, JavaMapperConfig javaMapperConfig)
        {
            initDefault();


            string rootDir;
            string result = String.Empty;

            Action action = () =>
            {
                result = daoTemplate.Run(instance =>
                {
                    instance.Model = javaDaoConfig;
                });
                Console.WriteLine(result);
                rootDir = CodeUtil.PrepareJavaRoot(javaDaoConfig);

                string filePath = rootDir + Path.DirectorySeparatorChar + javaDaoConfig.DaoName + ".java";

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.WriteAllText(filePath, result, new UTF8Encoding(false));

                javaMapperConfig.JavaClass = javaDaoConfig.JavaClass;
                GenerateMapper(javaMapperConfig);
            };


            if (javaDaoConfig.SplitReadWrite)
            {
                javaDaoConfig.ForRead  = true;
                javaDaoConfig.ForWrite = false;

                action();


                javaDaoConfig.ForWrite = true;
                javaDaoConfig.ForRead  = false;
                action();
            }
            else
            {
                action();
            }
        }