@@ -763,9 +763,10 @@ public void run() throws InterruptedException {
763763 //**************************************************************************
764764 //** getTables
765765 //**************************************************************************
766- /** Used to retrieve an array of tables found in this database.
766+ /** Used to retrieve an array of tables and columns found in this database.
767767 */
768768 public Table [] getTables () throws SQLException {
769+ if (tables !=null ) return tables ;
769770 try (Connection conn = getConnection ()){
770771 return getTables (conn );
771772 }
@@ -775,7 +776,7 @@ public Table[] getTables() throws SQLException {
775776 //**************************************************************************
776777 //** getTables
777778 //**************************************************************************
778- /** Used to retrieve an array of tables found in a database.
779+ /** Used to retrieve an array of tables and columns found in a database.
779780 */
780781 public static Table [] getTables (Connection conn ){
781782 Database database = conn .getDatabase ();
@@ -802,6 +803,56 @@ public static Table[] getTables(Connection conn){
802803 }
803804
804805
806+ //**************************************************************************
807+ //** getTableNames
808+ //**************************************************************************
809+ /** Used to retrieve an array of table names found in the database. If a
810+ * table is part of a schema, the schema name is prepended to the table
811+ * name. This method is significantly faster than the getTables() method
812+ * which returns the full metadata for each table.
813+ */
814+ public String [] getTableNames () throws SQLException {
815+ java .util .ArrayList <javaxt .utils .Record > tableNames = new java .util .ArrayList <>();
816+
817+
818+ if (tables !=null ){
819+ for (Table table : tables ){
820+ javaxt .utils .Record record = new javaxt .utils .Record ();
821+ record .set ("schema" , table .getSchema ());
822+ record .set ("table" , table .getName ());
823+ tableNames .add (record );
824+ }
825+ }
826+ else {
827+ try (Connection conn = getConnection ()){
828+
829+ DatabaseMetaData dbmd = conn .getConnection ().getMetaData ();
830+ try (ResultSet rs = dbmd .getTables (null ,null ,null ,new String []{"TABLE" })){
831+ while (rs .next ()) {
832+ javaxt .utils .Record record = new javaxt .utils .Record ();
833+ record .set ("schema" , rs .getString ("TABLE_SCHEM" ));
834+ record .set ("table" , rs .getString ("TABLE_NAME" ));
835+ tableNames .add (record );
836+ }
837+ }
838+ }
839+ }
840+
841+ String [] arr = new String [tableNames .size ()];
842+ for (int i =0 ; i <arr .length ; i ++){
843+ javaxt .utils .Record record = tableNames .get (i );
844+ String tableName = record .get ("table" ).toString ();
845+ String schemaName = record .get ("schema" ).toString ();
846+ if (schemaName !=null && !schemaName .isEmpty ()){
847+ tableName = schemaName + "." + tableName ;
848+ }
849+ arr [i ] = tableName ;
850+ }
851+ java .util .Arrays .sort (arr );
852+ return arr ;
853+ }
854+
855+
805856 //**************************************************************************
806857 //** getCatalogs
807858 //**************************************************************************
0 commit comments