You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I would like to write an extension plugin that automatically generates a method for querying or updating based on the unique constraint of a table. However, how can I obtain the unique constraint fields of a table in the plugin?
The text was updated successfully, but these errors were encountered:
Any plugin method has access to the plugin context. From the context you can create a database connection and retrieve information you need. In this case, you should call the getCrossReference method in database metadata and interpret the results as you wish. For example something like this:
@OverridepublicbooleanclientGenerated(Interfaceinterfaze, IntrospectedTableintrospectedTable) {
try (Connectionconnection = context.getConnection()) {
DatabaseMetaDatadatabaseMetaData = connection.getMetaData();
ResultSetresultSet = databaseMetaData.getCrossReference(...)
// process the resultSet to find the unique constraints, then generate methods as needed
} catch (SQLExceptione) {
thrownewRuntimeException("SqlException in my plugin", e);
}
returntrue;
}
If you need to do this in more than one plugin method, you could do the instrospection before the individual methods are called like this:
@Overridepublicvoidinitialized(IntrospectedTableintrospectedTable) {
try (Connectionconnection = context.getConnection()) {
DatabaseMetaDatadatabaseMetaData = connection.getMetaData();
ResultSetresultSet = databaseMetaData.getCrossReference(...)
// process the resultSet to find the unique constraints, then save that information for later use
} catch (SQLExceptione) {
thrownewRuntimeException("SqlException in my plugin", e);
}
}
@OverridepublicbooleanclientGenerated(Interfaceinterfaze, IntrospectedTableintrospectedTable) {
// use the saved data to generate methods as neededreturntrue;
}
Hello, I would like to write an extension plugin that automatically generates a method for querying or updating based on the unique constraint of a table. However, how can I obtain the unique constraint fields of a table in the plugin?
The text was updated successfully, but these errors were encountered: