Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DAB19106B1 for ; Sun, 1 Feb 2015 14:48:44 +0000 (UTC) Received: (qmail 43052 invoked by uid 500); 1 Feb 2015 14:48:45 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 43017 invoked by uid 500); 1 Feb 2015 14:48:45 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 43008 invoked by uid 99); 1 Feb 2015 14:48:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 01 Feb 2015 14:48:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 01 Feb 2015 14:48:14 +0000 Received: (qmail 42703 invoked by uid 99); 1 Feb 2015 14:48:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 01 Feb 2015 14:48:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3A8FFE028F; Sun, 1 Feb 2015 14:48:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akuznetsov@apache.org To: commits@ignite.incubator.apache.org Date: Sun, 01 Feb 2015 14:48:10 -0000 Message-Id: In-Reply-To: <6a6bc385a2164b0eb71c587d5eca0f3d@git.apache.org> References: <6a6bc385a2164b0eb71c587d5eca0f3d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] incubator-ignite git commit: # IGNITE-32: reworked db metadata parser to use dialect. X-Virus-Checked: Checked by ClamAV on apache.org # IGNITE-32: reworked db metadata parser to use dialect. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/7c1a29be Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/7c1a29be Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/7c1a29be Branch: refs/heads/ignite-32 Commit: 7c1a29be35bd1d125a0dfec5a87af78c87a64b20 Parents: fe50f54 Author: AKuznetsov Authored: Sun Feb 1 21:48:01 2015 +0700 Committer: AKuznetsov Committed: Sun Feb 1 21:48:01 2015 +0700 ---------------------------------------------------------------------- .../query/CacheQueryTableColumnMetadata.java | 143 +++++++++ .../cache/query/CacheQueryTableMetadata.java | 134 ++++++++ .../cache/query/CacheQueryTypeDescriptor.java | 135 -------- .../cache/query/CacheQueryTypeMetadata.java | 143 +++------ .../ignite/cache/store/jdbc/JdbcCacheStore.java | 97 +++--- .../cache/store/jdbc/JdbcPojoCacheStore.java | 20 +- .../core/src/test/config/store/jdbc/Ignite.xml | 16 +- modules/schema-load/pom.xml | 1 + .../ignite/schema/generator/XmlGenerator.java | 122 ++++---- .../ignite/schema/model/PojoDescriptor.java | 248 ++++++++++----- .../apache/ignite/schema/model/PojoField.java | 162 ++++------ .../schema/parser/DatabaseMetadataParser.java | 305 +++++-------------- .../apache/ignite/schema/parser/DbColumn.java | 76 +++++ .../apache/ignite/schema/parser/DbIndex.java | 39 +++ .../apache/ignite/schema/parser/DbTable.java | 98 ++++++ .../parser/dialect/DB2MetadataDialect.java | 30 ++ .../parser/dialect/DatabaseMetadataDialect.java | 45 +++ .../parser/dialect/JdbcMetadataDialect.java | 115 +++++++ .../parser/dialect/OracleMetadataDialect.java | 33 ++ .../org/apache/ignite/schema/ui/MessageBox.java | 12 +- .../apache/ignite/schema/ui/SchemaLoadApp.java | 38 +-- .../schema/load/BaseSchemaLoaderSelfTest.java | 13 +- .../load/generator/PojoGeneratorSelfTest.java | 2 +- .../load/generator/XmlGeneratorSelfTest.java | 12 +- .../apache/ignite/schema/load/model/Ignite.xml | 64 ++-- .../load/parser/DbMetadataParserSelfTest.java | 4 +- 26 files changed, 1261 insertions(+), 846 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7c1a29be/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTableColumnMetadata.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTableColumnMetadata.java b/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTableColumnMetadata.java new file mode 100644 index 0000000..059cc8b --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTableColumnMetadata.java @@ -0,0 +1,143 @@ +/* + * 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.ignite.cache.query; + +import org.apache.ignite.internal.util.typedef.internal.*; + +/** + * Database table column metadata. + */ +public class CacheQueryTableColumnMetadata { + /** Column name in database. */ + private String dbName; + + /** Column JDBC type in database. */ + private int dbType; + + /** Column name in database. */ + private String javaName; + + /** Corresponding java type. */ + private Class javaType; + + /** + * Default constructor. + */ + public CacheQueryTableColumnMetadata() { + // No-op. + } + + /** + * @param dbName Column name in database. + * @param dbType Column JDBC type in database. + * @param javaName Field name in java object. + * @param javaType Field java type. + */ + public CacheQueryTableColumnMetadata(String javaName, Class javaType, String dbName, int dbType) { + this.dbName = dbName; + this.dbType = dbType; + this.javaName = javaName; + this.javaType = javaType; + } + + /** + * @return Column name in database. + */ + public String getDbName() { + return dbName; + } + + /** + * @param dbName Column name in database. + */ + public void setDbName(String dbName) { + this.dbName = dbName; + } + + /** + * @return Column JDBC type in database. + */ + public int getDbType() { + return dbType; + } + + /** + * @param dbType Column JDBC type in database. + */ + public void setDbType(int dbType) { + this.dbType = dbType; + } + + /** + * @return Field name in java object. + */ + public String getJavaName() { + return javaName; + } + + /** + * @param javaName Field name in java object. + */ + public void setJavaName(String javaName) { + this.javaName = javaName; + } + + /** + * @return Field java type. + */ + public Class getJavaType() { + return javaType; + } + + /** + * @param javaType Corresponding java type. + */ + public void setJavaType(Class javaType) { + this.javaType = javaType; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (!(o instanceof CacheQueryTableColumnMetadata)) + return false; + + CacheQueryTableColumnMetadata that = (CacheQueryTableColumnMetadata)o; + + return javaName.equals(that.javaName) && dbName.equals(that.dbName) && + javaType == that.javaType && dbType == that.dbType; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int res = dbName.hashCode(); + + res = 31 * res + dbType; + res = 31 * res + javaName.hashCode(); + res = 31 * res + javaType.hashCode(); + + return res; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(CacheQueryTableColumnMetadata.class, this); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7c1a29be/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTableMetadata.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTableMetadata.java b/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTableMetadata.java new file mode 100644 index 0000000..63436cb --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTableMetadata.java @@ -0,0 +1,134 @@ +/* + * 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.ignite.cache.query; + +import org.apache.ignite.internal.util.tostring.*; + +import java.util.*; + +/** + * Database table metadata. + */ +public class CacheQueryTableMetadata { + /** Schema name in database. */ + private String schema; + + /** Table name in database. */ + private String tbl; + + /** Key columns. */ + @GridToStringInclude + private Collection keyCols; + + /** Value columns . */ + @GridToStringInclude + private Collection valCols; + + /** + * Default constructor. + */ + public CacheQueryTableMetadata() { + keyCols = new ArrayList<>(); + valCols = new ArrayList<>(); + } + + /** + * Copy constructor. + * + * @param src Source table metadata. + */ + public CacheQueryTableMetadata(CacheQueryTableMetadata src) { + schema = src.getSchema(); + tbl = src.getTableName(); + + keyCols = new ArrayList<>(src.getKeyColumns()); + valCols = new ArrayList<>(src.getValueColumns()); + } + + /** + * Gets database schema name. + * + * @return Schema name. + */ + public String getSchema() { + return schema; + } + + /** + * Sets database schema name. + * + * @param schema Schema name. + */ + public void setSchema(String schema) { + this.schema = schema; + } + + /** + * Gets table name in database. + * + * @return Table name in database. + */ + public String getTableName() { + return tbl; + } + + /** + * Table name in database. + * + * @param tbl Table name in database. + */ + public void setTableName(String tbl) { + this.tbl = tbl; + } + + /** + * Gets key columns. + * + * @return Key columns. + */ + public Collection getKeyColumns() { + return keyCols; + } + + /** + * Sets key columns. + * + * @param keyCols New key columns. + */ + public void setKeyColumns(Collection keyCols) { + this.keyCols = keyCols; + } + + /** + * Gets value columns. + * + * @return Value columns. + */ + public Collection getValueColumns() { + return valCols; + } + + /** + * Sets value columns. + * + * @param valCols New value columns. + */ + public void setValueColumnbs(Collection valCols) { + this.valCols = valCols; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7c1a29be/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTypeDescriptor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTypeDescriptor.java b/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTypeDescriptor.java deleted file mode 100644 index 9e660cb..0000000 --- a/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTypeDescriptor.java +++ /dev/null @@ -1,135 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.apache.ignite.cache.query; - -import org.apache.ignite.internal.util.typedef.internal.*; - -/** - * Type descriptor for field in java and database. - */ -public class CacheQueryTypeDescriptor { - /** Column name in database. */ - private String javaName; - - /** Corresponding java type. */ - private Class javaType; - - /** Column name in database. */ - private String dbName; - - /** Column JDBC type in database. */ - private int dbType; - - /** - * Default constructor. - */ - public CacheQueryTypeDescriptor() { - // No-op. - } - - /** - * @param javaName Field name in java object. - * @param javaType Field java type. - * @param dbName Column name in database. - * @param dbType Column JDBC type in database. - */ - public CacheQueryTypeDescriptor(String javaName, Class javaType, String dbName, int dbType) { - this.javaName = javaName; - this.javaType = javaType; - this.dbName = dbName; - this.dbType = dbType; - } - - /** - * @return Field name in java object. - */ - public String getJavaName() { - return javaName; - } - - /** - * @param javaName Field name in java object. - */ - public void setJavaName(String javaName) { - this.javaName = javaName; - } - - /** - * @return Field java type. - */ - public Class getJavaType() { - return javaType; - } - - /** - * @param javaType Corresponding java type. - */ - public void setJavaType(Class javaType) { - this.javaType = javaType; - } - - /** - * @return Column name in database. - */ - public String getDbName() { - return dbName; - } - - /** - * @param dbName Column name in database. - */ - public void setDbName(String dbName) { - this.dbName = dbName; - } - - /** - * @return Column JDBC type in database. - */ - public int getDbType() { - return dbType; - } - - /** - * @param dbType Column JDBC type in database. - */ - public void setDbType(int dbType) { - this.dbType = dbType; - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - if (this == o) - return true; - - if (!(o instanceof CacheQueryTypeDescriptor)) - return false; - - CacheQueryTypeDescriptor that = (CacheQueryTypeDescriptor)o; - - return javaName.equals(that.javaName) && dbName.equals(that.dbName) && - javaType == that.javaType && dbType == that.dbType; - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - int res = javaName.hashCode(); - - res = 31 * res + dbName.hashCode(); - res = 31 * res + javaType.hashCode(); - res = 31 * res + dbType; - - return res; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(CacheQueryTypeDescriptor.class, this); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7c1a29be/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTypeMetadata.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTypeMetadata.java b/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTypeMetadata.java index 4a1d8eb..775fde9 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTypeMetadata.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/CacheQueryTypeMetadata.java @@ -27,25 +27,14 @@ import java.util.*; * Cache query type metadata. */ public class CacheQueryTypeMetadata { - /** Type name, e.g. class name. */ - private String type; - - /** Schema name in database. */ - private String schema; - - /** Table name in database. */ - private String tbl; - - /** Key class. */ + /** Key class used to store value in cache. */ private String keyType; - /** Type descriptors. */ - @GridToStringInclude - private Collection keyDescs; + /** Type name, e.g. class name. */ + private String valType; - /** Type descriptors. */ - @GridToStringInclude - private Collection valDescs; + /** Database table metadata.*/ + private CacheQueryTableMetadata tblMeta; /** Fields to be queried, in addition to indexed fields. */ @GridToStringInclude @@ -71,9 +60,7 @@ public class CacheQueryTypeMetadata { * Default constructor. */ public CacheQueryTypeMetadata() { - keyDescs = new ArrayList<>(); - - valDescs = new ArrayList<>(); + tblMeta = new CacheQueryTableMetadata(); qryFlds = new LinkedHashMap<>(); @@ -87,90 +74,27 @@ public class CacheQueryTypeMetadata { } /** - * + * Copy constructor. */ - public CacheQueryTypeMetadata( CacheQueryTypeMetadata src) { - type = src.getType(); + public CacheQueryTypeMetadata(CacheQueryTypeMetadata src) { keyType = src.getKeyType(); - schema = src.getSchema(); - tbl = src.getTableName(); + valType = src.getType(); - keyDescs = new ArrayList<>(src.getKeyDescriptors()); - valDescs = new ArrayList<>(src.getValueDescriptors()); + tblMeta = new CacheQueryTableMetadata(src.getTableMetadata()); qryFlds = new LinkedHashMap<>(src.getQueryFields()); + ascFlds = new LinkedHashMap<>(src.getAscendingFields()); + descFlds = new LinkedHashMap<>(src.getDescendingFields()); + txtFlds = new LinkedHashSet<>(src.getTextFields()); grps = new LinkedHashMap<>(src.getGroups()); } /** - * Gets type (e.g. class name). - * - * @return Type name. - */ - public String getType() { - return type; - } - - /** - * Sets type. - * - * @param cls Type class. - */ - public void setType(Class cls) { - setType(cls.getName()); - } - - /** - * Sets type. - * - * @param type Type name. - */ - public void setType(String type) { - this.type = type; - } - - /** - * Gets database schema name. - * - * @return Schema name. - */ - public String getSchema() { - return schema; - } - - /** - * Sets database schema name. - * - * @param schema Schema name. - */ - public void setSchema(String schema) { - this.schema = schema; - } - - /** - * Gets table name in database. - * - * @return Table name in database. - */ - public String getTableName() { - return tbl; - } - - /** - * Table name in database. - * - * @param tbl Table name in database. - */ - public void setTableName(String tbl) { - this.tbl = tbl; - } - - /** * Gets key type. * * @return Key type. @@ -189,39 +113,48 @@ public class CacheQueryTypeMetadata { } /** - * Gets key fields type descriptors. + * Gets type (e.g. class name). + * + * @return Type name. + */ + public String getType() { + return valType; + } + + /** + * Sets type. * - * @return Key fields type descriptors. + * @param cls Type class. */ - public Collection getKeyDescriptors() { - return keyDescs; + public void setType(Class cls) { + setType(cls.getName()); } /** - * Sets key fields type descriptors. + * Sets type. * - * @param keyDescs Key fields type descriptors. + * @param type Type name. */ - public void setKeyDescriptors(Collection keyDescs) { - this.keyDescs = keyDescs; + public void setType(String type) { + valType = type; } /** - * Gets value fields type descriptors. + * Gets table metadata. * - * @return Key value type descriptors. + * @return table metadata. */ - public Collection getValueDescriptors() { - return valDescs; + public CacheQueryTableMetadata getTableMetadata() { + return tblMeta; } /** - * Sets value fields type descriptors. + * Sets table metadata. * - * @param valDescs Value fields type descriptors. + * @param tblMeta New table metadata. */ - public void setValueDescriptors(Collection valDescs) { - this.valDescs = valDescs; + public void setTableMetadata(CacheQueryTableMetadata tblMeta) { + this.tblMeta = tblMeta; } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7c1a29be/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java index 7fd7494..b6887f0 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java @@ -154,7 +154,7 @@ public abstract class JdbcCacheStore extends CacheStore { * @param rs ResultSet. * @return Constructed object. */ - protected abstract R buildObject(String typeName, Collection fields, ResultSet rs) + protected abstract R buildObject(String typeName, Collection fields, ResultSet rs) throws CacheLoaderException; /** @@ -174,11 +174,12 @@ public abstract class JdbcCacheStore extends CacheStore { protected abstract Object keyId(String type) throws CacheException; /** - * Prepare internal store specific builders for provided type metadata. + * Prepare internal store specific builders for provided types metadata. * + * @param types Collection of types. * @throws CacheException If failed to prepare. */ - protected abstract void prepareBuilders(Collection typeMetadata) throws CacheException; + protected abstract void prepareBuilders(Collection types) throws CacheException; /** * Perform dialect resolution. @@ -434,8 +435,8 @@ public abstract class JdbcCacheStore extends CacheStore { ResultSet rs = stmt.executeQuery(); while (rs.next()) { - K key = buildObject(m.keyType(), m.keyDescriptors(), rs); - V val = buildObject(m.valueType(), m.valueDescriptors(), rs); + K key = buildObject(m.keyType(), m.keyColumns(), rs); + V val = buildObject(m.valueType(), m.valueColumns(), rs); clo.apply(key, val); } @@ -597,7 +598,7 @@ public abstract class JdbcCacheStore extends CacheStore { ResultSet rs = stmt.executeQuery(); if (rs.next()) - return buildObject(em.valueType(), em.valueDescriptors(), rs); + return buildObject(em.valueType(), em.valueColumns(), rs); } catch (SQLException e) { throw new CacheLoaderException("Failed to load object by key: " + key, e); @@ -924,7 +925,7 @@ public abstract class JdbcCacheStore extends CacheStore { */ protected int fillKeyParameters(PreparedStatement stmt, int i, EntryMapping type, Object key) throws CacheException { - for (CacheQueryTypeDescriptor field : type.keyDescriptors()) { + for (CacheQueryTableColumnMetadata field : type.keyColumns()) { Object fieldVal = extractField(type.keyType(), field.getJavaName(), key); try { @@ -960,7 +961,7 @@ public abstract class JdbcCacheStore extends CacheStore { */ protected int fillValueParameters(PreparedStatement stmt, int i, EntryMapping m, Object val) throws CacheWriterException { - for (CacheQueryTypeDescriptor field : m.uniqValFields) { + for (CacheQueryTableColumnMetadata field : m.uniqValFields) { Object fieldVal = extractField(m.valueType(), field.getJavaName(), val); try { @@ -1146,33 +1147,37 @@ public abstract class JdbcCacheStore extends CacheStore { private final Collection cols; /** Unique value fields. */ - private final Collection uniqValFields; + private final Collection uniqValFields; /** Type metadata. */ - private final CacheQueryTypeMetadata typeMetadata; + private final CacheQueryTypeMetadata typeMeta; + + /** Table metadata. */ + private final CacheQueryTableMetadata tblMeta; /** - * @param typeMetadata Type metadata. + * @param typeMeta Type metadata. */ - public EntryMapping(JdbcDialect dialect, CacheQueryTypeMetadata typeMetadata) { + public EntryMapping(JdbcDialect dialect, CacheQueryTypeMetadata typeMeta) { this.dialect = dialect; - this.typeMetadata = typeMetadata; + this.typeMeta = typeMeta; - final Collection keyFields = typeMetadata.getKeyDescriptors(); + tblMeta = typeMeta.getTableMetadata(); - Collection valFields = typeMetadata.getValueDescriptors(); + final Collection keyFields = tblMeta.getKeyColumns(); - uniqValFields = F.view(typeMetadata.getValueDescriptors(), - new IgnitePredicate() { - @Override public boolean apply(CacheQueryTypeDescriptor desc) { - return !keyFields.contains(desc); - } - }); + Collection valFields = tblMeta.getValueColumns(); + + uniqValFields = F.view(valFields, new IgnitePredicate() { + @Override public boolean apply(CacheQueryTableColumnMetadata col) { + return !keyFields.contains(col); + } + }); - String schema = typeMetadata.getSchema(); + String schema = tblMeta.getSchema(); - String tblName = typeMetadata.getTableName(); + String tblName = tblMeta.getTableName(); keyCols = databaseColumns(keyFields); @@ -1202,15 +1207,15 @@ public abstract class JdbcCacheStore extends CacheStore { } /** - * Extract database column names from {@link CacheQueryTypeDescriptor}. + * Extract database column names from {@link CacheQueryTableColumnMetadata}. * - * @param dsc collection of {@link CacheQueryTypeDescriptor}. + * @param dsc collection of {@link CacheQueryTableColumnMetadata}. */ - private static Collection databaseColumns(Collection dsc) { - return F.transform(dsc, new C1() { + private static Collection databaseColumns(Collection dsc) { + return F.transform(dsc, new C1() { /** {@inheritDoc} */ - @Override public String apply(CacheQueryTypeDescriptor desc) { - return desc.getDbName(); + @Override public String apply(CacheQueryTableColumnMetadata col) { + return col.getDbName(); } }); } @@ -1229,7 +1234,7 @@ public abstract class JdbcCacheStore extends CacheStore { if (keyCnt == 1) return loadQrySingle; - return dialect.loadQuery(typeMetadata.getSchema(), typeMetadata.getTableName(), keyCols, cols, keyCnt); + return dialect.loadQuery(tblMeta.getSchema(), tblMeta.getTableName(), keyCols, cols, keyCnt); } /** * Construct query for select values in range. @@ -1239,36 +1244,36 @@ public abstract class JdbcCacheStore extends CacheStore { * @return Query with range. */ protected String loadCacheRangeQuery(boolean appendLowerBound, boolean appendUpperBound) { - return dialect.loadCacheRangeQuery(typeMetadata.getSchema(), typeMetadata.getTableName(), keyCols, cols, + return dialect.loadCacheRangeQuery(tblMeta.getSchema(), tblMeta.getTableName(), keyCols, cols, appendLowerBound, appendUpperBound); } /** Key type. */ protected String keyType() { - return typeMetadata.getKeyType(); + return typeMeta.getKeyType(); } /** Value type. */ protected String valueType() { - return typeMetadata.getType(); + return typeMeta.getType(); } /** - * Gets key fields type descriptors. + * Gets key columns. * - * @return Key fields type descriptors. + * @return Key columns. */ - protected Collection keyDescriptors() { - return typeMetadata.getKeyDescriptors(); + protected Collection keyColumns() { + return tblMeta.getKeyColumns(); } /** - * Gets value fields type descriptors. + * Gets value columns. * - * @return Key value type descriptors. + * @return Value columns. */ - protected Collection valueDescriptors() { - return typeMetadata.getValueDescriptors(); + protected Collection valueColumns() { + return tblMeta.getValueColumns(); } } @@ -1313,8 +1318,8 @@ public abstract class JdbcCacheStore extends CacheStore { ResultSet rs = stmt.executeQuery(); while (rs.next()) { - K1 key = buildObject(m.keyType(), m.keyDescriptors(), rs); - V1 val = buildObject(m.valueType(), m.valueDescriptors(), rs); + K1 key = buildObject(m.keyType(), m.keyColumns(), rs); + V1 val = buildObject(m.valueType(), m.valueColumns(), rs); clo.apply(key, val); } @@ -1369,7 +1374,7 @@ public abstract class JdbcCacheStore extends CacheStore { int i = 1; for (Object key : keys) - for (CacheQueryTypeDescriptor field : m.keyDescriptors()) { + for (CacheQueryTableColumnMetadata field : m.keyColumns()) { Object fieldVal = extractField(m.keyType(), field.getJavaName(), key); if (fieldVal != null) @@ -1383,8 +1388,8 @@ public abstract class JdbcCacheStore extends CacheStore { Map entries = U.newHashMap(keys.size()); while (rs.next()) { - K1 key = buildObject(m.keyType(), m.keyDescriptors(), rs); - V1 val = buildObject(m.valueType(), m.valueDescriptors(), rs); + K1 key = buildObject(m.keyType(), m.keyColumns(), rs); + V1 val = buildObject(m.valueType(), m.valueColumns(), rs); entries.put(key, val); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7c1a29be/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcPojoCacheStore.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcPojoCacheStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcPojoCacheStore.java index 960f93f..71bb5b4 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcPojoCacheStore.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcPojoCacheStore.java @@ -56,7 +56,7 @@ public class JdbcPojoCacheStore extends JdbcCacheStore { * @param clsName Class name. * @param fields Fields. */ - public PojoMethodsCache(String clsName, Collection fields) throws CacheException { + public PojoMethodsCache(String clsName, Collection fields) throws CacheException { try { cls = Class.forName(clsName); @@ -77,7 +77,7 @@ public class JdbcPojoCacheStore extends JdbcCacheStore { getters = U.newHashMap(fields.size()); - for (CacheQueryTypeDescriptor field : fields) { + for (CacheQueryTableColumnMetadata field : fields) { String prop = capitalFirst(field.getJavaName()); try { @@ -134,29 +134,31 @@ public class JdbcPojoCacheStore extends JdbcCacheStore { protected Map mtdsCache; /** {@inheritDoc} */ - @Override protected void prepareBuilders(Collection typeMetadata) throws CacheException { - mtdsCache = U.newHashMap(typeMetadata.size() * 2); + @Override protected void prepareBuilders(Collection types) throws CacheException { + mtdsCache = U.newHashMap(types.size() * 2); - for (CacheQueryTypeMetadata type : typeMetadata) { - PojoMethodsCache keyCache = new PojoMethodsCache(type.getKeyType(), type.getKeyDescriptors()); + for (CacheQueryTypeMetadata type : types) { + CacheQueryTableMetadata tblMeta = type.getTableMetadata(); + + PojoMethodsCache keyCache = new PojoMethodsCache(type.getKeyType(), tblMeta.getKeyColumns()); mtdsCache.put(type.getKeyType(), keyCache); - mtdsCache.put(type.getType(), new PojoMethodsCache(type.getType(), type.getValueDescriptors())); + mtdsCache.put(type.getType(), new PojoMethodsCache(type.getType(), tblMeta.getValueColumns())); } mtdsCache = Collections.unmodifiableMap(mtdsCache); } /** {@inheritDoc} */ - @Override protected R buildObject(String typeName, Collection fields, + @Override protected R buildObject(String typeName, Collection fields, ResultSet rs) throws CacheLoaderException { PojoMethodsCache t = mtdsCache.get(typeName); Object obj = t.newInstance(); try { - for (CacheQueryTypeDescriptor field : fields) + for (CacheQueryTableColumnMetadata field : fields) t.setters.get(field.getJavaName()).invoke(obj, rs.getObject(field.getDbName())); return (R)obj; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7c1a29be/modules/core/src/test/config/store/jdbc/Ignite.xml ---------------------------------------------------------------------- diff --git a/modules/core/src/test/config/store/jdbc/Ignite.xml b/modules/core/src/test/config/store/jdbc/Ignite.xml index cc5f117..6cd8287 100644 --- a/modules/core/src/test/config/store/jdbc/Ignite.xml +++ b/modules/core/src/test/config/store/jdbc/Ignite.xml @@ -29,7 +29,7 @@ - +