[Jiemamy-notify:1420] commit [2652] refactor /

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 2月 12日 (木) 02:13:40 JST


Revision: 2652
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2652
Author:   daisuke_m
Date:     2009-02-12 02:13:40 +0900 (Thu, 12 Feb 2009)

Log Message:
-----------
refactor /
SQL化ロジック整備。

Modified Paths:
--------------
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultSqlEmitter.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Keyword.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Literal.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Separator.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/SqlStatementImpl.java
    zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DataTypeCategory.java
    zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/LiteralType.java
    zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/SqlStatement.java

Added Paths:
-----------
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Operator.java


-------------- next part --------------
Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java	2009-02-11 16:35:30 UTC (rev 2651)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java	2009-02-11 17:13:40 UTC (rev 2652)
@@ -113,7 +113,13 @@
 	public BuiltinDataType resolveDataType(JiemamyFactory factory, int sqlType, String typeName) {
 		Validate.notNull(factory);
 		BuiltinDataType builtinDataType = factory.newModel(BuiltinDataType.class);
-		builtinDataType.setCategory(DataTypeCategory.fromSqlType(sqlType));
+		DataTypeCategory category;
+		try {
+			category = DataTypeCategory.valueOf(typeName);
+		} catch (IllegalArgumentException e) {
+			category = DataTypeCategory.fromSqlType(sqlType);
+		}
+		builtinDataType.setCategory(category);
 		builtinDataType.setTypeName(typeName);
 		return builtinDataType;
 	}

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultSqlEmitter.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultSqlEmitter.java	2009-02-11 16:35:30 UTC (rev 2651)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultSqlEmitter.java	2009-02-11 17:13:40 UTC (rev 2652)
@@ -45,6 +45,7 @@
 import org.jiemamy.model.sql.Identifier;
 import org.jiemamy.model.sql.Keyword;
 import org.jiemamy.model.sql.Literal;
+import org.jiemamy.model.sql.Operator;
 import org.jiemamy.model.sql.Separator;
 import org.jiemamy.model.sql.SqlStatement;
 import org.jiemamy.model.sql.SqlStatementImpl;
@@ -262,9 +263,9 @@
 				ColumnModel columnModel = referenceResolver.resolve(nnModel.getColumn());
 				tokens.add(new Identifier(columnModel.getName()));
 				
-				tokens.add(Keyword.IS);
-				tokens.add(Keyword.NOT);
-				tokens.add(Keyword.NULL);
+				tokens.add(Operator.IS);
+				tokens.add(Operator.NOT);
+				tokens.add(Literal.NULL);
 				tokens.add(Separator.RIGHT_PAREN);
 				return tokens;
 			}

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java	2009-02-11 16:35:30 UTC (rev 2651)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java	2009-02-11 17:13:40 UTC (rev 2652)
@@ -18,8 +18,6 @@
  */
 package org.jiemamy.formatter;
 
-import org.apache.commons.lang.ArrayUtils;
-
 import org.jiemamy.model.sql.Separator;
 import org.jiemamy.model.sql.SqlStatement;
 import org.jiemamy.model.sql.Token;
