use of org.eclipse.persistence.tools.oracleddl.metadata.TableType in project eclipselink by eclipse-ee4j.
the class JDBCHelper method loadTables.
protected List<TableType> loadTables(String originalCatalogPattern, String originalSchemaPattern, String originalTablePattern) {
List<TableType> dbTables = null;
String schemaPattern = escapePunctuation(originalSchemaPattern);
String tablePattern = escapePunctuation(originalTablePattern);
DatabaseMetaData databaseMetaData = getDatabaseMetaData(dbwsBuilder.getConnection());
boolean supportsCatalogsInTableDefinitions = true;
try {
supportsCatalogsInTableDefinitions = databaseMetaData.supportsCatalogsInTableDefinitions();
} catch (SQLException sqlException) {
/* ignore*/
}
String catalogPattern = escapePunctuation(supportsCatalogsInTableDefinitions ? originalCatalogPattern : "");
// Make sure table(s) is/are available
ResultSet tablesInfo = null;
try {
tablesInfo = databaseMetaData.getTables(catalogPattern, schemaPattern, tablePattern, null);
} catch (SQLException sqlException) {
throw new IllegalStateException("failure retrieving JDBC table metadata", sqlException);
}
// did we get a hit?
if (tablesInfo != null) {
dbTables = new ArrayList<TableType>();
try {
while (tablesInfo.next()) {
String actualTableCatalog = null;
try {
actualTableCatalog = tablesInfo.getString(TABLESINFO_CATALOG);
} catch (SQLException sqlException) {
// we can live without catalog info
}
String actualTableSchema = null;
try {
actualTableSchema = tablesInfo.getString(TABLESINFO_SCHEMA);
} catch (SQLException sqlException) {
// we can live without schema info
}
String actualTableName = tablesInfo.getString(TABLESINFO_NAME);
String tableType = null;
try {
tableType = tablesInfo.getString(TABLESINFO_TYPE);
} catch (SQLException sqlException) {
// we can live without table type - assume TABLE
}
DbTable dbTable = new DbTable();
dbTable.setCatalog(actualTableCatalog);
dbTable.setSchema(actualTableSchema);
dbTable.setTableName(actualTableName);
if (tableType != null) {
dbTable.setType(tableType);
}
dbTables.add(dbTable);
ResultSet columnInfo = databaseMetaData.getColumns(actualTableCatalog, actualTableSchema, actualTableName, "%");
while (columnInfo.next()) {
String columnName = columnInfo.getString(COLUMNSINFO_COLUMN_NAME);
DbColumn dbColumn = new DbColumn(columnName);
int dbPrecision = -1;
try {
dbPrecision = columnInfo.getInt(COLUMNSINFO_COLUMN_SIZE);
} catch (NumberFormatException nfe) {
// ignore
}
int dbScale = columnInfo.getInt(COLUMNSINFO_DECIMAL_DIGITS);
if (columnInfo.getInt(COLUMNSINFO_NULLABLE) == columnNullable) {
dbColumn.unSetNotNull();
} else {
dbColumn.setNotNull();
}
dbColumn.setJDBCType(columnInfo.getInt(COLUMNSINFO_DATA_TYPE));
dbColumn.setJDBCTypeName(columnInfo.getString(COLUMNSINFO_TYPE_NAME));
dbColumn.setEnclosedType(buildTypeForJDBCType(dbColumn.getJDBCType(), dbPrecision, dbScale));
dbTable.getColumns().add(dbColumn);
}
columnInfo.close();
ResultSet pksInfo = databaseMetaData.getPrimaryKeys(actualTableCatalog, actualTableSchema, actualTableName);
if (pksInfo != null) {
while (pksInfo.next()) {
short keySeq = pksInfo.getShort(PKSINFO_KEY_SEQ);
String pkConstraintName = pksInfo.getString(PKSINFO_PK_NAME);
DbColumn dbColumn = (DbColumn) dbTable.getColumns().get(keySeq - 1);
dbColumn.setPk();
dbColumn.setPkConstraintName(pkConstraintName);
}
}
pksInfo.close();
try {
ResultSet indexInfo = databaseMetaData.getIndexInfo(actualTableCatalog, actualTableSchema, actualTableName, true, false);
if (indexInfo != null) {
while (indexInfo.next()) {
boolean nonUnique = indexInfo.getBoolean(INDEXINFO_NON_UNIQUE);
if (!nonUnique) {
// reverse logic!
short type = indexInfo.getShort(INDEXINFO_TYPE);
if (type != tableIndexStatistic) {
short pos = indexInfo.getShort(INDEXINFO_ORDINAL_POSITION);
DbColumn dbColumn = (DbColumn) dbTable.getColumns().get(pos - 1);
if (!dbColumn.pk()) {
dbColumn.setUnique(true);
}
}
}
}
}
indexInfo.close();
} catch (SQLException sqlException) {
// ignore
}
}
tablesInfo.close();
} catch (SQLException sqlException) {
throw new IllegalStateException("failure retrieving JDBC table metadata", sqlException);
}
}
return dbTables;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.TableType in project eclipselink by eclipse-ee4j.
the class JDBCHelper method loadTables.
@Override
protected List<TableType> loadTables(List<String> catalogPatterns, List<String> schemaPatterns, List<String> tableNamePatterns) {
List<TableType> tables = new ArrayList<TableType>();
for (int i = 0, len = catalogPatterns.size(); i < len; i++) {
String catalogPattern = catalogPatterns.get(i);
String schemaPattern = schemaPatterns.get(i);
String tablePattern = tableNamePatterns.get(i);
tables.addAll(loadTables(catalogPattern, schemaPattern, tablePattern));
}
return tables;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.TableType in project eclipselink by eclipse-ee4j.
the class JPAMetadataGenerator method processPLSQLArgument.
/**
* Generate a PL/SQL parameter based on the given ArgumentType. For
* non-PL/SQL arguments the processArgument method should be used.
*/
protected PLSQLParameterMetadata processPLSQLArgument(ArgumentType arg) {
// for %ROWTYPE, we need to create a PL/SQL record that mirrors the Table
if (arg.getEnclosedType().isROWTYPEType()) {
ROWTYPEType rType = (ROWTYPEType) arg.getEnclosedType();
TableType tableType = (TableType) rType.getEnclosedType();
PLSQLRecordType plsqlRec = new PLSQLRecordType(rType.getTypeName());
plsqlRec.setParentType(new PLSQLPackageType());
for (FieldType col : tableType.getColumns()) {
FieldType ft = new FieldType(col.getFieldName());
ft.setEnclosedType(col.getEnclosedType());
plsqlRec.addField(ft);
}
arg.setEnclosedType(plsqlRec);
}
PLSQLParameterMetadata param = new PLSQLParameterMetadata();
// handle cursor
if (arg.isPLSQLCursorType()) {
param.setDirection(OUT_CURSOR_STR);
}
// handle stored function return type
if (arg.getDirection() == ArgumentTypeDirection.RETURN) {
param.setName(arg.isPLSQLCursorType() ? CURSOR_STR : RESULT_STR);
} else {
// direction is already set for cursor type
if (!arg.isPLSQLCursorType()) {
param.setDirection(arg.getDirection().name());
}
param.setName(arg.getArgumentName());
}
String dbType = arg.getTypeName();
// handle composites
if (arg.isComposite()) {
DatabaseType enclosedType = arg.getEnclosedType();
// need to prepend the package name for most PL/SQL and Cursor types
if (enclosedType.isPLSQLType() || enclosedType.isPLSQLCursorType()) {
dbType = getQualifiedTypeName(enclosedType);
}
// process the composite enclosed type
processCompositeType(enclosedType, dbType);
}
param.setDatabaseType(processTypeName(dbType));
return param;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.TableType in project eclipselink by eclipse-ee4j.
the class OracleHelper method customizeSimpleXMLTagNames.
/**
* Customizes the simple-xml-format tags names to better represent the
* PL/SQL record/table/column type. This is possible only with
* strongly-typed ref cursors, since for weakly-typed ones we
* don't know anything about the cursor's output type.
*/
protected void customizeSimpleXMLTagNames(PLSQLCursorType plsqlCursor, ProcedureOperationModel procedureOperationModel) {
if (!plsqlCursor.isWeaklyTyped()) {
// do not override user tag customization
if (procedureOperationModel.getSimpleXMLFormatTag() == null) {
procedureOperationModel.setSimpleXMLFormatTag(plsqlCursor.getCursorName());
}
// - TYPEType
if (procedureOperationModel.getXmlTag() == null) {
if (plsqlCursor.getEnclosedType().isPLSQLRecordType()) {
PLSQLRecordType recType = (PLSQLRecordType) plsqlCursor.getEnclosedType();
procedureOperationModel.setXmlTag(recType.getTypeName());
} else if (plsqlCursor.getEnclosedType().isROWTYPEType()) {
// assumes ROWTYPEType has an enclosed TableType
ROWTYPEType rowType = (ROWTYPEType) plsqlCursor.getEnclosedType();
TableType tableType = (TableType) rowType.getEnclosedType();
procedureOperationModel.setXmlTag(tableType.getTableName());
}
}
}
}
Aggregations