Skip to content

Commit d9461f1

Browse files
authored
Merge pull request #483 from schemacrawler/issue482
Fix issue #482 - serialization for catalogs that have synonyms for objects that do not exist
2 parents f605957 + 0efdd2e commit d9461f1

File tree

25 files changed

+212
-65
lines changed

25 files changed

+212
-65
lines changed

schemacrawler-api/src/main/java/schemacrawler/crawl/SynonymRetriever.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555
*/
5656
final class SynonymRetriever extends AbstractRetriever {
5757

58+
private static final class UnknownDatabaseObject extends AbstractDatabaseObject {
59+
60+
private static final long serialVersionUID = -2212843304418302122L;
61+
62+
UnknownDatabaseObject(final Schema schema, final String name) {
63+
super(schema, name);
64+
}
65+
}
66+
5867
private static final SchemaCrawlerLogger LOGGER =
5968
SchemaCrawlerLogger.getLogger(SynonymRetriever.class.getName());
6069

@@ -133,11 +142,7 @@ void retrieveSynonymInformation(final InclusionRule synonymInclusionRule) throws
133142
} else if (referencedRoutine.isPresent()) {
134143
referencedObject = referencedRoutine.get();
135144
} else {
136-
referencedObject =
137-
new AbstractDatabaseObject(referencedSchema, referencedObjectName) {
138-
139-
private static final long serialVersionUID = -2212843304418302122L;
140-
};
145+
referencedObject = new UnknownDatabaseObject(referencedSchema, referencedObjectName);
141146
}
142147

143148
final MutableSynonym synonym = new MutableSynonym(schema, synonymName);

schemacrawler-docker-compose/sqlserver.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ services:
1111
protocol: tcp
1212
mode: host
1313
environment:
14-
ACCEPT_EULA: Y
14+
ACCEPT_EULA: "Y"
1515
SA_PASSWORD: Schem#Crawl3r

schemacrawler-oracle/src/test/resources/testOracleWithConnection.11.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
System Information
44
========================================================================
55

6-
generated by SchemaCrawler 16.12.1
7-
generated on 2021-02-12 23:12:43.4338236
6+
generated by SchemaCrawler 16.15.1
7+
generated on 2021-07-06 22:42:09.2169227
88
database version Oracle Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
99
driver version Oracle JDBC driver 21.1.0.0.0
1010

@@ -497,6 +497,12 @@ Synonyms
497497

498498

499499

500+
BOOKS.OTHER_TABLE [synonym]
501+
------------------------------------------------------------------------
502+
OTHER_TABLE --> BOOKS.FAKE_TABLE
503+
504+
505+
500506
BOOKS.PUBLICATIONS [synonym]
501507
------------------------------------------------------------------------
502508
PUBLICATIONS --> BOOKS.BOOKS
@@ -812,7 +818,7 @@ JDBC Driver Information
812818
driver name Oracle JDBC driver
813819
driver version 21.1.0.0.0
814820
driver class name oracle.jdbc.OracleDriver
815-
url jdbc:oracle:thin:system/oracle@localhost:49212:xe
821+
url jdbc:oracle:thin:system/oracle@localhost:49204:xe
816822
is JDBC compliant true
817823

818824

@@ -841,7 +847,7 @@ com.sun.jndi.ldap.read.timeout [driver property]
841847
database [driver property]
842848

843849
not required
844-
value localhost:49212:xe
850+
value localhost:49204:xe
845851

846852
defaultExecuteBatch [driver property]
847853

schemacrawler-oracle/src/test/resources/testOracleWithConnection.8.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
System Information
44
========================================================================
55

6-
generated by SchemaCrawler 16.12.1
7-
generated on 2021-02-12 22:50:10.056
6+
generated by SchemaCrawler 16.15.1
7+
generated on 2021-07-06 22:21:19.959
88
database version Oracle Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
99
driver version Oracle JDBC driver 21.1.0.0.0
1010

@@ -497,6 +497,12 @@ Synonyms
497497

498498

499499

