CAY-2116 Split schema synchronization code in a separate module * removing unused code... prolly work in progress ... does not belong on master
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/f3d73743 Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/f3d73743 Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/f3d73743 Branch: refs/heads/master Commit: f3d737435953330c176023a9ef7b69314ea72518 Parents: 2ba43b0 Author: Andrus Adamchik <and...@objectstyle.com> Authored: Fri Sep 30 14:55:48 2016 +0300 Committer: Andrus Adamchik <and...@objectstyle.com> Committed: Fri Sep 30 14:55:48 2016 +0300 ---------------------------------------------------------------------- .../config/DefaultTypeMapperBuilder.java | 82 ---------- .../cayenne/tools/dbimport/config/Type.java | 151 ------------------- .../tools/dbimport/config/TypeMapper.java | 101 ------------- 3 files changed, 334 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/f3d73743/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/DefaultTypeMapperBuilder.java ---------------------------------------------------------------------- diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/DefaultTypeMapperBuilder.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/DefaultTypeMapperBuilder.java deleted file mode 100644 index c8cab3a..0000000 --- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/DefaultTypeMapperBuilder.java +++ /dev/null @@ -1,82 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.cayenne.tools.dbimport.config; - -import org.apache.cayenne.dbsync.reverse.mapper.DbType; -import org.apache.cayenne.dbsync.reverse.mapper.DefaultJdbc2JavaTypeMapper; -import org.apache.cayenne.dbsync.reverse.mapper.Jdbc2JavaTypeMapper; -import org.apache.commons.lang.ClassUtils; -import org.apache.commons.logging.Log; - -import static org.apache.commons.lang.StringUtils.isBlank; - -/** - * @since 4.0. - */ -public class DefaultTypeMapperBuilder { - - private final DefaultJdbc2JavaTypeMapper mapper; - private final Log logger; - - public DefaultTypeMapperBuilder(Log logger, TypeMapper typeMapper) { - this.logger = logger; - this.mapper = createMapper(typeMapper.getMapperClassName()); - - for (Type type : typeMapper.getTypes()) { - this.mapper.add(buildType(type), type.getJava()); - } - } - - private DbType buildType(Type type) { - return new DbType( - type.getJdbc(), - type.getLength(), - type.getPrecision(), - type.getScale(), - type.getNotNull() - ); - } - - private DefaultJdbc2JavaTypeMapper createMapper(String className) { - if (!isBlank(className)) { - try { - return (DefaultJdbc2JavaTypeMapper) ClassUtils.getClass(Thread.currentThread() - .getContextClassLoader(), className).newInstance(); - } catch (ClassNotFoundException e) { - logger.error("Can't load class '" + className + "': ", e); - } catch (InstantiationException e) { - logger.error("Can't instantiate '" + className + "' make sure it has default constructor.", e); - } catch (IllegalAccessException e) { - logger.error("Can't instantiate '" + className + "' make sure it has default constructor.", e); - } - } - - return new DefaultJdbc2JavaTypeMapper(); - } - - public DefaultTypeMapperBuilder setUsePrimitives(Boolean usePrimitives) { - mapper.setUsePrimitives(usePrimitives); - - return this; - } - - public Jdbc2JavaTypeMapper build() { - return mapper; - } -} http://git-wip-us.apache.org/repos/asf/cayenne/blob/f3d73743/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Type.java ---------------------------------------------------------------------- diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Type.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Type.java deleted file mode 100644 index b995c62..0000000 --- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Type.java +++ /dev/null @@ -1,151 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.cayenne.tools.dbimport.config; - -import org.apache.cayenne.util.ToStringBuilder; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; - -/** - * @since 4.0. - */ -@XmlAccessorType(XmlAccessType.FIELD) -public class Type { - - @XmlElement(name = "jdbc") - private String jdbc; - - @XmlElement(name = "java") - private String java; - - @XmlElement(name = "length") - private Integer length; - - @XmlElement(name = "precision") - private Integer precision; - - @XmlElement(name = "scale") - private Integer scale; - - @XmlElement(name = "notNull") - private Boolean notNull; - - public String getJdbc() { - return jdbc; - } - - public void setJdbc(String jdbc) { - this.jdbc = jdbc; - } - - public String getJava() { - return java; - } - - public void setJava(String java) { - this.java = java; - } - - public Integer getLength() { - return length; - } - - public void setLength(Integer length) { - this.length = length; - } - - public Integer getPrecision() { - return precision; - } - - public void setPrecision(Integer precision) { - this.precision = precision; - } - - public Integer getScale() { - return scale; - } - - public void setScale(Integer scale) { - this.scale = scale; - } - - public Boolean getNotNull() { - return notNull; - } - - public void setNotNull(Boolean notNull) { - this.notNull = notNull; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - Type type = (Type) o; - - if (jdbc != null ? !jdbc.equals(type.jdbc) : type.jdbc != null) { - return false; - } - if (!length.equals(type.length)) { - return false; - } - if (!notNull.equals(type.notNull)) { - return false; - } - if (!precision.equals(type.precision)) { - return false; - } - if (!scale.equals(type.scale)) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result = jdbc != null ? jdbc.hashCode() : 0; - result = 31 * result + length.hashCode(); - result = 31 * result + precision.hashCode(); - result = 31 * result + scale.hashCode(); - result = 31 * result + notNull.hashCode(); - return result; - } - - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("jdbc", jdbc) - .append("java", java) - .append("length", length) - .append("precision", precision) - .append("scale", scale) - .append("notNull", notNull) - .toString(); - } -} http://git-wip-us.apache.org/repos/asf/cayenne/blob/f3d73743/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/TypeMapper.java ---------------------------------------------------------------------- diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/TypeMapper.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/TypeMapper.java deleted file mode 100644 index 048c753..0000000 --- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/TypeMapper.java +++ /dev/null @@ -1,101 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.cayenne.tools.dbimport.config; - -import org.apache.cayenne.util.EqualsBuilder; -import org.apache.cayenne.util.HashCodeBuilder; - -import javax.xml.bind.annotation.*; -import java.util.Collection; -import java.util.LinkedList; - -/** - * @since 4.0. - */ -@XmlRootElement(name = "typeMapper") -@XmlAccessorType(XmlAccessType.FIELD) -public class TypeMapper { - - @XmlElement(name = "mapperClassName") - private String mapperClassName; - - @XmlElement(name = "usePrimitives") - private Boolean usePrimitives; - - @XmlElement(name = "type") - private Collection<Type> types = new LinkedList<Type>(); - - public String getMapperClassName() { - return mapperClassName; - } - - public void setMapperClassName(String mapperClassName) { - this.mapperClassName = mapperClassName; - } - - public Boolean getUsePrimitives() { - return usePrimitives; - } - - public void setUsePrimitives(Boolean usePrimitives) { - this.usePrimitives = usePrimitives; - } - - public Collection<Type> getTypes() { - return types; - } - - public void setTypes(Collection<Type> types) { - this.types = types; - } - - public void addType(Type type) { - this.types.add(type); - } - - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (obj.getClass() != getClass()) { - return false; - } - TypeMapper rhs = (TypeMapper) obj; - return new EqualsBuilder() - .append(this.mapperClassName, rhs.mapperClassName) - .append(this.usePrimitives, rhs.usePrimitives) - .append(this.types, rhs.types) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder().append(mapperClassName).append(usePrimitives).append(types).toHashCode(); - } - - @Override - public String toString() { - return "TypeMapper {mapperClassName=" + mapperClassName + ", usePrimitives=" + usePrimitives + ", types=" + types + '}'; - } -}