use of org.postgresql.PGNotification in project binnavi by google.
the class PostgreSQLTypesNotificationParser method parse.
@Override
public Collection<TypesNotificationContainer> parse(final Collection<PGNotification> notifications, final SQLProvider provider) {
Preconditions.checkNotNull(notifications, "Error: notifications argument can not be null");
Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
final Collection<TypesNotificationContainer> containers = Lists.newArrayList();
for (final PGNotification notification : notifications) {
if (notification.getParameter().startsWith(CTableNames.EXPRESSION_TYPES_TABLE)) {
containers.add(parseExpressionTypesNotification(notification));
} else if (notification.getParameter().startsWith(CTableNames.TYPE_MEMBERS_TABLE)) {
containers.add(parseTypesNotification(notification));
} else if (notification.getParameter().startsWith(CTableNames.BASE_TYPES_TABLE)) {
containers.add(parseBaseTypesNotification(notification));
} else {
throw new IllegalStateException("Error: Table name supplied in notification " + notification.getParameter() + " does not match tables where type notifications are expected on.");
}
}
return containers;
}
use of org.postgresql.PGNotification in project binnavi by google.
the class PostgreSQLTypeInstancesNotificationParser method parse.
@Override
public Collection<TypeInstancesNotificationContainer> parse(final Collection<PGNotification> notifications, final SQLProvider provider) {
Preconditions.checkNotNull(notifications, "Error: notifications argument can not be null");
Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
final Collection<TypeInstancesNotificationContainer> containers = Lists.newArrayList();
for (final PGNotification notification : notifications) {
if (notification.getParameter().startsWith(CTableNames.TYPE_INSTANCE_TABLE)) {
containers.add(parseTypeInstanceNotification(notification));
} else if (notification.getParameter().startsWith(CTableNames.EXPRESSION_TYPE_INSTANCES_TABLE)) {
containers.add(parseExpressionTypeInstanceNotification(notification));
} else {
throw new IllegalStateException("Error: Table name supplied in notification " + notification.getParameter() + " does not match tables where type instance notifications are accepted on.");
}
}
return containers;
}
use of org.postgresql.PGNotification in project binnavi by google.
the class PostgreSQLViewNotificationParser method parse.
/**
* The parser function for view notifications. The function checks for the database table the
* notification originated from and dispatches the parsing appropriately to the right function.
*
* @param notifications The {@link Collection} of {@link PGNotification} to parse.
* @param provider The {@link SQLProvider} to access the database with.
* @return A {@link Collection} of {@link ViewNotificationContainer}.
*/
@Override
public Collection<ViewNotificationContainer> parse(final Collection<PGNotification> notifications, final SQLProvider provider) {
Preconditions.checkNotNull(notifications, "IE02745: notifications argument can not be null");
Preconditions.checkNotNull(provider, "IE02746: provider argument can not be null");
final Collection<ViewNotificationContainer> containers = Lists.newArrayList();
for (final PGNotification notification : notifications) {
if (notification.getParameter().startsWith(CTableNames.VIEWS_TABLE)) {
containers.add(parseViewNotification(notification, provider));
} else if (notification.getParameter().startsWith(CTableNames.MODULE_VIEWS_TABLE)) {
containers.add(parseModuleViewNotification(notification, provider));
} else if (notification.getParameter().startsWith(CTableNames.PROJECT_VIEWS_TABLE)) {
containers.add(parseProjectViewNotification(notification, provider));
} else {
throw new IllegalStateException("IE02747: Table name supplied in notification: " + notification.getParameter() + " does not match tables where view notifications are accepted on.");
}
}
return containers;
}
use of org.postgresql.PGNotification in project binnavi by google.
the class PostgreSQLCommentNotificationParser method parse.
@Override
public Collection<CommentNotification> parse(final Collection<PGNotification> commentNotifications, final SQLProvider provider) {
Preconditions.checkNotNull(commentNotifications, "Error: commentNotifications argument can not be null");
Preconditions.checkNotNull(provider, "IE02524: provider argument can not be null");
for (final PGNotification notification : commentNotifications) {
final String notificationParameter = notification.getParameter();
final String tableName = notificationParameter.split("\\s")[0];
try {
switch(tableName) {
case CTableNames.CODENODE_INSTRUCTIONS_TABLE:
informNotification(processNodeLocalInstructionCommentNotification(notification, provider), provider);
break;
case CTableNames.INSTRUCTIONS_TABLE:
informNotification(processInstructionGlobalCommentNotification(notification, provider), provider);
break;
case CTableNames.CODE_NODES_TABLE:
informNotification(processNodeLocalNodeCommentNotification(notification, provider), provider);
break;
case CTableNames.GLOBAL_NODE_COMMENTS_TABLE:
informNotification(processNodeGlobalCommentNotification(notification, provider), provider);
break;
case CTableNames.EDGES_TABLE:
informNotification(processEdgeLocalCommentNotification(notification, provider), provider);
break;
case CTableNames.GLOBAL_EDGE_COMMENTS_TABLE:
informNotification(processEdgeGlobalCommentNotification(notification, provider), provider);
break;
case CTableNames.FUNCTION_NODES_TABLE:
informNotification(processFunctionNodeCommentNotification(notification, provider), provider);
break;
case CTableNames.FUNCTIONS_TABLE:
informNotification(processFunctionCommentNotification(notification, provider), provider);
break;
case CTableNames.TEXT_NODES_TABLE:
informNotification(processTextNodeCommentNotification(notification, provider), provider);
break;
case CTableNames.GROUP_NODES_TABLE:
informNotification(processGroupNodeCommentNotification(notification, provider), provider);
break;
case CTableNames.TYPE_INSTANCE_TABLE:
informNotification(processTypeInstanceCommentNotification(notification, provider), provider);
break;
case CTableNames.COMMENTS_TABLE:
informNotification(processCommentNotification(notification, provider), provider);
break;
default:
NaviLogger.warning("Table name %s not known", tableName);
}
} catch (CouldntLoadDataException exception) {
NaviLogger.severe("Error: Could not successfully parse the database comment notification: %s", notification.toString());
}
}
// TODO(timkornau): change the interface to not return anything here.
return new ArrayList<>();
}
use of org.postgresql.PGNotification in project binnavi by google.
the class PostgreSQLNotificationParserTest method testTypeInstanceCommentParsingDeleteComment.
@Test
public void testTypeInstanceCommentParsingDeleteComment() throws CouldntSaveDataException, CouldntLoadDataException {
final INaviModule module = new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
module.getContent().getSections().createSection("A", new CAddress(0), new CAddress(1234), SectionPermission.READ, null);
final TypeInstance fakeInstance = module.getContent().getTypeInstanceContainer().createInstance("TYPE INSTANCE", null, module.getTypeManager().getTypes().get(0), module.getContent().getSections().getSection(0), 0);
final PGNotification notification = new MockPGNotification("comment_changes", "bn_type_instances UPDATE 1 " + fakeInstance.getId() + " null");
final CommentNotification result = PostgreSQLCommentNotificationParser.processTypeInstanceCommentNotification(notification, provider);
assertNotNull(result);
final TypeInstanceCommentNotificationContainer container = (TypeInstanceCommentNotificationContainer) result;
assertNotNull(container);
final TypeInstance instance = container.getInstance();
assertEquals(fakeInstance.getId(), instance.getId());
assertEquals(CommentOperation.DELETE, container.getOperation());
assertNull(container.getCommentId());
}
Aggregations