500+
BOOKS.OTHER_TABLE [synonym]
501+
------------------------------------------------------------------------
502+
OTHER_TABLE --> BOOKS.FAKE_TABLE
503+
504+
505+
500506
BOOKS.PUBLICATIONS [synonym]
501507
------------------------------------------------------------------------
502508
PUBLICATIONS --> BOOKS.BOOKS
@@ -811,7 +817,7 @@ JDBC Driver Information
811817
driver name Oracle JDBC driver
812818
driver version 21.1.0.0.0
813819
driver class name oracle.jdbc.OracleDriver
814-
url jdbc:oracle:thin:system/oracle@localhost:49208:xe
820+
url jdbc:oracle:thin:system/oracle@localhost:49200:xe
815821
is JDBC compliant true
816822

817823

@@ -840,7 +846,7 @@ com.sun.jndi.ldap.read.timeout [driver property]
840846
database [driver property]
841847

842848
not required
843-
value localhost:49208:xe
849+
value localhost:49200:xe
844850

845851
defaultExecuteBatch [driver property]
846852

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
========================================================================
3+
SchemaCrawler
4+
http://www.schemacrawler.com
5+
Copyright (c) 2000-2021, Sualeh Fatehi <sualeh@hotmail.com>.
6+
All rights reserved.
7+
------------------------------------------------------------------------
8+
9+
SchemaCrawler is distributed in the hope that it will be useful, but
10+
WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
13+
SchemaCrawler and the accompanying materials are made available under
14+
the terms of the Eclipse Public License v1.0, GNU General Public License
15+
v3 or GNU Lesser General Public License v3.
16+
17+
You may elect to redistribute this code under any of these licenses.
18+
19+
The Eclipse Public License is available at:
20+
http://www.eclipse.org/legal/epl-v10.html
21+
22+
The GNU General Public License v3 and the GNU Lesser General Public
23+
License v3 are available at:
24+
http://www.gnu.org/licenses/
25+
26+
========================================================================
27+
*/
28+
package schemacrawler.integration.test;
29+
30+
import static org.hamcrest.MatcherAssert.assertThat;
31+
import static org.hamcrest.Matchers.equalTo;
32+
import static org.hamcrest.Matchers.hasSize;
33+
34+
import java.sql.SQLException;
35+
36+
import org.apache.commons.lang3.SerializationUtils;
37+
import org.junit.jupiter.api.BeforeEach;
38+
import org.junit.jupiter.api.Test;
39+
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
40+
import org.junit.jupiter.api.extension.ExtendWith;
41+
import org.testcontainers.containers.JdbcDatabaseContainer;
42+
import org.testcontainers.containers.MSSQLServerContainer;
43+
import org.testcontainers.junit.jupiter.Container;
44+
import org.testcontainers.junit.jupiter.Testcontainers;
45+
import org.testcontainers.utility.DockerImageName;
46+
47+
import schemacrawler.inclusionrule.RegularExpressionInclusionRule;
48+
import schemacrawler.schema.Catalog;
49+
import schemacrawler.schemacrawler.LimitOptionsBuilder;
50+
import schemacrawler.schemacrawler.LoadOptionsBuilder;
51+
import schemacrawler.schemacrawler.SchemaCrawlerException;
52+
import schemacrawler.schemacrawler.SchemaCrawlerOptions;
53+
import schemacrawler.schemacrawler.SchemaCrawlerOptionsBuilder;
54+
import schemacrawler.schemacrawler.SchemaInfoLevelBuilder;
55+
import schemacrawler.test.utility.BaseAdditionalDatabaseTest;
56+
import schemacrawler.test.utility.TestContext;
57+
import schemacrawler.test.utility.TestContextParameterResolver;
58+
import schemacrawler.test.utility.TestLoggingExtension;
59+
import schemacrawler.tools.utility.SchemaCrawlerUtility;
60+
61+
@ExtendWith(TestLoggingExtension.class)
62+
@ExtendWith(TestContextParameterResolver.class)
63+
@Testcontainers(disabledWithoutDocker = true)
64+
@EnabledIfSystemProperty(named = "heavydb", matches = "^((?!(false|no)).)*$")
65+
public class Issue482Test extends BaseAdditionalDatabaseTest {
66+
67+
@Container
68+
private final JdbcDatabaseContainer<?> dbContainer =
69+
new MSSQLServerContainer<>(
70+
DockerImageName.parse("mcr.microsoft.com/mssql/server")
71+
.withTag("2017-CU22-ubuntu-16.04"))
72+
.acceptLicense();
73+
74+
@BeforeEach
75+
public void createDatabase() throws SQLException, SchemaCrawlerException {
76+
createDataSource(
77+
dbContainer.getJdbcUrl(), dbContainer.getUsername(), dbContainer.getPassword());
78+
79+
createDatabase("/sqlserver.scripts.txt");
80+
}
81+
82+
@Test
83+
public void serializeUnknownObjectSynonym(final TestContext testContext) throws Exception {
84+
85+
final LimitOptionsBuilder limitOptionsBuilder =
86+
LimitOptionsBuilder.builder()
87+
.includeSchemas(new RegularExpressionInclusionRule("BOOKS\\.dbo"))
88+
.includeAllSynonyms();
89+
final LoadOptionsBuilder loadOptionsBuilder =
90+
LoadOptionsBuilder.builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum());
91+
final SchemaCrawlerOptions schemaCrawlerOptions =
92+
SchemaCrawlerOptionsBuilder.newSchemaCrawlerOptions()
93+
.withLimitOptions(limitOptionsBuilder.toOptions())
94+
.withLoadOptions(loadOptionsBuilder.toOptions());
95+
96+
final Catalog catalog = SchemaCrawlerUtility.getCatalog(getConnection(), schemaCrawlerOptions);
97+
98+
assertThat(catalog.getTables(), hasSize(10));
99+
assertThat(catalog.getSynonyms(), hasSize(2));
100+
101+
final Catalog clonedCatalog = SerializationUtils.clone(catalog);
102+
103+
assertThat(catalog, equalTo(clonedCatalog));
104+
assertThat(clonedCatalog.getTables(), hasSize(10));
105+
assertThat(clonedCatalog.getSynonyms(), hasSize(2));
106+
}
107+
}

schemacrawler-sqlserver/src/test/resources/testSQLServerWithConnection.11.txt

+13-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
System Information
44
========================================================================
55

6-
generated by SchemaCrawler 16.14.4
7-
generated on 2021-04-23 16:57:46.6775033
6+
generated by SchemaCrawler 16.15.1
7+
generated on 2021-07-06 22:01:36.3368672
88
database version Microsoft SQL Server 14.00.3356
99
driver version Microsoft JDBC Driver 9.2 for SQL Server 9.2.1.0
1010

@@ -316,7 +316,7 @@ BOOKS.dbo.Publishers [table]
316316

317317
Primary Key
318318

319-
PK__Publishe__3214EC0767C7F782 [primary key]
319+
PK__Publishe__3214EC079B242878 [primary key]
320320
Id
321321

322322
Foreign Keys
@@ -326,7 +326,7 @@ FK_βιβλία_Publishers [foreign key, with no action]
326326

327327
Indexes
328328

329-
PK__Publishe__3214EC0767C7F782 [unique clustered index]
329+
PK__Publishe__3214EC079B242878 [unique clustered index]
330330
Id ascending
331331

332332
Privileges and Grants
@@ -455,6 +455,12 @@ Synonyms
455455

456456

457457

458+
BOOKS.dbo.OTHER_TABLE [synonym]
459+
------------------------------------------------------------------------
460+
OTHER_TABLE --> FAKE_TABLE
461+
462+
463+
458464
BOOKS.dbo.Publications [synonym]
459465
------------------------------------------------------------------------
460466
Publications --> Books
@@ -708,7 +714,7 @@ Database Server Information
708714
-=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=-
709715
InstanceName null
710716
IsClustered 0
711-
ServerName 7ae27e894079
717+
ServerName 0109acb0fadb
712718

713719

714720
Database Information
@@ -892,7 +898,7 @@ JDBC Driver Information
892898
driver name Microsoft JDBC Driver 9.2 for SQL Server
893899
driver version 9.2.1.0
894900
driver class name com.microsoft.sqlserver.jdbc.SQLServerDriver
895-
url jdbc:sqlserver://localhost:49320;maxResultBuffer=-1;sendTemporalDataTypesAsStringForBulkCopy=true;delayLoadingLobs=true;useFmtOnly=false;useBulkCopyForBatchInsert=false;cancelQueryTimeout=-1;sslProtocol=TLS;jaasConfigurationName=SQLJDBCDriver;statementPoolingCacheSize=0;serverPreparedStatementDiscardThreshold=10;enablePrepareOnFirstPreparedStatementCall=false;fips=false;socketTimeout=0;authentication=NotSpecified;authenticationScheme=nativeAuthentication;xopenStates=false;sendTimeAsDatetime=true;trustStoreType=JKS;trustServerCertificate=false;TransparentNetworkIPResolution=true;serverNameAsACE=false;sendStringParametersAsUnicode=true;selectMethod=direct;responseBuffering=adaptive;queryTimeout=-1;packetSize=8000;multiSubnetFailover=false;loginTimeout=15;lockTimeout=-1;lastUpdateCount=true;encrypt=false;disableStatementPooling=true;columnEncryptionSetting=Disabled;applicationName=Microsoft JDBC Driver for SQL Server;applicationIntent=readwrite;
901+
url jdbc:sqlserver://localhost:49177;maxResultBuffer=-1;sendTemporalDataTypesAsStringForBulkCopy=true;delayLoadingLobs=true;useFmtOnly=false;useBulkCopyForBatchInsert=false;cancelQueryTimeout=-1;sslProtocol=TLS;jaasConfigurationName=SQLJDBCDriver;statementPoolingCacheSize=0;serverPreparedStatementDiscardThreshold=10;enablePrepareOnFirstPreparedStatementCall=false;fips=false;socketTimeout=0;authentication=NotSpecified;authenticationScheme=nativeAuthentication;xopenStates=false;sendTimeAsDatetime=true;trustStoreType=JKS;trustServerCertificate=false;TransparentNetworkIPResolution=true;serverNameAsACE=false;sendStringParametersAsUnicode=true;selectMethod=direct;responseBuffering=adaptive;queryTimeout=-1;packetSize=8000;multiSubnetFailover=false;loginTimeout=15;lockTimeout=-1;lastUpdateCount=true;encrypt=false;disableStatementPooling=true;columnEncryptionSetting=Disabled;applicationName=Microsoft JDBC Driver for SQL Server;applicationIntent=readwrite;
896902
is JDBC compliant true
897903

898904

@@ -1096,7 +1102,7 @@ password [driver property]
10961102
portNumber [driver property]
10971103
The TCP port where an instance of SQL Server is listening.
10981104
not required
1099-
value 49320
1105+
value 49177
11001106

11011107
queryTimeout [driver property]
11021108
The number of seconds to wait before the database reports a query time-out.

schemacrawler-sqlserver/src/test/resources/testSQLServerWithConnection.8.txt

+13-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
System Information
44
========================================================================
55

6-
generated by SchemaCrawler 16.14.4
7-
generated on 2021-04-23 16:47:32.728
6+
generated by SchemaCrawler 16.15.1
7+
generated on 2021-07-06 21:56:19.86
88
database version Microsoft SQL Server 14.00.3356
99
driver version Microsoft JDBC Driver 9.2 for SQL Server 9.2.1.0
1010

@@ -316,7 +316,7 @@ BOOKS.dbo.Publishers [table]
316316

317317
Primary Key
318318

319-
PK__Publishe__3214EC07B738FF45 [primary key]
319+
PK__Publishe__3214EC072DE6B4E4 [primary key]
320320
Id
321321

322322
Foreign Keys
@@ -326,7 +326,7 @@ FK_βιβλία_Publishers [foreign key, with no action]
326326

327327
Indexes
328328

329-
PK__Publishe__3214EC07B738FF45 [unique clustered index]
329+
PK__Publishe__3214EC072DE6B4E4 [unique clustered index]
330330
Id ascending
331331

332332
Privileges and Grants
@@ -455,6 +455,12 @@ Synonyms
455455

456456

457457

458+
BOOKS.dbo.OTHER_TABLE [synonym]
459+
------------------------------------------------------------------------
460+
OTHER_TABLE --> FAKE_TABLE
461+
462+
463+
458464
BOOKS.dbo.Publications [synonym]
459465
------------------------------------------------------------------------
460466
Publications --> Books
@@ -708,7 +714,7 @@ Database Server Information
708714
-=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=-
709715
InstanceName null
710716
IsClustered 0
711-
ServerName f01f1cadf4e7
717+
ServerName a4daae9fb89e
712718

713719

714720
Database Information
@@ -891,7 +897,7 @@ JDBC Driver Information
891897
driver name Microsoft JDBC Driver 9.2 for SQL Server
892898
driver version 9.2.1.0
893899
driver class name com.microsoft.sqlserver.jdbc.SQLServerDriver
894-
url jdbc:sqlserver://localhost:49317;maxResultBuffer=-1;sendTemporalDataTypesAsStringForBulkCopy=true;delayLoadingLobs=true;useFmtOnly=false;useBulkCopyForBatchInsert=false;cancelQueryTimeout=-1;sslProtocol=TLS;jaasConfigurationName=SQLJDBCDriver;statementPoolingCacheSize=0;serverPreparedStatementDiscardThreshold=10;enablePrepareOnFirstPreparedStatementCall=false;fips=false;socketTimeout=0;authentication=NotSpecified;authenticationScheme=nativeAuthentication;xopenStates=false;sendTimeAsDatetime=true;trustStoreType=JKS;trustServerCertificate=false;TransparentNetworkIPResolution=true;serverNameAsACE=false;sendStringParametersAsUnicode=true;selectMethod=direct;responseBuffering=adaptive;queryTimeout=-1;packetSize=8000;multiSubnetFailover=false;loginTimeout=15;lockTimeout=-1;lastUpdateCount=true;encrypt=false;disableStatementPooling=true;columnEncryptionSetting=Disabled;applicationName=Microsoft JDBC Driver for SQL Server;applicationIntent=readwrite;
900+
url jdbc:sqlserver://localhost:49173;maxResultBuffer=-1;sendTemporalDataTypesAsStringForBulkCopy=true;delayLoadingLobs=true;useFmtOnly=false;useBulkCopyForBatchInsert=false;cancelQueryTimeout=-1;sslProtocol=TLS;jaasConfigurationName=SQLJDBCDriver;statementPoolingCacheSize=0;serverPreparedStatementDiscardThreshold=10;enablePrepareOnFirstPreparedStatementCall=false;fips=false;socketTimeout=0;authentication=NotSpecified;authenticationScheme=nativeAuthentication;xopenStates=false;sendTimeAsDatetime=true;trustStoreType=JKS;trustServerCertificate=false;TransparentNetworkIPResolution=true;serverNameAsACE=false;sendStringParametersAsUnicode=true;selectMethod=direct;responseBuffering=adaptive;queryTimeout=-1;packetSize=8000;multiSubnetFailover=false;loginTimeout=15;lockTimeout=-1;lastUpdateCount=true;encrypt=false;disableStatementPooling=true;columnEncryptionSetting=Disabled;applicationName=Microsoft JDBC Driver for SQL Server;applicationIntent=readwrite;
895901
is JDBC compliant true
896902

897903

@@ -1095,7 +1101,7 @@ password [driver property]
10951101
portNumber [driver property]
10961102
The TCP port where an instance of SQL Server is listening.
10971103
not required
1098-
value 49317
1104+
value 49173
10991105

11001106
queryTimeout [driver property]
11011107
The number of seconds to wait before the database reports a query time-out.

schemacrawler-testdb/src/main/resources/cockroachdb.scripts.txt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#,/db/books/09_functions_01_A.sql
1919
#,/db/books/10_triggers_01_A.sql
2020
#,/db/books/11_synonyms_01_A.sql
21+
#,/db/books/11_synonyms_02_A.sql
2122
#,/db/books/12_generated_columns_01_A.sql
2223
#,/db/books/12_hidden_columns_01_A.sql
2324
#,/db/books/13_grants_01_A.sql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Synonyms for objects that do not exist
2+
CREATE SYNONYM OTHER_TABLE FOR FAKE_TABLE;

0 commit comments

Comments
 (0)