-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3667a5b
commit a66c331
Showing
7 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
group=org.babyfish.jimmer | ||
version=0.9.57 | ||
version=0.9.58 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...t/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/model/pg/MacAddressScalarProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.babyfish.jimmer.sql.model.pg; | ||
|
||
import org.babyfish.jimmer.sql.runtime.ScalarProvider; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.postgresql.util.PGobject; | ||
|
||
public class MacAddressScalarProvider implements ScalarProvider<String, PGobject> { | ||
|
||
@Override | ||
public String toScalar(@NotNull PGobject sqlValue) throws Exception { | ||
return sqlValue.getValue(); | ||
} | ||
|
||
@Override | ||
public PGobject toSql(@NotNull String scalarValue) throws Exception { | ||
PGobject po = new PGobject(); | ||
po.setType("macaddr"); | ||
po.setValue(scalarValue); | ||
return po; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/model/pg/PgTypeRow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.babyfish.jimmer.sql.model.pg; | ||
|
||
import org.babyfish.jimmer.sql.*; | ||
|
||
@Entity | ||
@DatabaseValidationIgnore | ||
public interface PgTypeRow { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
long id(); | ||
|
||
String macAddress(); | ||
} |
45 changes: 45 additions & 0 deletions
45
project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/mutation/PgTypeRowTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.babyfish.jimmer.sql.mutation; | ||
|
||
import org.babyfish.jimmer.sql.ast.mutation.SaveMode; | ||
import org.babyfish.jimmer.sql.common.AbstractMutationTest; | ||
import org.babyfish.jimmer.sql.common.NativeDatabases; | ||
import org.babyfish.jimmer.sql.dialect.PostgresDialect; | ||
import org.babyfish.jimmer.sql.meta.impl.IdentityIdGenerator; | ||
import org.babyfish.jimmer.sql.model.Immutables; | ||
import org.babyfish.jimmer.sql.model.pg.MacAddressScalarProvider; | ||
import org.babyfish.jimmer.sql.model.pg.PgTypeRow; | ||
import org.babyfish.jimmer.sql.model.pg.PgTypeRowProps; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class PgTypeRowTest extends AbstractMutationTest { | ||
|
||
@Test | ||
public void insert() { | ||
|
||
NativeDatabases.assumeNativeDatabase(); | ||
|
||
PgTypeRow row = Immutables.createPgTypeRow(draft -> { | ||
draft.setMacAddress("08:00:2b:01:02:03"); | ||
}); | ||
|
||
resetIdentity(NativeDatabases.POSTGRES_DATA_SOURCE, "pg_type_row"); | ||
executeAndExpectResult( | ||
NativeDatabases.POSTGRES_DATA_SOURCE, | ||
getSqlClient(it -> { | ||
it.setDialect(new PostgresDialect()); | ||
it.setIdGenerator(IdentityIdGenerator.INSTANCE); | ||
it.setScalarProvider(PgTypeRowProps.MAC_ADDRESS, new MacAddressScalarProvider()); | ||
}).saveCommand(row).setMode(SaveMode.INSERT_ONLY), | ||
ctx -> { | ||
ctx.statement(it -> { | ||
it.sql("insert into PG_TYPE_ROW(MAC_ADDRESS) values(?) returning ID"); | ||
}); | ||
ctx.entity(it -> { | ||
it.modified( | ||
"{\"id\":100,\"macAddress\":\"08:00:2b:01:02:03\"}" | ||
); | ||
}); | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters