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");
}
}
}
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;
}
Aggregations