List of usage examples for java.sql DatabaseMetaData getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:de.griffel.confluence.plugins.plantuml.DatasourceHelper.java
/** * Gets attribute from Database meta data and stores it in map. * * @param dbmd Database meta data/*from w w w .java2 s.c o m*/ * @param attribute Name of attribute to get * @param result Map to store attribute name and value in */ private static void fillValue(DatabaseMetaData dbmd, String attribute, Map<String, String> result) { final Class[] noparams = {}; try { final Method m = dbmd.getClass().getMethod("get" + attribute, noparams); result.put(attribute, "" + m.invoke(dbmd)); } catch (IllegalAccessException e) { log.debug("IllegalAccess", e); result.put(attribute, ERROR); } catch (IllegalArgumentException e) { log.debug("IllegalArgument", e); result.put(attribute, ERROR); } catch (NoSuchMethodException e) { log.debug("NoSuchMethod", e); result.put(attribute, ERROR); } catch (SecurityException e) { log.debug("Security", e); result.put(attribute, ERROR); } catch (InvocationTargetException e) { log.debug("InvocationTarget", e); result.put(attribute, ERROR); } }
From source file:nl.b3p.datastorelinker.gui.stripes.ConvertLargeObjectsAction.java
public void convertLOBS() throws SQLException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, IOException { statusArray.put("Opening connection.."); EntityManager em = JpaUtilServlet.getThreadEntityManager(); Session session = (Session) em.getDelegate(); Connection conn = session.connection(); conn.setAutoCommit(false);/* www.j a v a 2 s .c om*/ DatabaseMetaData metadata = conn.getMetaData(); statusArray.put("Digging deep to retrieve implementation"); Field f = metadata.getClass().getDeclaredField("inner"); f.setAccessible(true); Object pgconnMetadata = f.get(metadata); statusArray.put("Retrieving postgres connection.."); org.postgresql.PGConnection connection = (org.postgresql.PGConnection) ((org.postgresql.jdbc4.Jdbc4DatabaseMetaData) pgconnMetadata) .getConnection(); statusArray.put("Connection established"); lom = connection.getLargeObjectAPI(); statusArray.put("Create LargeObjectManager"); em.getTransaction().begin(); statusArray.put("Begin converting LOBs"); processProcesses(em); processProcessesStatusses(em); statusArray.put("Converting finished"); em.getTransaction().commit(); statusArray.put("Changes saved"); }
From source file:org.apache.ddlutils.task.DumpMetadataTask.java
/** * Dumps the database meta data into XML elements under the current element in the given writer. * /*from w w w.j a v a 2 s . c o m*/ * @param xmlWriter The XML writer to write to * @param metaData The meta data to write */ private void dumpMetaData(PrettyPrintingXmlWriter xmlWriter, DatabaseMetaData metaData) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, SQLException { // We rather iterate over the methods because most metadata properties // do not follow the bean naming standard Method[] methods = metaData.getClass().getMethods(); Set filtered = new HashSet(Arrays.asList(IGNORED_PROPERTY_METHODS)); for (int idx = 0; idx < methods.length; idx++) { // only no-arg methods that return something and that are not defined in Object // we also filter certain methods if ((methods[idx].getParameterTypes().length == 0) && (methods[idx].getReturnType() != null) && (Object.class != methods[idx].getDeclaringClass()) && !filtered.contains(methods[idx].getName())) { dumpProperty(xmlWriter, metaData, methods[idx]); } } dumpCatalogsAndSchemas(xmlWriter, metaData); if (_dumpTables) { dumpTables(xmlWriter, metaData); } if (_dumpProcedures) { dumpProcedures(xmlWriter, metaData); } }
From source file:org.executequery.databaseobjects.impl.DefaultDatabaseHost.java
/** * Retrieves key/value type pairs using the <code>Reflection</code> * API to call and retrieve values from the connection's meta data * object's methods and variables./*from ww w .j ava 2s. c o m*/ * * @return the database properties as key/value pairs */ public Map<Object, Object> getDatabaseProperties() throws DataSourceException { DatabaseMetaData dmd = getDatabaseMetaData(); Object[] defaultArg = new Object[] {}; Map<Object, Object> properties = new HashMap<Object, Object>(); String STRING = "String"; String GET = "get"; Class<?> metaClass = dmd.getClass(); Method[] metaMethods = metaClass.getMethods(); for (int i = 0; i < metaMethods.length; i++) { Class<?> clazz = metaMethods[i].getReturnType(); String methodName = metaMethods[i].getName(); if (methodName == null || clazz == null) { continue; } if (clazz.isPrimitive() || clazz.getName().endsWith(STRING)) { if (methodName.startsWith(GET)) { methodName = methodName.substring(3); } try { Object res = metaMethods[i].invoke(dmd, defaultArg); if (res != null) { properties.put(methodName, res.toString()); } } catch (AbstractMethodError e) { continue; } catch (IllegalArgumentException e) { continue; } catch (IllegalAccessException e) { continue; } catch (InvocationTargetException e) { continue; } } } return properties; }
From source file:org.talend.metadata.managment.model.DBConnectionFillerImpl.java
@Override public List<Schema> fillSchemaToCatalog(DatabaseConnection dbConn, DatabaseMetaData dbJDBCMetadata, Catalog catalog, List<String> schemaFilter) throws Throwable { ResultSet schemaRs = null;//from ww w . ja v a2 s . c om try { // Case of JDK 1.6 if (dbJDBCMetadata.getDriverName().equals(DatabaseConstant.MSSQL_DRIVER_NAME_JDBC2_0)) { Method getSchemaMethod = dbJDBCMetadata.getClass().getMethod("getSchemas", String.class, //$NON-NLS-1$ String.class); schemaRs = (ResultSet) getSchemaMethod.invoke(dbJDBCMetadata, catalog.getName(), null); } } catch (SecurityException e) { // Case of JDK1.5 } catch (NoSuchMethodException e) { // do nothing here !!! } catch (IllegalArgumentException e) { // do nothing here !!! } catch (IllegalAccessException e) { // do nothing here !!! } catch (InvocationTargetException e) { // Case of JDK1.5 if (e.getTargetException().getClass().toString().equals("SQLServerException")) { //$NON-NLS-1$ throw e.getTargetException(); } } catch (SQLException e) { log.error(e, e); } if (schemaRs == null) { try { if (dbJDBCMetadata instanceof SybaseDatabaseMetaData) { schemaRs = ((SybaseDatabaseMetaData) dbJDBCMetadata).getSchemas(catalog.getName(), null); } else if (dbJDBCMetadata instanceof AS400DatabaseMetaData) { String schemaPattern = null; if (!schemaFilter.isEmpty()) { schemaPattern = schemaFilter.get(0); } schemaRs = dbJDBCMetadata.getSchemas(catalog.getName(), schemaPattern); } else { schemaRs = dbJDBCMetadata.getSchemas(); } } catch (SQLException e) { if (log.isDebugEnabled()) { log.debug(e, e); } } } List<String> schemaNameCacheTmp = new ArrayList<String>(); List<Schema> schemaList = new ArrayList<Schema>(); if (schemaRs == null) { log.error("Schema result set is null"); //$NON-NLS-1$ } else { try { while (schemaRs.next()) { String schemaName = getSchemaName(schemaRs, dbJDBCMetadata, catalog); if (schemaName == null) { continue; } // MOD mzhao bug 9606 filter duplicated schemas. if (!schemaNameCacheTmp.contains(schemaName) && !MetadataConnectionUtils.isMysql(dbJDBCMetadata)) { if (dbConn != null && !isNullUiSchema(dbConn)) { // this case we only create one schema which name is same as UiSchema Schema createByUiSchema = createSchemaByUiSchema(dbConn); schemaList.add(createByUiSchema); break; } else if (isCreateElement(schemaFilter, schemaName)) { Schema schema = SchemaHelper.createSchema(schemaName); schemaList.add(schema); schemaNameCacheTmp.add(schemaName); } } } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug(e, e); } } finally { schemaRs.close(); } } return schemaList; }