forked from opengaussexamples/examples
hibernateTest
This commit is contained in:
parent
dc74b35b5c
commit
0bfd2be29e
|
|
@ -0,0 +1,5 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# GitHub Copilot persisted chat sessions
|
||||
/copilot/chatSessions
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="VerifyJDBCDataType" />
|
||||
<module name="testGaussDB" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
<module name="testGaussDB" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="thirdparty" />
|
||||
<option name="name" value="Maven Envision thirdparty Repo" />
|
||||
<option name="url" value="http://nexus.eniot.io/content/repositories/Thirdparty" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="http://maven.aliyun.com/nexus/content/groups/public" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="maven_public_envision" />
|
||||
<option name="name" value="Maven Envision Central Repo" />
|
||||
<option name="url" value="http://nexus.eniot.io/content/groups/public" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="http://nexus.eniot.io/content/groups/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="maven_private_envision" />
|
||||
<option name="name" value="Maven Envision private Repo" />
|
||||
<option name="url" value="http://nexus.eniot.io/content/repositories/envision" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="workspaceImportForciblyTurnedOn" value="true" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/testGaussDB.iml" filepath="$PROJECT_DIR$/.idea/testGaussDB.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>VerifyJDBCDataType</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>2.7.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<version>2.7.9</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.opengauss</groupId>
|
||||
<artifactId>opengauss-jdbc</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.20</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
<version>2.7.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
<version>2.7.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.13</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
|
||||
<!-- 指定方言 -->
|
||||
<property name="dialect">org.hibernate.dialect.PostgreSQL82Dialect</property>
|
||||
|
||||
<!-- 映射类 -->
|
||||
<mapping class="org.example.MyEntity">
|
||||
<property name="id">
|
||||
<column name="id" sql-type="1111" />
|
||||
</property>
|
||||
<!-- <property name="name">-->
|
||||
<!-- <column name="name" sql-type="VARCHAR(255)" />-->
|
||||
<!-- </property>-->
|
||||
<!-- 其他属性 -->
|
||||
</mapping>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.example;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package org.example.controller;
|
||||
|
||||
import org.example.entity.BinaryEntity;
|
||||
import org.hibernate.transform.Transformers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@ResponseBody
|
||||
@RequestMapping("/og")
|
||||
public class BinaryTypeController {
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
@GetMapping("/queryBinary")
|
||||
@Transactional
|
||||
public List<Object> testBinary() {
|
||||
String dropSql = "drop table if exists t_binary";
|
||||
Query q1 = entityManager.createNativeQuery(dropSql);
|
||||
q1.executeUpdate();
|
||||
String createSql = "create table t_binary(c1 binary,c2 binary(5))";
|
||||
Query q2 = entityManager.createNativeQuery(createSql);
|
||||
q2.executeUpdate();
|
||||
|
||||
String paramSql = "set bytea_output=escape;";
|
||||
Query q5 = entityManager.createNativeQuery(paramSql);
|
||||
q5.executeUpdate();
|
||||
|
||||
String insertSql = "insert into t_binary values('a','abcde')";
|
||||
Query q3 = entityManager.createNativeQuery(insertSql);
|
||||
q3.executeUpdate();
|
||||
|
||||
String selectSql = "select * from t_binary";
|
||||
Query q4 = entityManager.createNativeQuery(selectSql);
|
||||
q4.unwrap(org.hibernate.Query.class)
|
||||
.setResultTransformer(Transformers.aliasToBean(BinaryEntity.class));
|
||||
List<BinaryEntity> list = q4.getResultList();
|
||||
List<Object> result = new ArrayList<>();
|
||||
result.add(new String(list.get(0).getC1()));
|
||||
result.add(new String(list.get(0).getC2()));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package org.example.controller;
|
||||
|
||||
import org.example.entity.BitEntity;
|
||||
import org.hibernate.transform.Transformers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@ResponseBody
|
||||
@RequestMapping("/og")
|
||||
public class BitTypeTest {
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
@GetMapping("/queryBit")
|
||||
@Transactional
|
||||
public List<Object> testBit() {
|
||||
String dropSql = "drop table if exists t_bit";
|
||||
Query q1 = entityManager.createNativeQuery(dropSql);
|
||||
q1.executeUpdate();
|
||||
String createSql = "create table t_bit(c1 bit(1),c2 bit(5),c3 bit(10),c4 boolean)";
|
||||
Query q2 = entityManager.createNativeQuery(createSql);
|
||||
q2.executeUpdate();
|
||||
|
||||
String insertSql = "insert into t_bit values(1,28,369,false)";
|
||||
Query q3 = entityManager.createNativeQuery(insertSql);
|
||||
q3.executeUpdate();
|
||||
|
||||
String selectSql = "select * from t_bit";
|
||||
Query q4 = entityManager.createNativeQuery(selectSql);
|
||||
q4.unwrap(org.hibernate.Query.class)
|
||||
.setResultTransformer(Transformers.aliasToBean(BitEntity.class));
|
||||
return q4.getResultList();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package org.example.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@ResponseBody
|
||||
@RequestMapping("/og")
|
||||
public class BlobTypeTest {
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
@GetMapping("/queryBlob")
|
||||
@Transactional
|
||||
public List<Object> testBlob() {
|
||||
String dropSql = "drop table if exists t_blob";
|
||||
Query q1 = entityManager.createNativeQuery(dropSql);
|
||||
q1.executeUpdate();
|
||||
String createSql = "create table t_blob(id blob)";
|
||||
Query q2 = entityManager.createNativeQuery(createSql);
|
||||
q2.executeUpdate();
|
||||
|
||||
String insertSql = "insert into t_blob values('abc')";
|
||||
Query q3 = entityManager.createNativeQuery(insertSql);
|
||||
q3.executeUpdate();
|
||||
|
||||
String selectSql = "select * from t_blob";
|
||||
Query q4 = entityManager.createNativeQuery(selectSql);
|
||||
List<byte[]> list = q4.getResultList();
|
||||
List<Object> result = new ArrayList<>();
|
||||
result.add(new String(list.get(0)));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
package org.example.controller;
|
||||
|
||||
import org.example.entity.DateEntity;
|
||||
import org.hibernate.transform.Transformers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@ResponseBody
|
||||
@RequestMapping("/og")
|
||||
public class DateTypeTest {
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
@GetMapping("/queryDate1")
|
||||
@Transactional
|
||||
public List<Object> testCastTime() {
|
||||
String dropSql = "drop table if exists t_as_time";
|
||||
Query q1 = entityManager.createNativeQuery(dropSql);
|
||||
q1.executeUpdate();
|
||||
String createSql = "create table t_as_time(c1 varchar(32), c2 varchar(32), c3 varchar(32))";
|
||||
Query q2 = entityManager.createNativeQuery(createSql);
|
||||
q2.executeUpdate();
|
||||
|
||||
String insertSql = "insert into t_as_time values(?1,?2,?3)";
|
||||
Query q3 = entityManager.createNativeQuery(insertSql);
|
||||
q3.setParameter(1, "12345");
|
||||
q3.setParameter(2, "-1948");
|
||||
q3.setParameter(3, "0");
|
||||
q3.executeUpdate();
|
||||
q3.setParameter(1, "2024-04-05");
|
||||
q3.setParameter(2, "12:12:12");
|
||||
q3.setParameter(3, "2018/5/9");
|
||||
q3.executeUpdate();
|
||||
|
||||
String selectSql = "select cast(c1 as time),cast(c2 as time),cast(c3 as time) from t_as_time";
|
||||
Query q4 = entityManager.createNativeQuery(selectSql);
|
||||
return q4.getResultList();
|
||||
}
|
||||
|
||||
@GetMapping("/queryDate2")
|
||||
@Transactional
|
||||
public List<Object> testCastDate() {
|
||||
String dropSql = "drop table if exists t_as_date";
|
||||
Query q1 = entityManager.createNativeQuery(dropSql);
|
||||
q1.executeUpdate();
|
||||
String createSql = "create table t_as_date(c1 varchar(32), c2 varchar(32), c3 varchar(32))";
|
||||
Query q2 = entityManager.createNativeQuery(createSql);
|
||||
q2.executeUpdate();
|
||||
|
||||
String insertSql = "insert into t_as_date values(?1,?2,?3)";
|
||||
Query q3 = entityManager.createNativeQuery(insertSql);
|
||||
q3.setParameter(1, "2024-04-05");
|
||||
q3.setParameter(2, "12:12:12");
|
||||
q3.setParameter(3, "2018/5/9");
|
||||
q3.executeUpdate();
|
||||
|
||||
String selectSql = "select cast(c1 as date),cast(c2 as date),cast(c3 as date) from t_as_date";
|
||||
Query q4 = entityManager.createNativeQuery(selectSql);
|
||||
return q4.getResultList();
|
||||
}
|
||||
|
||||
@GetMapping("/queryDate3")
|
||||
@Transactional
|
||||
public List<Object> testDate() {
|
||||
String dropSql = "drop table if exists t_date";
|
||||
Query q1 = entityManager.createNativeQuery(dropSql);
|
||||
q1.executeUpdate();
|
||||
String createSql = "create table t_date(c1 date, c2 time, c3 year, c4 datetime, c5 timestamp)";
|
||||
Query q2 = entityManager.createNativeQuery(createSql);
|
||||
q2.executeUpdate();
|
||||
|
||||
String insertSql = "insert into t_date values(?1,?2,?3,?4,?5)";
|
||||
Query q3 = entityManager.createNativeQuery(insertSql);
|
||||
Date date = new Date();
|
||||
q3.setParameter(1, date);
|
||||
q3.setParameter(2, date);
|
||||
q3.setParameter(3, "2024");
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
q3.setParameter(4, dateTime);
|
||||
q3.setParameter(5, dateTime);
|
||||
q3.executeUpdate();
|
||||
|
||||
String selectSql = "select * from t_date";
|
||||
Query q4 = entityManager.createNativeQuery(selectSql);
|
||||
q4.unwrap(org.hibernate.Query.class)
|
||||
.setResultTransformer(Transformers.aliasToBean(DateEntity.class));
|
||||
return q4.getResultList();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package org.example.controller;
|
||||
|
||||
import org.example.entity.DoubleEntity;
|
||||
import org.example.entity.IntEntity;
|
||||
import org.hibernate.transform.Transformers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@ResponseBody
|
||||
@RequestMapping("/og")
|
||||
public class NumberTypeTest {
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
@GetMapping("/queryInt")
|
||||
@Transactional
|
||||
public List<Object> testInt() {
|
||||
String dropSql = "drop table if exists t_int";
|
||||
Query q1 = entityManager.createNativeQuery(dropSql);
|
||||
q1.executeUpdate();
|
||||
String createSql = "create table t_int(c1 tinyint,c2 smallint,c3 int,c4 bigint," +
|
||||
"c5 tinyint unsigned,c6 smallint unsigned,c7 int unsigned,c8 bigint unsigned)";
|
||||
Query q2 = entityManager.createNativeQuery(createSql);
|
||||
q2.executeUpdate();
|
||||
|
||||
String insertSql = "insert into t_int values(18,479,-3950438,-38475983932,105,785,5902,13345)";
|
||||
Query q3 = entityManager.createNativeQuery(insertSql);
|
||||
q3.executeUpdate();
|
||||
|
||||
String selectSql = "select * from t_int";
|
||||
Query q4 = entityManager.createNativeQuery(selectSql);
|
||||
q4.unwrap(org.hibernate.Query.class)
|
||||
.setResultTransformer(Transformers.aliasToBean(IntEntity.class));
|
||||
return q4.getResultList();
|
||||
}
|
||||
|
||||
@GetMapping("/queryDouble")
|
||||
@Transactional
|
||||
public List<Object> testDouble() {
|
||||
String dropSql = "drop table if exists t_double";
|
||||
Query q1 = entityManager.createNativeQuery(dropSql);
|
||||
q1.executeUpdate();
|
||||
String createSql = "create table t_double(c1 float,c2 double,c3 numeric,c4 numeric(10,6),c5 decimal,c6 decimal(10,6))";
|
||||
Query q2 = entityManager.createNativeQuery(createSql);
|
||||
q2.executeUpdate();
|
||||
|
||||
String insertSql = "insert into t_double values(3.5,3.6,3.75564,2.9837453,5.33847462,3.211)";
|
||||
Query q3 = entityManager.createNativeQuery(insertSql);
|
||||
q3.executeUpdate();
|
||||
|
||||
String selectSql = "select * from t_double";
|
||||
Query q4 = entityManager.createNativeQuery(selectSql);
|
||||
q4.unwrap(org.hibernate.Query.class)
|
||||
.setResultTransformer(Transformers.aliasToBean(DoubleEntity.class));
|
||||
return q4.getResultList();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package org.example.controller;
|
||||
|
||||
import org.example.entity.StringEntity;
|
||||
import org.hibernate.transform.Transformers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* other
|
||||
*/
|
||||
@Controller
|
||||
@ResponseBody
|
||||
@RequestMapping("/og")
|
||||
public class OtherTypeTest {
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
@GetMapping("/queryString")
|
||||
@Transactional
|
||||
public List<Object> testString() {
|
||||
String dropSql = "drop table if exists t_varchar";
|
||||
Query q1 = entityManager.createNativeQuery(dropSql);
|
||||
q1.executeUpdate();
|
||||
String createSql = "create table t_varchar(c1 varchar(5),c2 text,c3 json)";
|
||||
Query q2 = entityManager.createNativeQuery(createSql);
|
||||
q2.executeUpdate();
|
||||
|
||||
String insertSql = "insert into t_varchar values('abc','mytest','{\"a\":\"b\",\"c\":\"d\"}')";
|
||||
Query q3 = entityManager.createNativeQuery(insertSql);
|
||||
q3.executeUpdate();
|
||||
|
||||
String selectSql = "select * from t_varchar";
|
||||
Query q4 = entityManager.createNativeQuery(selectSql);
|
||||
q4.unwrap(org.hibernate.Query.class)
|
||||
.setResultTransformer(Transformers.aliasToBean(StringEntity.class));
|
||||
return q4.getResultList();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package org.example.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BinaryEntity {
|
||||
byte[] c1;
|
||||
byte[] c2;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.example.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BitEntity {
|
||||
boolean c1;
|
||||
boolean c2;
|
||||
boolean c3;
|
||||
boolean c4;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.example.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BlobEntity {
|
||||
Object c1;
|
||||
Object c2;
|
||||
Object c3;
|
||||
Object c4;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.example.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class DateEntity {
|
||||
Date c1;
|
||||
Time c2;
|
||||
Date c3;
|
||||
Timestamp c4;
|
||||
Timestamp c5;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.example.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class DoubleEntity {
|
||||
double c1;
|
||||
double c2;
|
||||
BigDecimal c3;
|
||||
BigDecimal c4;
|
||||
BigDecimal c5;
|
||||
BigDecimal c6;
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package org.example.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
@Data
|
||||
public class IntEntity {
|
||||
Byte c1;
|
||||
Short c2;
|
||||
Integer c3;
|
||||
BigInteger c4;
|
||||
Byte c5;
|
||||
Short c6;
|
||||
Integer c7;
|
||||
BigInteger c8;
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package org.example.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class StringEntity {
|
||||
String c1;
|
||||
String c2;
|
||||
String c3;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
server.port=8899
|
||||
spring.datasource.url = jdbc:opengauss://127.0.0.1:5432/target_db?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&bitToString=true
|
||||
spring.datasource.username = test
|
||||
spring.datasource.password = @og123456
|
||||
spring.datasource.driverClassName = org.opengauss.Driver
|
||||
spring.jpa.show-sql = true
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
server.port=8899
|
||||
spring.datasource.url = jdbc:opengauss://192.168.0.118:5437/jdbc_utf8_b?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&bitToString=true
|
||||
spring.datasource.username = zt2
|
||||
spring.datasource.password = @zt7567628
|
||||
spring.datasource.driverClassName = org.opengauss.Driver
|
||||
spring.jpa.show-sql = true
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$" dumb="true">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea/copilot/chatSessions" />
|
||||
</content>
|
||||
</component>
|
||||
</module>
|
||||
Loading…
Reference in New Issue