@@ -31,16 +29,18 @@
  */
 public class DefaultSqlFormatter implements SqlFormatter {
 	
+	private static boolean isSeparator(Token token) {
+		return token instanceof Separator;
+	}
+	
 	/**
 	 * {@inheritDoc}
 	 */
 	public String format(SqlStatement stmt) {
 		StringBuilder sb = new StringBuilder();
-		Token lastToken = Separator.SEMICOLON;
-		for (Token token : stmt.getTokens()) {
-			if (lastToken.equals(Separator.COMMA)
-					|| (ArrayUtils.contains(Separator.values(), lastToken) == false && ArrayUtils.contains(Separator
-						.values(), token) == false)) {
+		Token lastToken = Separator.INITIAL;
+		for (Token token : stmt.toTokens()) {
+			if (lastToken.equals(Separator.COMMA) || (isSeparator(lastToken) == false && isSeparator(token) == false)) {
 				sb.append(" ");
 			}
 			sb.append(token);

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Keyword.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Keyword.java	2009-02-11 16:35:30 UTC (rev 2651)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Keyword.java	2009-02-11 17:13:40 UTC (rev 2652)
@@ -25,120 +25,117 @@
  */
 public class Keyword implements Token {
 	
-	/***/
+	/** CREATE */
 	public static final Keyword CREATE = new Keyword("CREATE");
 	
-	/***/
+	/** TABLE */
 	public static final Keyword TABLE = new Keyword("TABLE");
 	
-	/***/
+	/** VIEW */
 	public static final Keyword VIEW = new Keyword("VIEW");
 	
-	/***/
+	/** AS */
+	public static final Keyword AS = new Keyword("AS");
+	
+	/** KEY */
 	public static final Keyword KEY = new Keyword("KEY");
 	
-	/***/
+	/** PRIMARY */
 	public static final Keyword PRIMARY = new Keyword("PRIMARY");
 	
-	/***/
+	/** UNIQUE */
 	public static final Keyword UNIQUE = new Keyword("UNIQUE");
 	
-	/***/
+	/** FOREIGN */
 	public static final Keyword FOREIGN = new Keyword("FOREIGN");
 	
-	/***/
+	/** CHECK */
 	public static final Keyword CHECK = new Keyword("CHECK");
 	
-	/***/
-	public static final Keyword NOT = new Keyword("NOT");
-	
-	/***/
-	public static final Keyword NULL = new Keyword("NULL");
-	
-	/***/
+	/** SCHEMA */
 	public static final Keyword SCHEMA = new Keyword("SCHEMA");
 	
-	/***/
-	public static final Keyword AS = new Keyword("AS");
-	
-	/***/
+	/** CONSTRAINT */
 	public static final Keyword CONSTRAINT = new Keyword("CONSTRAINT");
 	
-	/***/
+	/** DEFAULT */
 	public static final Keyword DEFAULT = new Keyword("DEFAULT");
 	
-	/***/
-	public static final Keyword IS = new Keyword("IS");
-	
-	/***/
+	/** REFERENCES */
 	public static final Keyword REFERENCES = new Keyword("REFERENCES");
 	
-	/***/
-	public static final Keyword MATCH = new Keyword("MATCH");
-	
-	/***/
+	/** ON */
 	public static final Keyword ON = new Keyword("ON");
 	
-	/***/
+	/** DELETE */
 	public static final Keyword DELETE = new Keyword("DELETE");
 	
-	/***/
+	/** UPDATE */
 	public static final Keyword UPDATE = new Keyword("UPDATE");
 	
-	/***/
-	public static final Keyword DEFERRABLE = new Keyword("DEFERRABLE");
-	
-	/***/
-	public static final Keyword INITIALLY = new Keyword("INITIALLY");
-	
-	/***/
-	public static final Keyword WITH = new Keyword("WITH");
-	
-	/***/
-	public static final Keyword WITHOUT = new Keyword("WITHOUT");
-	
-	/***/
-	public static final Keyword TIMEZONE = new Keyword("TIMEZONE");
-	
-	/***/
+	/** SET */
 	public static final Keyword SET = new Keyword("SET");
 	
-	/***/
+	/** NULL */
+	public static final Keyword NULL = new Keyword("NULL");
+	
+	/** CASCADE */
 	public static final Keyword CASCADE = new Keyword("CASCADE");
 	
-	/***/
+	/** RESTRICT */
 	public static final Keyword RESTRICT = new Keyword("RESTRICT");
 	
-	/***/
+	/** NO */
 	public static final Keyword NO = new Keyword("NO");
 	
-	/***/
+	/** ACTION */
 	public static final Keyword ACTION = new Keyword("ACTION");
 	
-	/***/
+	/** NOT */
+	public static final Keyword NOT = new Keyword("NOT");
+	
+	/** DEFERRABLE */
+	public static final Keyword DEFERRABLE = new Keyword("DEFERRABLE");
+	
+	/** INITIALLY */
+	public static final Keyword INITIALLY = new Keyword("INITIALLY");
+	
+	/** IMMEDIATE */
+	public static final Keyword IMMEDIATE = new Keyword("IMMEDIATE");
+	
+	/** DEFERRED */
+	public static final Keyword DEFERRED = new Keyword("DEFERRED");
+	
+	/** MATCH */
+	public static final Keyword MATCH = new Keyword("MATCH");
+	
+	/** SIMPLE */
 	public static final Keyword SIMPLE = new Keyword("SIMPLE");
 	
-	/***/
+	/** FULL */
 	public static final Keyword FULL = new Keyword("FULL");
 	
-	/***/
+	/** PARTIAL */
 	public static final Keyword PARTIAL = new Keyword("PARTIAL");
 	
-	/***/
-	public static final Keyword IMMEDIATE = new Keyword("IMMEDIATE");
+	/** WITH */
+	public static final Keyword WITH = new Keyword("WITH");
 	
-	/***/
-	public static final Keyword DEFERRED = new Keyword("DEFERRED");
+	/** WITHOUT */
+	public static final Keyword WITHOUT = new Keyword("WITHOUT");
 	
+	/** TIMEZONE */
+	public static final Keyword TIMEZONE = new Keyword("TIMEZONE");
+	
 
 	/**
 	 * TODO for daisuke
 	 * 
-	 * @param typeName
+	 * @param keyword
 	 * @return
 	 */
-	public static Keyword of(String typeName) {
-		return new Keyword(typeName);
+	public static Keyword of(String keyword) {
+		return new Keyword(keyword);
 	}
 	
 

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Literal.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Literal.java	2009-02-11 16:35:30 UTC (rev 2651)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Literal.java	2009-02-11 17:13:40 UTC (rev 2652)
@@ -29,6 +29,9 @@
  */
 public class Literal implements Token {
 	
+	/** NULL */
+	public static final Literal NULL = new Literal("NULL", LiteralType.NULL);
+	
 	private final String string;
 	
 
@@ -45,6 +48,7 @@
 	 * インスタンスを生成する。
 	 * 
 	 * @param string
+	 * @param type 
 	 */
 	public Literal(String string, LiteralType type) {
 		Validate.notNull(string);

Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Operator.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Operator.java	                        (rev 0)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Operator.java	2009-02-11 17:13:40 UTC (rev 2652)
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on 2009/02/12
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.model.sql;
+
+import org.apache.commons.lang.Validate;
+
+/**
+ * TODO for daisuke
+ * 
+ * @author daisuke
+ */
+public class Operator implements Token {
+	
+	public static final Operator IS = new Operator("IS");
+	
+	public static final Operator NOT = new Operator("NOT");
+	
+	private final String string;
+	
+
+	/**
+	 * インスタンスを生成する。
+	 * 
+	 * @param string
+	 */
+	Operator(String string) {
+		Validate.notNull(string);
+		this.string = string;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public String toString() {
+		return string;
+	}
+	
+}


Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Operator.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Separator.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Separator.java	2009-02-11 16:35:30 UTC (rev 2651)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/Separator.java	2009-02-11 17:13:40 UTC (rev 2652)
@@ -35,7 +35,10 @@
 	LEFT_PAREN("("),
 
 	/** 右括弧 */
-	RIGHT_PAREN(")");
+	RIGHT_PAREN(")"),
+
+	/** 初期状態 */
+	INITIAL("");
 	
 	private final String string;
 	

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/SqlStatementImpl.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/SqlStatementImpl.java	2009-02-11 16:35:30 UTC (rev 2651)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/model/sql/SqlStatementImpl.java	2009-02-11 17:13:40 UTC (rev 2652)
@@ -60,7 +60,7 @@
 		tokens.add(token);
 	}
 	
-	public List<Token> getTokens() {
+	public List<Token> toTokens() {
 		return CollectionsUtil.newArrayList(tokens);
 	}
 	

Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DataTypeCategory.java
===================================================================
--- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DataTypeCategory.java	2009-02-11 16:35:30 UTC (rev 2651)
+++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/DataTypeCategory.java	2009-02-11 17:13:40 UTC (rev 2652)
@@ -84,9 +84,6 @@
 	/** その他型 */
 	OTHER(Types.OTHER, LiteralType.CHARACTER);
 	
-	private static LiteralType literalType;
-	
-
 	/**
 	 * TODO for daisuke
 	 * 
@@ -103,13 +100,14 @@
 	}
 	
 
+	private LiteralType literalType;
+	
 	private final int sqlType;
 	
 
 	DataTypeCategory(int sqlType, LiteralType literalType) {
 		this.sqlType = sqlType;
 		this.literalType = literalType;
-		
 	}
 	
 	/**
@@ -120,9 +118,4 @@
 	public LiteralType getLiteralType() {
 		return literalType;
 	}
-	
-	public int getSqlType() {
-		return sqlType;
-	}
-	
 }

Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/LiteralType.java
===================================================================
--- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/LiteralType.java	2009-02-11 16:35:30 UTC (rev 2651)
+++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/datatype/LiteralType.java	2009-02-11 17:13:40 UTC (rev 2652)
@@ -11,6 +11,9 @@
 		
 		@Override
 		public String convert(String string) {
+			if (string == null) {
+				return "NULL";
+			}
 			return "'" + string + "'";
 		}
 	},
@@ -19,6 +22,9 @@
 		
 		@Override
 		public String convert(String string) {
+			if (string == null) {
+				return "NULL";
+			}
 			return string;
 		}
 	},
@@ -27,6 +33,9 @@
 		
 		@Override
 		public String convert(String string) {
+			if (string == null) {
+				return "NULL";
+			}
 			return string;
 		}
 	},
@@ -35,6 +44,9 @@
 		
 		@Override
 		public String convert(String string) {
+			if (string == null) {
+				return "NULL";
+			}
 			return "DATE '" + string + "'";
 		}
 	},
@@ -43,6 +55,9 @@
 		
 		@Override
 		public String convert(String string) {
+			if (string == null) {
+				return "NULL";
+			}
 			return "TIME '" + string + "'";
 		}
 	},
@@ -51,6 +66,9 @@
 		
 		@Override
 		public String convert(String string) {
+			if (string == null) {
+				return "NULL";
+			}
 			return "TIMESTAMP '" + string + "'";
 		}
 	},
@@ -59,15 +77,30 @@
 		
 		@Override
 		public String convert(String string) {
+			if (string == null) {
+				return "NULL";
+			}
 			return "INTERVAL " + string;
 		}
 	},
 	
 	/***/
+	NULL {
+		
+		@Override
+		public String convert(String string) {
+			return "NULL";
+		}
+	},
+	
+	/***/
 	FRAGMENT {
 		
 		@Override
 		public String convert(String string) {
+			if (string == null) {
+				return "";
+			}
 			return string;
 		}
 	};

Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/SqlStatement.java
===================================================================
--- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/SqlStatement.java	2009-02-11 16:35:30 UTC (rev 2651)
+++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/model/sql/SqlStatement.java	2009-02-11 17:13:40 UTC (rev 2652)
@@ -31,7 +31,7 @@
  */
 public interface SqlStatement {
 	
-	List<Token> getTokens();
+	List<Token> toTokens();
 	
 	/**
 	 * SQL文に変換する。



Jiemamy-notify メーリングリストの案内
Back to archive index