diff options
Diffstat (limited to 'tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder')
13 files changed, 0 insertions, 1627 deletions
diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DataObjectMaker.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DataObjectMaker.java deleted file mode 100644 index 2d58c0f269..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DataObjectMaker.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.impl; - -import java.util.Iterator; - -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Type; -import commonj.sdo.helper.DataFactory; - -public class DataObjectMaker { - - private final DataObject rootObject; - - private boolean debug = false; - - public DataObjectMaker(DataObject root) { - this.rootObject = root; - } - - /** - * @param tableData - * @return - */ - public DataObject createAndAddDataObject(TableData tableData, - ResultMetadata resultMetadata) { - // Get a Type from the package and create a standalone DataObject - - DebugUtil.debugln(getClass(), this.debug, "Looking for Type for " - + tableData.getTableName()); - - Type tableClass = findTableTypeByPropertyName(tableData.getTableName()); - - if (tableClass == null) - throw new RuntimeException("An SDO Type with name " - + tableData.getTableName() + " was not found"); - - DataObject obj = DataFactory.INSTANCE.create(tableClass); - - // Now, check to see if the root data object has a containment reference - // to this EClass. If so, add it to the graph. If not, it will be taken - // care - // of when we process relationships - - Iterator i = this.rootObject.getType().getProperties().iterator(); - while (i.hasNext()) { - Property p = (Property) i.next(); - - if (p.isContainment() && p.getType().equals(tableClass)) { - if (p.isMany()) - rootObject.getList(p).add(obj); - // TODO This was a performance optimization for EMF in SDO 1.1, - // check to see if there is - // something equivalent in SDO 2.0 - // ((InternalEList) this.dataGraph.eGet(ref)).addUnique(obj); - else - this.rootObject.set(p, obj); - } - - } - - Iterator columnNames = resultMetadata.getColumnNames( - tableData.getTableName()).iterator(); - while (columnNames.hasNext()) { - String columnName = (String) columnNames.next(); - DataObject dataObject = (DataObject) obj; - Property p = findProperty(dataObject.getType(), columnName); - Object value = tableData.getColumnData(columnName); - - dataObject.set(p, value); - } - - return obj; - } - - // temporary, ignoring case - private Property findProperty(Type type, String columnName) { - Iterator properties = type.getProperties().iterator(); - while (properties.hasNext()) { - Property p = (Property) properties.next(); - if (columnName.equalsIgnoreCase(p.getName())) - return p; - } - return null; - } - - private Type findTableTypeByPropertyName(String tableName) { - Iterator i = rootObject.getType().getProperties().iterator(); - while (i.hasNext()) { - Property p = (Property) i.next(); - // System.out.println(p.getType().getName()); - if (tableName.equals(p.getType().getName())) - return p.getType(); - } - - return null; - } - - private Type findTableTypeByRootReference(String refName) { - return rootObject.getProperty(refName).getType(); - } - -} diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DefaultConverter.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DefaultConverter.java deleted file mode 100644 index 54c536d95c..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DefaultConverter.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.impl; - -import java.sql.Blob; -import java.sql.SQLException; - -import org.apache.tuscany.das.rdb.Converter; - - -public class DefaultConverter implements Converter { - - public DefaultConverter() { - super(); - } - - public Object getColumnValue(Object data) { - return data; - } - - public Object getPropertyValue(Object data) { -// if (type.isInstance(data)) -// return data; -// -// if ( data == null ) -// return null; -// -// String name = type.getInstanceClass().getName(); -// if (name == "java.lang.Byte" || name == "byte") { -// return new Byte(data.toString()); -// } -// -// else if (name == "java.lang.Double" || name == "double") { -// return new Double(data.toString()); -// } -// -// else if (name == "java.lang.Float" || name == "float") { -// return new Float(data.toString()); -// } -// -// else if (name == "java.lang.Integer" || name == "int") { -// return new Integer(data.toString()); -// } -// -// else if (name == "java.lang.Long" || name == "long") { -// return new Long(data.toString()); -// } -// -// else if (name == "java.lang.Short" || name == "short") { -// return new Short(data.toString()); -// } -// -// else if (name == "java.lang.String") { -// return String.valueOf(data.toString()); -// } - - if ( data instanceof Blob ) { - Blob b = (Blob) data; - try { - return b.getBytes(1, (int)b.length()); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } else { - return data; - } - - - -// else { -// -// throw new IllegalArgumentException("The database value of type " -// + data.getClass().getName() + " must be converted to type " -// + type.getInstanceClass().getName()); -// } - } -} diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java deleted file mode 100644 index 6247dea757..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.impl; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -import org.apache.tuscany.das.rdb.ResultSetShape; -import org.apache.tuscany.das.rdb.config.Config; -import org.apache.tuscany.das.rdb.graphbuilder.schema.ESchemaMaker; -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.Type; - - -/** - */ -public class GraphBuilderMetadata { - - private Config mappingModel; - private final Collection resultSets = new ArrayList(); - private boolean debug = false; - private Type schema; - - - public GraphBuilderMetadata(Collection results, Type schema, Config model, ResultSetShape shape) throws SQLException { - this.mappingModel = model; - this.schema = schema; - - Iterator i = results.iterator(); - while (i.hasNext()) { - ResultSet rs = (ResultSet) i.next(); - ResultMetadata resultMetadata = new ResultMetadata(rs, mappingModel, shape); - resultSets.add(resultMetadata); - } - - DebugUtil.debugln(getClass(), debug, "Mapping model: " + mappingModel); - } - - - public Collection getResultMetadata() { - return this.resultSets; - } - - - public boolean hasMappingModel() { - return mappingModel == null ? false : true; - } - - - /** - * @return - */ - - public Collection getRelationships() { - if (!hasMappingModel()) { - DebugUtil.debugln(getClass(), debug, "No relationships to return"); - return Collections.EMPTY_LIST; - } - - return mappingModel.getRelationship(); - } - - - /** - * @return - */ - public Type getSchema() { - if ( this.schema == null ) { - ESchemaMaker schemaMaker = new ESchemaMaker(this); - return schemaMaker.createTypes(); - } else { - return this.schema; - } - } - - public Config getMapping() { - return this.mappingModel; - } -} diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/MultiTableRegistry.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/MultiTableRegistry.java deleted file mode 100644 index 142aee5c60..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/MultiTableRegistry.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.impl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.DataObject; - - - -/** - * - * Used to store and look up table objects based on primary key - * This could be a lot more efficient if we could use LinkedHashMap from JDK 1.4 - */ -public class MultiTableRegistry implements TableRegistry { - - private HashMap tableNameMap; - private HashMap tableValueMap; - private boolean debug = false; - - - public MultiTableRegistry() { - tableNameMap = new HashMap(); - tableValueMap = new HashMap(); - } - - - - /** - * Get the table with the specified name and primary key - * @param tableName - * @param primaryKey - * @return EDataObject - */ - public DataObject get(String tableName, List primaryKey) { - if ( debug ) { - DebugUtil.debugln(getClass(), debug, "Looking for table " + tableName + " with PK " + primaryKey); - DebugUtil.debugln(getClass(), debug, ("\tReturning " + getPkMap(tableName).get(primaryKey))); - } - return (DataObject) getPkMap(tableName).get(primaryKey); - } - - /** - * Add the table with the specified name and primary key - * @param tableName - * @param primaryKey - * @param value - */ - public void put(String tableName, List primaryKey, DataObject value) { - if ( getPkMap(tableName).put(primaryKey, value) == null ) - getCreateValueList(tableName).add(value); - } - - /** - * Get the HashMap that contains the primary key to table object - * mappings. - * @param tableName - * @return HashMap - */ - private HashMap getPkMap(String tableName) { - HashMap pkMap = (HashMap)tableNameMap.get(tableName); - if ( pkMap == null ) { - pkMap = new HashMap(); - tableNameMap.put(tableName, pkMap); - } - return pkMap; - } - - private List getCreateValueList(String tableName) { - List values = (List) tableValueMap.get(tableName); - if ( values == null ) { - values = new ArrayList(); - tableValueMap.put(tableName, values); - } - return values; - } - - - - public boolean contains(String tableName, List primaryKey) { - return get(tableName,primaryKey) == null ? false : true; - - } - - -}
\ No newline at end of file diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultMetadata.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultMetadata.java deleted file mode 100644 index 04c873db13..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultMetadata.java +++ /dev/null @@ -1,293 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.impl; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; - -import org.apache.tuscany.das.rdb.Converter; -import org.apache.tuscany.das.rdb.ResultSetShape; -import org.apache.tuscany.das.rdb.config.Column; -import org.apache.tuscany.das.rdb.config.Config; -import org.apache.tuscany.das.rdb.config.Table; -import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper; -import org.apache.tuscany.das.rdb.config.wrapper.TableWrapper; -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.Type; - -public class ResultMetadata { - - private HashMap tableToColumnMap = new HashMap(); - - private ArrayList tablePropertyNames = new ArrayList(); - - private ArrayList columnPropertyNames = new ArrayList(); - - private final ResultSet resultSet; - - private final ResultSetShape resultSetShape; - - private final MappingWrapper mappingWrapper; - - private Converter[] converters; - - private static boolean debug = false; - - public ResultMetadata(ResultSet rs, Config model, ResultSetShape shape) - throws SQLException { - debug("Creating new ResultMetadata with mapping model " + model); - this.resultSet = rs; - this.mappingWrapper = new MappingWrapper(model); - - if (shape == null) - this.resultSetShape = new ResultSetShape(rs.getMetaData()); - else - this.resultSetShape = shape; - - this.converters = new Converter[resultSetShape.getColumnCount()]; - - for (int i = 1; i <= resultSetShape.getColumnCount(); i++) { - String tableName = resultSetShape.getTableName(i); - - String tableProperty = mappingWrapper - .getTablePropertyName(tableName); - String columnProperty = mappingWrapper.getColumnPropertyName( - tableName, resultSetShape.getColumnName(i)); - String converter = mappingWrapper.getConverter(tableName, - resultSetShape.getColumnName(i)); - if (converter != null) { - - try { - - Class converterClazz= Class.forName(converter, true, Thread.currentThread().getContextClassLoader()); - if(null != converterClazz) - converters[i - 1]= (Converter) converterClazz.newInstance(); - - }catch( Exception e){ - //try loading below.... - converters[i - 1]= null; //safety - } - - - if(null == converters[i - 1] ) - try{ - - - Converter convInstance = (Converter) Class.forName( - converter).newInstance(); - converters[i - 1] = convInstance; - } catch (Exception ex) { - throw new RuntimeException(ex); - } - - } else { - // TODO make static - converters[i - 1] = new DefaultConverter(); - } - DebugUtil.debugln(getClass(), debug, "Adding table/column: " - + tableProperty + "/" + columnProperty); - tablePropertyNames.add(tableProperty); - columnPropertyNames.add(columnProperty); - - Collection columns = (Collection) tableToColumnMap - .get(tableProperty); - if (columns == null) - columns = new ArrayList(); - columns.add(columnProperty); - tableToColumnMap.put(tableProperty, columns); - } - - // Add any tables defined in the model but not included in the ResultSet - // to the list of propertyNames - if (model != null) { - Iterator tablesFromModel = model.getTable().iterator(); - while (tablesFromModel.hasNext()) { - TableWrapper t = new TableWrapper((Table) tablesFromModel - .next()); - if (tableToColumnMap.get(t.getPropertyName()) == null) - tableToColumnMap.put(t.getPropertyName(), - Collections.EMPTY_LIST); - } - } - - if (debug) { - DebugUtil.debugln(getClass(), debug, toString()); - DebugUtil - .debugln(getClass(), debug, this.resultSetShape.toString()); - } - - } - - private void debug(Object string) { - if (debug) - DebugUtil.debugln(getClass(), debug, string); - } - - public Collection getColumnNames() { - return columnPropertyNames; - } - - public String getColumnPropertyName(int i) { - return (String) columnPropertyNames.get(i - 1); - } - - public String getDatabaseColumnName(int i) { - return resultSetShape.getColumnName(i); - } - - public String getTableName(String columnName) { - return (String) tablePropertyNames.get(columnPropertyNames - .indexOf(columnName)); - } - - public int getTableSize(String tableName) { - return ((Collection) tableToColumnMap.get(tableName)).size(); - } - - public Type getDataType(String columnName) { - return resultSetShape.getColumnType(columnPropertyNames - .indexOf(columnName)); - } - - public String getTablePropertyName(int i) { - return (String) tablePropertyNames.get(i - 1); - } - - public Collection getAllTablePropertyNames() { - return tableToColumnMap.keySet(); - } - - public String toString() { - - StringBuffer result = new StringBuffer(super.toString()); - result.append(" (Table Names: "); - Iterator i = tablePropertyNames.iterator(); - while (i.hasNext()) { - String tableName = (String) i.next(); - result.append(' '); - result.append(tableName); - result.append(','); - } - - result.append(" columnNames: "); - - i = columnPropertyNames.iterator(); - while (i.hasNext()) { - String columnName = (String) i.next(); - result.append(' '); - result.append(columnName); - result.append(','); - } - - result.append(" mappingModel: "); - result.append(this.mappingWrapper.getConfig()); - - result.append(" resultSet: "); - result.append(resultSet); - - result.append(" resultSetSize: "); - result.append(resultSetShape.getColumnCount()); - result.append(')'); - return result.toString(); - - } - - /** - * @return - */ - public int getNumberOfTables() { - return tableToColumnMap.keySet().size(); - } - - /** - * Return whether the column at the given position is part of a primary key. - * If we don't have this information, we assume every column is a primary - * key. This results in uniqueness checks using all columns in a table. - * - * @param i - * @return - */ - public boolean isPKColumn(int i) { - if (debug) { - DebugUtil.debugln(getClass(), debug, "Checking to see if " - + getColumnPropertyName(i) + " is a PK column in " - + getTablePropertyName(i)); - } - if (!hasMappingModel()) { - if (debug) - DebugUtil - .debugln(getClass(), debug, - "No mapping model exists, all columns will be considered PK columns"); - return true; - } else { - Table t = mappingWrapper.getTable(getTablePropertyName(i)); - if (t == null) - return true; - Column c = mappingWrapper.getColumn(t, getDatabaseColumnName(i)); - - if (c == null) - return false; - - if (c.isPrimaryKey()) - return true; - } - return false; - } - - public boolean hasMappingModel() { - return mappingWrapper.getConfig() == null ? false : true; - } - - /** - * @param i - * @return - */ - public Type getDataType(int i) { - return resultSetShape.getColumnType(i); - } - - /** - * @param tableName - * @return - */ - public Collection getColumnNames(String tableName) { - return (Collection) tableToColumnMap.get(tableName); - } - - public ResultSet getResultSet() { - return this.resultSet; - } - - public int getResultSetSize() { - return resultSetShape.getColumnCount(); - } - - public boolean isRecursive() { - return mappingWrapper.hasRecursiveRelationships(); - } - - public Converter getConverter(int i) { - return converters[i - 1]; - } - -} diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetProcessor.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetProcessor.java deleted file mode 100644 index 8ccc0aee12..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetProcessor.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.impl; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Iterator; - -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.DataObject; - -/** - * - * A ResultSetProcessor is used to transform the data in a ResultSet into a set - * of inter-related EDataObjects. - */ -public class ResultSetProcessor { - - private TableRegistry registry; - - private GraphBuilderMetadata metadata; - - private boolean debug = false; - - private final DataObjectMaker doMaker; - - public ResultSetProcessor(DataObject g, GraphBuilderMetadata gbmd) { - - this.metadata = gbmd; - if (metadata.getRelationships().size() == 0) - registry = new SingleTableRegistry(); - else - registry = new MultiTableRegistry(); - - doMaker = new DataObjectMaker(g); - - debug(metadata); - - } - - private void debug(Object output) { - DebugUtil.debugln(getClass(), debug, output); - } - - /** - * Process the ResultSet. For each row in the ResultSet, a - * - * @link ResultSetRow object will be created to represent the row as a set - * of EDataObjects. Then, the relevant relationships will be - * constructed between each object in the - * @link ResultSetRow. - * - * @param rs - * The ResultSet - */ - public void processResults(int start, int end) throws SQLException { - - Iterator i = metadata.getResultMetadata().iterator(); - while ( i.hasNext()) { - ResultMetadata resultMetadata = (ResultMetadata)i.next(); - ResultSet results = resultMetadata.getResultSet(); - - processResultSet(results, resultMetadata, start, end); - - //TODO These statements HAVE to be closed or we will have major problems - //results.getStatement().close(); - results.close(); - } - - } - - - private void processResultSet(ResultSet rs, ResultMetadata rsMetadata, - int start, int end) throws SQLException { - - if ( rs.getType() == ResultSet.TYPE_FORWARD_ONLY) { - while (rs.next() && start < end) { - ResultSetRow rsr = new ResultSetRow(rs, rsMetadata); - addRowToGraph(rsr, rsMetadata); - ++start; - } - } else { - while (rs.absolute(start) && start < end) { - ResultSetRow rsr = new ResultSetRow(rs, rsMetadata); - addRowToGraph(rsr, rsMetadata); - ++start; - } - } - } - - /** - * @param row - * @param resultMetadata - */ - private void addRowToGraph(ResultSetRow row, ResultMetadata resultMetadata) { - RowObjects tableObjects = new RowObjects(metadata, registry); - Iterator tables = row.getAllTableData().iterator(); - while (tables.hasNext()) { - TableData rawDataFromRow = (TableData) tables.next(); - - if ( (resultMetadata.hasMappingModel()) && (!rawDataFromRow.hasValidPrimaryKey() ) ) - continue; - - String tableName = rawDataFromRow.getTableName(); - DataObject tableObject = registry.get(tableName, rawDataFromRow - .getPrimaryKeyValues()); - if (tableObject == null) { - tableObject = doMaker.createAndAddDataObject(rawDataFromRow, resultMetadata); - - debug("Putting table " + tableName + " with PK " + rawDataFromRow.getPrimaryKeyValues() + " into registry"); - - registry.put(tableName, rawDataFromRow.getPrimaryKeyValues(), - tableObject); - } - tableObjects.put(tableName, tableObject); - } - - tableObjects.processRelationships(); - - } - -} diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetRow.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetRow.java deleted file mode 100644 index f68f48fc06..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetRow.java +++ /dev/null @@ -1,169 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.impl; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; - -import org.apache.tuscany.das.rdb.util.DebugUtil; - - -/** - * - * A ResultSetRow is used to transform a single row of a ResultSet into a set of - * EDataObjects. - */ -public class ResultSetRow { - - private final ResultMetadata metadata; - - private HashMap tableMap = new HashMap(); - - private ArrayList allTableData; - - private boolean debug = false; - - /** - * Method ResultSetRow. - * - * @param rs - * A ResultSet positioned on the desired row - * @param ePackage - * The package used to create EDataObjects - */ - public ResultSetRow(ResultSet rs, ResultMetadata m) throws SQLException { - this.metadata = m; - if (m.isRecursive()) - processRecursiveRow(rs); - else - processRow(rs); - } - - /** - * Processes a single row in the ResultSet Method processRow. - * - * @param rs - */ - private void processRow(ResultSet rs) throws SQLException { - - DebugUtil.debugln(getClass(), debug, ""); - for (int i = 1; i <= metadata.getResultSetSize(); i++) { - Object data = getObject(rs, i); - - TableData table = getRawData(metadata.getTablePropertyName(i)); - DebugUtil.debugln(getClass(), debug, "Adding column: " - + metadata.getColumnPropertyName(i) + "\tValue: " + data - + "\tTable: " + metadata.getTablePropertyName(i)); - table.addData(metadata.getColumnPropertyName(i), metadata - .isPKColumn(i), data); - } - - } - - public void processRecursiveRow(ResultSet rs) throws SQLException { - this.allTableData = new ArrayList(); - int i = 1; - DebugUtil.debugln(getClass(), debug, ""); - while (i <= metadata.getResultSetSize()) { - DebugUtil.debugln(getClass(), debug, ""); - TableData table = new TableData(metadata.getTablePropertyName(i)); - this.allTableData.add(table); - - while ( (i <= metadata.getResultSetSize()) && (metadata.isPKColumn(i))) { - Object data = getObject(rs, i); - DebugUtil.debugln(getClass(), debug, "Adding column: " - + metadata.getColumnPropertyName(i) + "\tValue: " + data - + "\tTable: " + metadata.getTablePropertyName(i)); - table.addData(metadata.getColumnPropertyName(i), true, data); - i++; - } - - while ( (i <= metadata.getResultSetSize()) && - (!metadata.isPKColumn(i))) { - Object data = getObject(rs, i); - DebugUtil.debugln(getClass(), debug, "Adding column: " - + metadata.getColumnPropertyName(i) + "\tValue: " + data - + "\tTable: " + metadata.getTablePropertyName(i)); - table.addData(metadata.getColumnPropertyName(i), false, data); - i++; - } - } - } - - /** - * @param rs - * @param metadata - * @param i - * @return - */ - private Object getObject(ResultSet rs, int i) - throws SQLException { - - Object data = rs.getObject(i); - - if (rs.wasNull()) - return null; - else - return metadata.getConverter(i).getPropertyValue(data); - } - - /** - * Returns a HashMap that holds data for the specified table - * - * @param tableName - * The name of the table - * @return HashMap - */ - public TableData getTable(String tableName) { - return (TableData) tableMap.get(tableName); - } - - /** - * Returns a HashMap that holds data for the specified table If the HashMap - * doesn't exist, it will be created. This is used internally to build the - * ResultSetRow, whereas getTable is used externally to retrieve existing - * table data. - * - * @param tableName - * The name of the table - * @return HashMap - */ - private TableData getRawData(String tableName) { - - TableData table = (TableData) tableMap.get(tableName); - - if (table == null) { - table = new TableData(tableName); - tableMap.put(tableName, table); - } - - return table; - } - - public ArrayList getAllTableData() { - if ( this.allTableData == null ) { - this.allTableData = new ArrayList(); - this.allTableData.addAll(tableMap.values()); - } - DebugUtil.debugln(getClass(), debug, allTableData); - - return this.allTableData; - } - -} diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/RowObjects.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/RowObjects.java deleted file mode 100644 index f0df0ab7c3..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/RowObjects.java +++ /dev/null @@ -1,140 +0,0 @@ -/** -* -* Copyright 2005 The Apache Software Foundation or its licensors, as applicable. -* -* 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.apache.tuscany.das.rdb.graphbuilder.impl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - -import org.apache.tuscany.das.rdb.config.KeyPair; -import org.apache.tuscany.das.rdb.config.Relationship; -import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper; -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; - - -public class RowObjects { - - private HashMap objectsByTableName; - - private ArrayList tableObjects; - - private static final boolean debug = false; - - private final GraphBuilderMetadata metadata; - - private final TableRegistry registry; - - public RowObjects(GraphBuilderMetadata metadata, TableRegistry registry) { - objectsByTableName = new HashMap(); - tableObjects = new ArrayList(); - this.metadata = metadata; - this.registry = registry; - } - - public void put(String key, DataObject value) { - objectsByTableName.put(key, value); - tableObjects.add(value); - } - - public DataObject get(String tablePropertyName) { - return (DataObject) objectsByTableName.get(tablePropertyName); - } - - void processRelationships() { - MappingWrapper wrapper = new MappingWrapper(metadata.getMapping()); - if (wrapper.hasRecursiveRelationships()) { - processRecursiveRelationships(wrapper); - return; - } - - Iterator i = metadata.getRelationships().iterator(); - while (i.hasNext()) { - Relationship r = (Relationship) i.next(); - - - DataObject parentTable = get(wrapper - .getTablePropertyName(r.getPrimaryKeyTable())); - DataObject childTable = get(wrapper - .getTablePropertyName(r.getForeignKeyTable())); - - DebugUtil.debugln(getClass(), debug, "Parent table: " + parentTable); - DebugUtil.debugln(getClass(), debug, "Child table: " + childTable); - - if ((parentTable == null) || (childTable == null)) - continue; - - Property p = parentTable.getType().getProperty(r.getName()); - setOrAdd(parentTable, childTable, p); - - } - } - - - - private void processRecursiveRelationships(MappingWrapper wrapper) { - Iterator i = tableObjects.iterator(); - while (i.hasNext()) { - DataObject table = (DataObject) i.next(); - - Iterator relationships = wrapper.getRelationshipsByChildTable(table.getType().getName()).iterator(); - while ( relationships.hasNext() ) { - Relationship r = (Relationship) relationships.next(); - - DataObject parentTable = findParentTable(table, r, wrapper); - - if (parentTable == null) - continue; - - Property p = parentTable.getType().getProperty(r.getName()); - setOrAdd(parentTable, table, p); - } - - } - } - - private void setOrAdd(DataObject parent, DataObject child, Property p) { - if (p.isMany()) { - parent.getList(p).add(child); - } else { - parent.set(p, child); - } - } - - private DataObject findParentTable(DataObject childTable, - Relationship r, MappingWrapper wrapper) { - - ArrayList fkValue = new ArrayList(); - Iterator keyPairs = r.getKeyPair().iterator(); - while (keyPairs.hasNext()) { - KeyPair pair = (KeyPair) keyPairs.next(); - String childProperty = wrapper.getColumnPropertyName(r.getPrimaryKeyTable(), pair.getForeignKeyColumn()); - - Property p = childTable.getType().getProperty(childProperty); - fkValue.add(childTable.get(p)); - } - - DebugUtil.debugln(getClass(), debug, "Trying to find parent of " + r.getForeignKeyTable() + " with FK " - + fkValue); - DataObject parentTable = registry.get(r.getPrimaryKeyTable(), fkValue); - DebugUtil.debugln(getClass(), debug, "Parent table from registry: " + parentTable); - return parentTable; - } - -} diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/SingleTableRegistry.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/SingleTableRegistry.java deleted file mode 100644 index f00ef2770d..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/SingleTableRegistry.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.impl; - -import java.util.List; - -import commonj.sdo.DataObject; - -/** - */ -public class SingleTableRegistry implements TableRegistry { - - //private HashMap<List,DataObject> values = new HashMap<List,DataObject>(); - - public SingleTableRegistry() { - // Empty Constructor - } - - /* (non-Javadoc) - * @see com.ibm.ws.sdo.mediator.jdbc.graphbuilder.impl.TableRegistry#get(java.lang.String, java.util.List) - */ - public DataObject get(String tableName, List primaryKey) { - return null; - } - - /* (non-Javadoc) - * @see com.ibm.ws.sdo.mediator.jdbc.graphbuilder.impl.TableRegistry#put(java.lang.String, java.util.List, java.lang.Object) - */ - public void put(String tableName, List primaryKey, DataObject value) { - // do nothing - - } - - public boolean contains(String name, List list) { - return false; - } - -} diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/TableData.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/TableData.java deleted file mode 100644 index 48b6dc0187..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/TableData.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.impl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.apache.tuscany.das.rdb.util.DebugUtil; - - -/** - * - */ -public class TableData { - - private HashMap columnData = new HashMap(); - private ArrayList primaryKey = new ArrayList(); - private final String name; - private boolean hasValidPrimaryKey = true; - private static final boolean debug = false; - - public TableData(String tableName) { - DebugUtil.debugln(getClass(), debug, "Creating TableData for table " + tableName); - this.name = tableName; - } - - - public void addData(String columnName, boolean isPrimaryKeyColumn, Object data) { - DebugUtil.debugln(getClass(), debug, "Adding column " + columnName + " with value " + data); - columnData.put(columnName, data); - if ( isPrimaryKeyColumn ) { - if ( data == null ) { - DebugUtil.debugln(getClass(), debug, "Column " + columnName + " is a primary key column and is null"); - hasValidPrimaryKey = false; - } - primaryKey.add(data); - } - } - - public Object getColumnData(String columnName) { - return columnData.get(columnName); - } - - public String getTableName() { - return this.name; - } - - - /** - * @return - */ - public List getPrimaryKeyValues() { - return primaryKey; - } - - - public boolean hasValidPrimaryKey() { - return hasValidPrimaryKey; - } -} diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/TableRegistry.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/TableRegistry.java deleted file mode 100644 index 4b5a3677ae..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/TableRegistry.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.impl; - -import java.util.List; - -import commonj.sdo.DataObject; - -/** - */ -public interface TableRegistry { - /** - * Get the table with the specified name and primary key - * @param tableName - * @param primaryKey - * @return EDataObject - */ - public DataObject get(String tableName, List primaryKey); - - /** - * Add the table with the specified name and primary key - * @param tableName - * @param primaryKey - * @param value - */ - public void put(String tableName, List primaryKey, DataObject value); - - public boolean contains(String name, List list); -}
\ No newline at end of file diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ESchemaMaker.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ESchemaMaker.java deleted file mode 100644 index 3082384160..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ESchemaMaker.java +++ /dev/null @@ -1,171 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.schema; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - -import org.apache.tuscany.das.rdb.config.Relationship; -import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper; -import org.apache.tuscany.das.rdb.graphbuilder.impl.GraphBuilderMetadata; -import org.apache.tuscany.das.rdb.graphbuilder.impl.ResultMetadata; -import org.apache.tuscany.das.rdb.util.DebugUtil; -import org.apache.tuscany.sdo.util.DataObjectUtil; -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.Property; -import commonj.sdo.Type; -import commonj.sdo.helper.TypeHelper; - -/** - * - * An ESchemaMaker is used to create an EMF Schema from an instance of JDBC - * Mediator Metadata. - * - */ -public class ESchemaMaker { - - private final GraphBuilderMetadata metadata; - - private boolean debug = false; - - /** - * Constructor for ESchemaMaker. Creates an SDO model based on the metadata - * passed in. - * - * @param metadata - */ - public ESchemaMaker(GraphBuilderMetadata metadata) { - this.metadata = metadata; - } - - /** - * Creates an EMF Schema by using the - * - * @link TableMaker and - * @link RelationshipMaker to transform - * @link Metadata elements into EMF Schema elements. - */ - - public Type createTypes() { - TypeHelper types = SDOUtil.createTypeHelper(); - - DataObjectUtil.initRuntime(); - SDOUtil.createDataGraph(); - - - Type rootType = SDOUtil.createType(types, getURI(), "DataGraphRoot", false); - - Iterator iter = metadata.getResultMetadata().iterator(); - while (iter.hasNext()) { - - ResultMetadata resultMetadata = (ResultMetadata) iter.next(); - - Iterator names = resultMetadata.getAllTablePropertyNames() - .iterator(); - while (names.hasNext()) { - String tableName = (String) names.next(); - - Type tableType = SDOUtil.createType(types, getURI(), tableName, false); - Property property = SDOUtil.createProperty(rootType, tableName, tableType); - SDOUtil.setMany(property,true); - SDOUtil.setContainment(property, true); - } - - // TODO tablePropertyMap is temporary until Tuscany-203 is fixed - HashMap tablePropertyMap = new HashMap(); - - for (int i = 1; i <= resultMetadata.getColumnNames().size(); i++) { - - Property ref = rootType.getProperty(resultMetadata.getTablePropertyName(i)); - - // TODO Temporary code to check to see if a property has already been added. - // Replace when Tuscany-203 is fixed - ArrayList addedProperties = (ArrayList) tablePropertyMap.get(ref.getName()); - if ( addedProperties == null ) { - addedProperties = new ArrayList(); - tablePropertyMap.put(ref.getName(), addedProperties); - } - - if (ref == null) - throw new RuntimeException("Could not find table " - + resultMetadata.getTablePropertyName(i) - + " in the SDO model"); - - String columnName = resultMetadata.getColumnPropertyName(i); - - // TODO temporary check until Tuscany-203 is fixed - if ( !addedProperties.contains(columnName)) { - addedProperties.add(columnName); - Type atype = (Type) resultMetadata.getDataType(i); - - SDOUtil.createProperty(ref.getType(), columnName, atype); - - DebugUtil.debugln(getClass(), debug, "Adding column " - + columnName + " to " - + resultMetadata.getTablePropertyName(i)); - } - - } - } - - if (metadata.hasMappingModel()) { - MappingWrapper wrapper = new MappingWrapper(metadata.getMapping()); - Iterator i = metadata.getRelationships().iterator(); - while (i.hasNext()) { - Relationship r = (Relationship) i.next(); - - Type parent = rootType.getProperty( - wrapper.getTablePropertyName(r.getPrimaryKeyTable())).getType(); - Type child = rootType.getProperty( - wrapper.getTablePropertyName(r.getForeignKeyTable())).getType(); - if (parent == null) { - throw new RuntimeException("The parent table (" - + r.getPrimaryKeyTable() + ") in relationship " - + r.getName() - + " was not found in the mapping information."); - } else if (child == null) { - throw new RuntimeException("The child table (" - + r.getForeignKeyTable() + ") in relationship " - + r.getName() - + " was not found in the mapping information."); - } - - // ReferenceImpl ref = refMaker.createReference(r, parent, child); - - Property parentProp = SDOUtil.createProperty(parent, r.getName(), child); - Property childProp = SDOUtil.createProperty(child, r.getName() + "_opposite", parent); - SDOUtil.setOpposite(parentProp, childProp); - SDOUtil.setOpposite(childProp, parentProp); - SDOUtil.setMany(parentProp, r.isMany()); - - - - } - - } - - return rootType; - } - - private String getURI() { - return "http:///org.apache.tuscany.das.rdb/das"; - } - - -} diff --git a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ResultSetTypeMap.java b/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ResultSetTypeMap.java deleted file mode 100644 index 832cfeac7e..0000000000 --- a/tags/java-M1-20060522/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ResultSetTypeMap.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.apache.tuscany.das.rdb.graphbuilder.schema; - -import java.sql.Types; - -import org.apache.tuscany.sdo.SDOPackage; - -import commonj.sdo.Type; -import commonj.sdo.helper.TypeHelper; - -/** - */ -public class ResultSetTypeMap { - - public static ResultSetTypeMap instance = new ResultSetTypeMap(); - - /** - * Constructor for ResultSetTypeMap. - */ - protected ResultSetTypeMap() { - // Empty Constructor - } - - /** - * These mappings taken primarily from "JDBC API and Tutorial and Reference" by - * Fisher, Ellis and Bruce. - * - * @param type - * @param isNullable - * @return - */ - public Type getEDataType(int type, boolean isNullable) { - - TypeHelper helper = TypeHelper.INSTANCE; - SDOPackage.eINSTANCE.eClass(); - switch (type) { - - case Types.CHAR: - case Types.VARCHAR: - case Types.LONGVARCHAR: - return helper.getType("commonj.sdo", "String"); - - case Types.NUMERIC: - case Types.DECIMAL: - return helper.getType("commonj.sdo", "Decimal"); - - case Types.BIT: - case Types.BOOLEAN: - if (isNullable) - return helper.getType("commonj.sdo", "Boolean"); - else - return helper.getType("commonj.sdo", "boolean"); - - case Types.TINYINT: - case Types.SMALLINT: - case Types.INTEGER: - if (isNullable) { - return helper.getType("commonj.sdo", "IntObject"); - } else - return helper.getType("commonj.sdo", "Int"); - - case Types.BIGINT: - if (isNullable) - return helper.getType("commonj.sdo", "Long"); - else - return helper.getType("commonj.sdo", "long"); - - case Types.REAL: - if (isNullable) - return helper.getType("commonj.sdo", "Float"); - else - return helper.getType("commonj.sdo", "float"); - - case Types.FLOAT: - case Types.DOUBLE: - if (isNullable) - return helper.getType("commonj.sdo", "Double"); - else - return helper.getType("commonj.sdo", "double"); - - case Types.BINARY: - case Types.VARBINARY: - case Types.LONGVARBINARY: - return helper.getType("commonj.sdo", "ByteArray"); - - case Types.DATE: - case Types.TIME: - case Types.TIMESTAMP: - return helper.getType("commonj.sdo", "Date"); - - case Types.CLOB: - return helper.getType("commonj.sdo", "Clob"); - - case Types.BLOB: - return helper.getType("commonj.sdo", "Blob"); - - case Types.ARRAY: - return helper.getType("commonj.sdo", "Array"); - - case Types.DISTINCT: - case Types.STRUCT: - case Types.REF: - case Types.DATALINK: - case Types.JAVA_OBJECT: - return helper.getType("commonj.sdo", "Object"); - - default: - return helper.getType("commonj.sdo", "Object"); - } - - } - - - public Type getType(int columnType, boolean b) { - return getEDataType(columnType, b); - } - -} |