Search in sources :

Example 1 with RDBMSSchemaInfo

use of org.datanucleus.store.rdbms.schema.RDBMSSchemaInfo in project datanucleus-rdbms by datanucleus.

the class RDBMSStoreManager method printInformation.

/**
 * Method to output particular information owned by this datastore.
 * Supports "DATASTORE" and "SCHEMA" categories.
 * @param category Category of information
 * @param ps PrintStream
 * @throws Exception Thrown if an error occurs in the output process
 */
public void printInformation(String category, PrintStream ps) throws Exception {
    DatastoreAdapter dba = getDatastoreAdapter();
    super.printInformation(category, ps);
    if (category.equalsIgnoreCase("DATASTORE")) {
        ps.println(dba.toString());
        ps.println();
        ps.println("Database TypeInfo");
        RDBMSTypesInfo typesInfo = (RDBMSTypesInfo) schemaHandler.getSchemaData(null, RDBMSSchemaHandler.TYPE_TYPES, null);
        if (typesInfo != null) {
            Iterator iter = typesInfo.getChildren().keySet().iterator();
            while (iter.hasNext()) {
                String jdbcTypeStr = (String) iter.next();
                short jdbcTypeNumber = 0;
                try {
                    jdbcTypeNumber = Short.parseShort(jdbcTypeStr);
                } catch (NumberFormatException nfe) {
                }
                JDBCTypeInfo jdbcType = (JDBCTypeInfo) typesInfo.getChild(jdbcTypeStr);
                Collection<String> sqlTypeNames = jdbcType.getChildren().keySet();
                StringBuilder sqlTypesName = new StringBuilder();
                String defaultSqlTypeName = null;
                for (String sqlTypeName : sqlTypeNames) {
                    if (!sqlTypeName.equals("DEFAULT")) {
                        if (sqlTypesName.length() > 0) {
                            sqlTypesName.append(',');
                        }
                        sqlTypesName.append(sqlTypeName);
                    } else {
                        defaultSqlTypeName = ((SQLTypeInfo) jdbcType.getChild(sqlTypeName)).getTypeName();
                    }
                }
                // SQL type names for JDBC type
                String typeStr = "JDBC Type=" + dba.getNameForJDBCType(jdbcTypeNumber) + " sqlTypes=" + sqlTypesName + (defaultSqlTypeName != null ? (" (default=" + defaultSqlTypeName + ")") : "");
                ps.println(typeStr);
                for (String sqlTypeName : sqlTypeNames) {
                    // SQL type details
                    if (!sqlTypeName.equals("DEFAULT")) {
                        SQLTypeInfo sqlType = (SQLTypeInfo) jdbcType.getChild(sqlTypeName);
                        ps.println(sqlType.toString("    "));
                    }
                }
            }
        }
        ps.println("");
        // Print out the keywords info
        ps.println("Database Keywords");
        Iterator reservedWordsIter = dba.iteratorReservedWords();
        while (reservedWordsIter.hasNext()) {
            Object words = reservedWordsIter.next();
            ps.println(words);
        }
        ps.println("");
    } else if (category.equalsIgnoreCase("SCHEMA")) {
        ps.println(dba.toString());
        ps.println();
        ps.println("TABLES");
        ManagedConnection mc = connectionMgr.getConnection(-1);
        try {
            Connection conn = (Connection) mc.getConnection();
            RDBMSSchemaInfo schemaInfo = (RDBMSSchemaInfo) schemaHandler.getSchemaData(conn, RDBMSSchemaHandler.TYPE_TABLES, new Object[] { this.catalogName, this.schemaName });
            if (schemaInfo != null) {
                Iterator tableIter = schemaInfo.getChildren().values().iterator();
                while (tableIter.hasNext()) {
                    // Print out the table information
                    RDBMSTableInfo tableInfo = (RDBMSTableInfo) tableIter.next();
                    ps.println(tableInfo);
                    Iterator<StoreSchemaData> columnIter = tableInfo.getChildren().iterator();
                    while (columnIter.hasNext()) {
                        // Print out the column information
                        RDBMSColumnInfo colInfo = (RDBMSColumnInfo) columnIter.next();
                        ps.println(colInfo);
                    }
                }
            }
        } finally {
            if (mc != null) {
                mc.release();
            }
        }
        ps.println("");
    }
}
Also used : RDBMSColumnInfo(org.datanucleus.store.rdbms.schema.RDBMSColumnInfo) RDBMSTableInfo(org.datanucleus.store.rdbms.schema.RDBMSTableInfo) Connection(java.sql.Connection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) MacroString(org.datanucleus.util.MacroString) SQLTypeInfo(org.datanucleus.store.rdbms.schema.SQLTypeInfo) JDBCTypeInfo(org.datanucleus.store.rdbms.schema.JDBCTypeInfo) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) DatastoreAdapter(org.datanucleus.store.rdbms.adapter.DatastoreAdapter) RDBMSTypesInfo(org.datanucleus.store.rdbms.schema.RDBMSTypesInfo) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) RDBMSSchemaInfo(org.datanucleus.store.rdbms.schema.RDBMSSchemaInfo)

Example 2 with RDBMSSchemaInfo

use of org.datanucleus.store.rdbms.schema.RDBMSSchemaInfo in project datanucleus-rdbms by datanucleus.

the class AbstractTable method create.

/**
 * Method to create this table.
 * @param conn Connection to the datastore.
 * @return true if the table was created
 * @throws SQLException Thrown if an error occurs creating the table.
 */
public boolean create(Connection conn) throws SQLException {
    assertIsInitialized();
    if (storeMgr.getSchemaHandler().isAutoCreateDatabase()) {
        if (identifier.getSchemaName() != null || identifier.getCatalogName() != null) {
            // Make sure the specified catalog/schema exists
            RDBMSSchemaInfo info = (RDBMSSchemaInfo) storeMgr.getSchemaHandler().getSchemaData(conn, RDBMSSchemaHandler.TYPE_SCHEMA, new Object[] { getSchemaName(), getCatalogName() });
            NucleusLogger.DATASTORE_SCHEMA.debug("Check of existence of catalog=" + identifier.getCatalogName() + " schema=" + identifier.getSchemaName() + " returned " + (info != null));
            if (info == null) {
                storeMgr.getSchemaHandler().createDatabase(identifier.getCatalogName(), identifier.getSchemaName(), null, conn);
            }
        }
    }
    List<String> createStmts = getSQLCreateStatements(null);
    executeDdlStatementList(createStmts, conn);
    return !createStmts.isEmpty();
}
Also used : RDBMSSchemaInfo(org.datanucleus.store.rdbms.schema.RDBMSSchemaInfo)

Aggregations

RDBMSSchemaInfo (org.datanucleus.store.rdbms.schema.RDBMSSchemaInfo)2 Connection (java.sql.Connection)1 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)1 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)1 DatastoreAdapter (org.datanucleus.store.rdbms.adapter.DatastoreAdapter)1 JDBCTypeInfo (org.datanucleus.store.rdbms.schema.JDBCTypeInfo)1 RDBMSColumnInfo (org.datanucleus.store.rdbms.schema.RDBMSColumnInfo)1 RDBMSTableInfo (org.datanucleus.store.rdbms.schema.RDBMSTableInfo)1 RDBMSTypesInfo (org.datanucleus.store.rdbms.schema.RDBMSTypesInfo)1 SQLTypeInfo (org.datanucleus.store.rdbms.schema.SQLTypeInfo)1 MacroString (org.datanucleus.util.MacroString)1