Relation doesn't exists when executing CDOServerUtil.addRepository() [message #1860877] |
Thu, 07 September 2023 04:44 |
I S Messages: 13 Registered: May 2022 |
Junior Member |
|
|
I'm using CDO 4.10. When I try to execute the following code, I get an exception while the last line is executing CDOServerUtil.addRepository( container, registerRepository );
Quote:
org.eclipse.net4j.db.DBException: org.postgresql.util.PSQLException: ERROR: relation "battery_level_mapping" does not exist
Position: 15
IDBAdapter dbAdapter = new PostgreSQLAdapter();
PGSimpleDataSource dataSource = new PGSimpleDataSource();
dataSource.setServerName( IP);
dataSource.setPortNumber( port);
dataSource.setDatabaseName( DB );
dataSource.setUser( User);
dataSource.setPassword( Pass );
IMappingStrategy mappingStrategy = null;
mappingStrategy = new HorizontalAuditMappingStrategy();
IDBConnectionProvider connectionProvider = DBUtil.createConnectionProvider(dataSource);
Map<String, String> registerProperties = new HashMap<String, String>();
registerProperties.put( Props.OVERRIDE_UUID, "public" );
registerProperties.put( Props.SUPPORTING_AUDITS, String.valueOf( true ) );
IDBStore store = CDODBUtil.createStore( mappingStrategy, dbAdapter, connectionProvider );
IRepository registerRepository = CDOServerUtil.createRepository("public", store, registerProperties );
IManagedContainer container = ContainerUtil.createContainer();
JVMUtil.prepareContainer(container);
LifecycleUtil.activate( container );
CDOServerUtil.addRepository( container, registerRepository );
The battery_level_mapping table from the exception located in another schema, not in public but DBAdatper.readSchema() ignores the schema name I passed. Actually, DBAdatper.readSchema() recieves the schema name in UPPER case and then drops schema name to null and tries to read all tables in all schemas. It happens in the last if statement, in the code below Icopied from org.eclipse.net4j.spi.db.DBAdatper class because schemaName is in UPPER case and schemaNames contains schema names in lower case as they are in the database.
public void readSchema(Connection connection, IDBSchema schema) {
boolean wasTrackConstruction = DBField.isTrackConstruction();
DBField.trackConstruction(false);
try {
String schemaName = schema.getName();
DatabaseMetaData metaData = connection.getMetaData();
Set<String> schemaNames = DBUtil.getAllSchemaNames(metaData);
if (!schemaNames.contains(schemaName)) {
schemaName = null;
}
///////////////////////////////////////////
How can I pass schema name and avoid using other schemas other than public?
P.S. Also, you ca6n find the problem from the screenshot attached.
[Updated on: Thu, 07 September 2023 04:47] Report message to a moderator
|
|
|
Re: Relation doesn't exists when executing CDOServerUtil.addRepository() [message #1860878 is a reply to message #1860877] |
Thu, 07 September 2023 06:10 |
|
You didn't paste a stacktrace that shows how exactly you end up with the upper case schema name in readSchema(), so I can only guess that the call stack looks similar to this:
org.eclipse.net4j.spi.db.DBAdapter.readSchema(Connection, IDBSchema)
org.eclipse.net4j.db.DBUtil.readSchema(IDBAdapter, Connection, IDBSchema)
org.eclipse.net4j.db.DBUtil.readSchema(IDBAdapter, Connection, String, boolean)
org.eclipse.net4j.internal.db.DBDatabase.DBDatabase(...).new RunnableWithConnection() {...}.run(Connection)
org.eclipse.net4j.internal.db.DBDatabase.DBDatabase(...).new RunnableWithConnection() {...}
org.eclipse.net4j.internal.db.DBDatabase.DBDatabase(DBAdapter, IDBConnectionProvider, String, boolean)
org.eclipse.net4j.db.DBUtil.openDatabase(IDBAdapter, IDBConnectionProvider, String, boolean)
org.eclipse.emf.cdo.server.internal.db.DBStore.openDatabase(IDBAdapter, IDBConnectionProvider, String, boolean)
org.eclipse.emf.cdo.server.internal.db.DBStore.doActivate()
But that would mean that the schema name comes from DBStore.doActivate(), where it's computed like so:
String schemaName = repository.getName();
database = openDatabase(dbAdapter, dbConnectionProvider, schemaName, fixNullableIndexColumns);
Perhaps you can find out why it's upper case?
In any case you could subclass PostgreSQLAdapter and override readSchema(). If there's anything I can fix, I can do it only in master for the 4.25 release in December, not in 4.10.
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01693 seconds