Search in sources :

Example 1 with DbColumn

use of org.eclipse.persistence.tools.dbws.jdbc.DbColumn in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method addToOROXProjectsForBuildSql.

protected void addToOROXProjectsForBuildSql(ModelWithBuildSql modelWithBuildSql, Project orProject, Project oxProject, NamingConventionTransformer nct) {
    List<DbColumn> columns = buildDbColumns(dbwsBuilder.getConnection(), modelWithBuildSql.getBuildSql());
    String schemaAlias = modelWithBuildSql.getReturnType();
    String tableName = schemaAlias;
    NamingConventionTransformer customNct = setUpCustomTransformer(tableName, nct);
    RelationalDescriptor desc = buildORDescriptor(tableName, dbwsBuilder.getProjectName(), null, customNct);
    createdORDescriptors.put(desc.getJavaClassName(), desc);
    desc.descriptorIsAggregate();
    orProject.addDescriptor(desc);
    XMLDescriptor xdesc = buildOXDescriptor(desc.getAlias(), schemaAlias, desc.getJavaClassName(), dbwsBuilder.getTargetNamespace());
    oxProject.addDescriptor(xdesc);
    List<String> columnsAlreadyProcessed = new ArrayList<String>();
    for (DbColumn dbColumn : columns) {
        String columnName = dbColumn.getFieldName();
        if (!columnsAlreadyProcessed.contains(columnName)) {
            columnsAlreadyProcessed.add(columnName);
            ElementStyle style = nct.styleForElement(columnName);
            if (style == NONE) {
                continue;
            }
            dbwsBuilder.logMessage(FINE, "Building mappings for " + columnName);
            DirectToFieldMapping orFieldMapping = buildORFieldMappingFromColumn(dbColumn, desc, dbwsBuilder.getDatabasePlatform(), nct);
            desc.addMapping(orFieldMapping);
            XMLDirectMapping oxFieldMapping = buildOXFieldMappingFromColumn(dbColumn, dbwsBuilder.getDatabasePlatform(), nct);
            if (oxFieldMapping instanceof XMLBinaryDataMapping) {
                xdesc.getNamespaceResolver().put(XML_MIME_PREFIX, XML_MIME_URL);
            }
            xdesc.addMapping(oxFieldMapping);
        } else {
            dbwsBuilder.logMessage(SEVERE, "Duplicate ResultSet columns not supported '" + columnName + "'");
            throw new RuntimeException("Duplicate ResultSet columns not supported");
        }
    }
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) DbColumn(org.eclipse.persistence.tools.dbws.jdbc.DbColumn) ArrayList(java.util.ArrayList) ElementStyle(org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Example 2 with DbColumn

use of org.eclipse.persistence.tools.dbws.jdbc.DbColumn in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method buildDbColumns.

protected static List<DbColumn> buildDbColumns(Connection connection, String secondarySql) {
    List<DbColumn> columns = null;
    ResultSetMetaData rsMetaData = getResultSetMetadataForSecondarySQL(connection, secondarySql);
    if (rsMetaData != null) {
        int columnCount = 0;
        try {
            columnCount = rsMetaData.getColumnCount();
        } catch (SQLException sqlException) {
            throw new IllegalStateException("failure retrieving columnCount", sqlException);
        }
        if (columnCount > 0) {
            columns = new ArrayList<DbColumn>(columnCount);
            try {
                for (int i = 1; i <= columnCount; i++) {
                    String dbColumnName = rsMetaData.getColumnLabel(i);
                    DbColumn dbColumn = new DbColumn(dbColumnName);
                    // dbColumn.setOrdinalPosition(i);
                    dbColumn.setJDBCType(rsMetaData.getColumnType(i));
                    dbColumn.setJDBCTypeName(rsMetaData.getColumnTypeName(i));
                    int dbPrecision = rsMetaData.getPrecision(i);
                    int dbScale = rsMetaData.getScale(i);
                    dbColumn.setEnclosedType(buildTypeForJDBCType(dbColumn.getJDBCType(), dbPrecision, dbScale));
                    if (rsMetaData.isNullable(i) == ResultSetMetaData.columnNullable) {
                        dbColumn.unSetNotNull();
                    } else {
                        dbColumn.setNotNull();
                    }
                    columns.add(dbColumn);
                }
            } catch (SQLException sqlException) {
                throw new IllegalStateException("failure retrieving column information", sqlException);
            }
        }
    }
    return columns;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DbColumn(org.eclipse.persistence.tools.dbws.jdbc.DbColumn) SQLException(java.sql.SQLException)

Aggregations

DbColumn (org.eclipse.persistence.tools.dbws.jdbc.DbColumn)2 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)1 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)1 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)1 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)1 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)1 ElementStyle (org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle)1