Skip to content

Commit

Permalink
Merge pull request #23 from maiqingqiang/update-20240929
Browse files Browse the repository at this point in the history
1.2.10
  • Loading branch information
johnmai-dev authored Sep 29, 2024
2 parents c27fd00 + 5c46c80 commit 9e7b227
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 55 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

## [Unreleased]

## [1.2.10] - 2024-09-29

### Fixed

- Fix SQL2Struct copy and paste bug.
- Fix SQL2Struct comment line break bug.

### Changed

- Bump guava

## [1.2.9] - 2024-08-22

### Fixed
Expand Down Expand Up @@ -140,7 +151,8 @@
- ORM Code Completion
- SQL to Struct

[Unreleased]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.9...HEAD
[Unreleased]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.10...HEAD
[1.2.9]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.9...v1.2.10
[1.2.9]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.8...v1.2.9
[1.2.8]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.7...v1.2.8
[1.2.7]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.6...v1.2.7
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = com.github.maiqingqiang.goormhelper
pluginName = Go ORM Helper
pluginRepositoryUrl = https://github.com/maiqingqiang/go-orm-helper
# SemVer format -> https://semver.org
pluginVersion = 1.2.9
pluginVersion = 1.2.10

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 232
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# libraries
junit = "5.11.0"
lombok = "1.18.34"
guava = "33.3.0-jre"
guava = "33.3.1-jre"
druid = "1.2.23"
jsqlparser = "5.0"
evoInflector = "1.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.util.validation.Validation;
import net.sf.jsqlparser.util.validation.ValidationError;
import net.sf.jsqlparser.util.validation.feature.FeaturesAllowed;
Expand All @@ -27,7 +29,6 @@
import java.awt.datatransfer.DataFlavor;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class EditorPasteListener extends EditorActionHandler {

Expand All @@ -39,76 +40,91 @@ public EditorPasteListener(EditorActionHandler handler) {

@Override
protected void doExecute(@NotNull Editor editor, @Nullable Caret caret, DataContext dataContext) {

PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
if (!(file instanceof GoFile)) {
handler.execute(editor, caret, dataContext);
return;
}

if ((file instanceof GoFile)) {
String text = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
String text = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
if (!verifySQL(text)) {
handler.execute(editor, caret, dataContext);
return;
}

if (verifySQL(text)) {
Project project = editor.getProject();
Project project = editor.getProject();
if (project == null) {
handler.execute(editor, caret, dataContext);
return;
}

GoORMHelperProjectSettings.State state = Objects.requireNonNull(
GoORMHelperProjectSettings.getInstance(Objects.requireNonNull(project)).getState()
);
GoORMHelperProjectSettings.State state = GoORMHelperProjectSettings.getInstance(project).getState();
if (state == null) {
handler.execute(editor, caret, dataContext);
return;
}

Types.ORM selectedORM = state.defaultORM;
Types.Database selectedDatabase = state.defaultDatabase;
Types.ORM selectedORM = state.defaultORM;
Types.Database selectedDatabase = state.defaultDatabase;

if (selectedORM == Types.ORM.AskEveryTime || selectedDatabase == Types.Database.AskEveryTime) {
ConvertSettingDialogWrapper wrapper = new ConvertSettingDialogWrapper(project);
if (!wrapper.showAndGet()) {
this.handler.execute(editor, caret, dataContext);
return;
}
if (selectedORM == Types.ORM.AskEveryTime || selectedDatabase == Types.Database.AskEveryTime) {
ConvertSettingDialogWrapper wrapper = new ConvertSettingDialogWrapper(project);
if (!wrapper.showAndGet()) {
handler.execute(editor, caret, dataContext);
return;
}
selectedORM = (Types.ORM) wrapper.getOrmComponent().getComponent().getSelectedItem();
selectedDatabase = (Types.Database) wrapper.getDatabaseComponent().getComponent().getSelectedItem();
}

selectedORM = (Types.ORM) wrapper.getOrmComponent().getComponent().getSelectedItem();
selectedDatabase = (Types.Database) wrapper.getDatabaseComponent().getComponent().getSelectedItem();
}
final Types.ORM finalSelectedORM = selectedORM;
final Types.Database finalSelectedDatabase = selectedDatabase;

final Types.ORM finalSelectedORM = selectedORM;
final Types.Database finalSelectedDatabase = selectedDatabase;

WriteCommandAction.runWriteCommandAction(editor.getProject(), () -> {
if (text == null || text.isEmpty() || finalSelectedORM == null || finalSelectedDatabase == null)
return;

ISQL2Struct sql2Struct = finalSelectedORM.sql2Struct(text, finalSelectedDatabase.toDbType());

Caret currentCaret = editor.getCaretModel().getCurrentCaret();
int start = currentCaret.getSelectionStart();

try {
editor.getDocument().insertString(start, sql2Struct.convert());
} catch (Exception ignored) {
Notifications.Bus.notify(
new Notification(
GoORMHelperBundle.message("name"),
GoORMHelperBundle.message("sql.convert.struct.not.support"),
GoORMHelperBundle.message("sql.convert.struct.check"),
NotificationType.WARNING),
project
);
this.handler.execute(editor, caret, dataContext);
}
});
WriteCommandAction.runWriteCommandAction(project, () -> {
if (text == null || text.isEmpty() || finalSelectedORM == null || finalSelectedDatabase == null) {
return;
}

ISQL2Struct sql2Struct = finalSelectedORM.sql2Struct(text, finalSelectedDatabase.toDbType());
if (sql2Struct == null) {
return;
}
}

this.handler.execute(editor, caret, dataContext);
String struct = sql2Struct.convert();
Caret currentCaret = editor.getCaretModel().getCurrentCaret();
int start = currentCaret.getSelectionStart();
int end = currentCaret.getSelectionEnd();
Document document = editor.getDocument();

try {
if (start == end) {
document.insertString(start, struct);
} else {
document.replaceString(start, end, struct);
}
currentCaret.moveToOffset(start + struct.length());
} catch (Exception ignored) {
Notifications.Bus.notify(
new Notification(
GoORMHelperBundle.message("name"),
GoORMHelperBundle.message("sql.convert.struct.not.support"),
GoORMHelperBundle.message("sql.convert.struct.check"),
NotificationType.WARNING),
project
);
handler.execute(editor, caret, dataContext);
}
});
}

private boolean verifySQL(String sql) {
try {
CCJSqlParserUtil.parse(sql);
Validation validation = new Validation(Collections.singletonList(FeaturesAllowed.CREATE), sql);
List<ValidationError> errors = validation.validate();

return errors.isEmpty();
} catch (Exception e) {
return false;
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ protected String getColumn(@NotNull SQLColumnDefinition definition) {
protected String getComment(@NotNull SQLColumnDefinition definition) {
if (definition.getComment() == null) return "";

return Strings.clearSingleQuotn(definition.getComment().toString());
String comment = definition.getComment().toString();

comment = Strings.clearSingleQuotn(comment);

comment = comment.replaceAll("\\R", " ");

return comment;
}

}

0 comments on commit 9e7b227

Please sign in to comment.