Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class EbeanLocalAccess<URN extends Urn> implements IEbeanLocalAccess<URN>
private static final int DEFAULT_PAGE_SIZE = 1000;
private static final String ASPECT_JSON_PLACEHOLDER = "__PLACEHOLDER__";
private static final String DEFAULT_ACTOR = "urn:li:principal:UNKNOWN";
private static final String EBEAN_SERVER_CONFIG = "EbeanServerConfig";
private static final String SERVICE_IDENTIFIER = "SERVICE_IDENTIFIER";

// key: table_name,
// value: Set(column1, column2, column3 ...)
Expand Down Expand Up @@ -623,14 +623,9 @@ private String toJsonString(@Nonnull URN urn) {

@Nonnull
private SchemaEvolutionManager createSchemaEvolutionManager(@Nonnull ServerConfig serverConfig) {

String name = serverConfig.getName();
String identifier = null;

if (name != null && name.endsWith(EBEAN_SERVER_CONFIG)) {
identifier = name.substring(0, name.length() - EBEAN_SERVER_CONFIG.length());
}

String identifier = serverConfig.getDataSourceConfig().getCustomProperties() != null
? serverConfig.getDataSourceConfig().getCustomProperties().getOrDefault(SERVICE_IDENTIFIER, null)
: null;
SchemaEvolutionManager.Config config = new SchemaEvolutionManager.Config(
serverConfig.getDataSourceConfig().getUrl(),
serverConfig.getDataSourceConfig().getPassword(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

/**
* This class tests have excatly the same content as EbeanLocalAccessTest, except with a different DB server config.
* It is expected to read default EbeanLocalAccessTest.conf file rather than EbeanLocalAccessTest-EbeanLocalAccessTest.conf.
* It is expected to read default EbeanLocalAccessTest.conf file rather than test-EbeanLocalAccessTest.conf.
*/

public class EbeanLocalAccessTestWithoutServiceIdentifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public class EbeanLocalDAOTest {
private static final String GMA_DROP_ALL_SQL = "gma-drop-all.sql";

private static final String CREATE_ALL_WITH_NON_DOLLAR_VIRTUAL_COLUMN_SQL = "ebean-local-dao-create-all-with-non-dollar-virtual-column-names.sql";
private static final String EBEAN_SERVER_CONFIG = "EbeanServerConfig";
private final EBeanDAOConfig _eBeanDAOConfig = new EBeanDAOConfig();
private static final LocalRelationshipFilter
EMPTY_FILTER = new LocalRelationshipFilter().setCriteria(new LocalRelationshipCriterionArray());
Expand Down Expand Up @@ -4090,15 +4089,15 @@ private void addIndex(Urn urn, String aspectName, String pathName, Object val) {
_eBeanDAOConfig.isNonDollarVirtualColumnsEnabled()); // e.g. i_aspectfoo$path1$value1

String checkColumnExistance = String.format("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '%s' AND"
+ " TABLE_NAME = '%s' AND COLUMN_NAME = '%s'", getDatabaseName(), getTableName(urn), fullIndexColumnName);
+ " TABLE_NAME = '%s' AND COLUMN_NAME = '%s'", _server.getName(), getTableName(urn), fullIndexColumnName);

if (_server.createSqlQuery(checkColumnExistance).findList().isEmpty()) {
String sqlUpdate = String.format("ALTER TABLE %s ADD COLUMN %s VARCHAR(255);", getTableName(urn), fullIndexColumnName);
_server.execute(Ebean.createSqlUpdate(sqlUpdate));
}

checkColumnExistance = String.format("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '%s' AND"
+ " TABLE_NAME = '%s' AND COLUMN_NAME = '%s'", getDatabaseName(), getTableName(urn), aspectColumnName);
+ " TABLE_NAME = '%s' AND COLUMN_NAME = '%s'", _server.getName(), getTableName(urn), aspectColumnName);
// similarly for index columns (i_*), we need to add any new aspect columns (a_*)
if (aspectColumnName != null && _server.createSqlQuery(checkColumnExistance).findList().isEmpty()) {
String sqlUpdate = String.format("ALTER TABLE %s ADD COLUMN %s VARCHAR(255);", getTableName(urn), aspectColumnName);
Expand Down Expand Up @@ -4237,21 +4236,4 @@ public void testExtractOptimisticLockForAspectFromIngestionParamsIfPossibleAspec

assertNull(result);
}

/**
* Returns the name of the database by removing the Ebean server configuration suffix
* from the server name. If the server name does not end with the expected suffix,
* an IllegalStateException is thrown.
*
* @return the database name without the Ebean server configuration suffix.
* @throws IllegalStateException if the server name does not end with the Ebean server configuration suffix.
*/
private String getDatabaseName() {
String name = _server.getName();
if (name != null && name.endsWith(EBEAN_SERVER_CONFIG)) {
return name.substring(0, name.length() - EBEAN_SERVER_CONFIG.length());
} else {
throw new IllegalStateException("Server name does not end with '" + EBEAN_SERVER_CONFIG + "': " + name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public class FlywaySchemaEvolutionManagerTest {
private FlywaySchemaEvolutionManager _schemaEvolutionManager;
private EbeanServer _server;

private static final String EBEAN_SERVER_CONFIG = "EbeanServerConfig";

@BeforeClass
public void init() throws IOException {
_server = EmbeddedMariaInstance.getServer(FlywaySchemaEvolutionManagerTest.class.getSimpleName());
Expand All @@ -29,7 +27,7 @@ public void init() throws IOException {
EmbeddedMariaInstance.SERVER_CONFIG_MAP.get(_server.getName()).getDataSourceConfig().getUrl(),
EmbeddedMariaInstance.SERVER_CONFIG_MAP.get(_server.getName()).getDataSourceConfig().getPassword(),
EmbeddedMariaInstance.SERVER_CONFIG_MAP.get(_server.getName()).getDataSourceConfig().getUsername(),
extractServiceIdentifier()
EmbeddedMariaInstance.SERVER_CONFIG_MAP.get(_server.getName()).getDataSourceConfig().getCustomProperties().get("SERVICE_IDENTIFIER")
);

_schemaEvolutionManager = new FlywaySchemaEvolutionManager(config);
Expand Down Expand Up @@ -59,7 +57,7 @@ public void testSchemaUpToDate() {

private boolean checkTableExists(String tableName) {
String checkTableExistsSql = String.format("SELECT count(*) as count FROM information_schema.TABLES WHERE TABLE_SCHEMA = '%s' AND"
+ " TABLE_NAME = '%s'", getDatabaseName(), tableName);
+ " TABLE_NAME = '%s'", _server.getName(), tableName);

return _server.createSqlQuery(checkTableExistsSql).findOne().getInteger("count") == 1;
}
Expand Down Expand Up @@ -101,23 +99,4 @@ public void testGetDatabaseName() throws NoSuchMethodException, InvocationTarget
SchemaEvolutionManager.Config config4 = new SchemaEvolutionManager.Config(databaseUrl, "pw", "user", "case4");
assertEquals(method.invoke(_schemaEvolutionManager, config4), "my_first_db");
}


private String extractServiceIdentifier() {
String serverName = _server.getName();
return serverName.substring(0, serverName.indexOf(EBEAN_SERVER_CONFIG));
}

/**
* Return the database name associated with the given Ebean server.
* @return the database name
*/
private String getDatabaseName() {
String name = _server.getName();
if (name != null && name.endsWith(EBEAN_SERVER_CONFIG)) {
return name.substring(0, name.length() - EBEAN_SERVER_CONFIG.length());
} else {
throw new IllegalStateException("Server name does not end with '" + EBEAN_SERVER_CONFIG + "': " + name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


Expand Down Expand Up @@ -44,9 +46,12 @@ public static synchronized EbeanServer getServer(String dbSchema) {
dataSourceConfig.setPassword(DB_PASS);
dataSourceConfig.setUrl(String.format("jdbc:mysql://localhost:%s/%s?allowMultiQueries=true", PORT, dbSchema));
dataSourceConfig.setDriver("com.mysql.cj.jdbc.Driver");
Map<String, String> customProperties = new HashMap<>();
customProperties.put("SERVICE_IDENTIFIER", "test");
dataSourceConfig.setCustomProperties(customProperties);

ServerConfig serverConfig = new ServerConfig();
serverConfig.setName(dbSchema + "EbeanServerConfig");
serverConfig.setName(dbSchema);
serverConfig.setDataSourceConfig(dataSourceConfig);
serverConfig.setDdlGenerate(false);
serverConfig.setDdlRun(false);
Expand Down