forked from opengaussexamples/examples
test: Add unit tests for OpenGaussDialect
- Added unit tests for column type mappings. - Verified correct SQL function registration for OpenGauss functions.
This commit is contained in:
parent
e084952ff6
commit
18ba24a730
|
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager">
|
||||
<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/examples.iml" filepath="$PROJECT_DIR$/.idea/examples.iml" />
|
||||
</modules>
|
||||
</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,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<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="openGaussDialect" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</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,25 @@
|
|||
<?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" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<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="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="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?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>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/openGaussDialect.iml" filepath="$PROJECT_DIR$/openGaussDialect.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="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="hibernate" name="Hibernate">
|
||||
<configuration>
|
||||
<datasource-map />
|
||||
<naming-strategy-map />
|
||||
<deploymentDescriptor name="hibernate.cfg.xml" url="file://$MODULE_DIR$/src/main/resources/hibernate.cfg.xml" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?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="hibernate.connection.driver_class">org.opengauss.Driver</property>
|
||||
<property name="hibernate.connection.url">jdbc:opengauss://43.138.80.125:25432/osapp</property>
|
||||
<property name="hibernate.connection.username">postgres</property>
|
||||
<property name="hibernate.connection.password">osapp_openGauss@123</property>
|
||||
<property name="hibernate.dialect">org.hibernate.dialect.OpenGaussDialect</property>
|
||||
<property name="hibernate.show_sql">true</property>
|
||||
<property name="hibernate.format_sql">true</property>
|
||||
<property name="hibernate.hbm2ddl.auto">create-drop</property>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package org.hibernate.dialect.entity.datatype;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "binary_test_table")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BinaryEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private byte[] binaryField;
|
||||
@Column(name = "varBinaryField", columnDefinition = "bytea")
|
||||
private byte[] varBinaryField;
|
||||
@Column(name = "longVarBinaryField", columnDefinition = "bytea")
|
||||
private byte[] longVarBinaryField;
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package org.hibernate.dialect.entity.datatype;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "bool_test_table")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BooleanEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private Boolean booleanField;
|
||||
|
||||
@Column(columnDefinition = "bit")
|
||||
private Boolean bitField;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package org.hibernate.dialect.entity.datatype;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "char_test_table")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CharEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private Character characterField;
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package org.hibernate.dialect.entity.datatype;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.sql.Date;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Entity
|
||||
@Table(name = "date_time_test_table")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DateTimeEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private Date dateField;
|
||||
private Time timeField;
|
||||
private Timestamp timestampField;
|
||||
@Column(name = "timetzField", columnDefinition = "timetz")
|
||||
private Timestamp timetzField;
|
||||
@Column(name = "timestamptzField", columnDefinition = "timestamptz")
|
||||
private Timestamp timestamptzField;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package org.hibernate.dialect.entity.datatype;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.hibernate.annotations.TypeDef;
|
||||
import org.hibernate.annotations.TypeDefs;
|
||||
import org.hibernate.dialect.pojo.Person;
|
||||
import org.hibernate.dialect.type.JsonType;
|
||||
import org.hibernate.dialect.type.JsonbType;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "test_table")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TypeDefs({
|
||||
@TypeDef(name = "jsonb", typeClass = JsonbType.class),
|
||||
@TypeDef(name = "json", typeClass = JsonType.class),
|
||||
})
|
||||
public class JsonEntity {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@Type(type = "json")
|
||||
private Person pojoJson;
|
||||
|
||||
@Type(type = "jsonb")
|
||||
@Column(columnDefinition = "jsonb")
|
||||
private Person pojoJsonb;
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package org.hibernate.dialect.entity.datatype;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.sql.Blob;
|
||||
import java.sql.Clob;
|
||||
import java.sql.NClob;
|
||||
|
||||
@Entity
|
||||
@Table(name = "lob_test_table")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LobEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
@Lob
|
||||
private Blob blobField; // Blob --> blob
|
||||
@Lob
|
||||
private Clob clobField; // Clob --> clob
|
||||
@Lob
|
||||
private NClob nclobField; // NClob --> text
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package org.hibernate.dialect.entity.datatype;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.Nationalized;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "nationalized_table")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class NationalizedEntity {
|
||||
@Id
|
||||
private Long id;
|
||||
@Nationalized
|
||||
private String nvarcharData;
|
||||
@Nationalized
|
||||
private Character ncharData;
|
||||
@Lob
|
||||
@Nationalized
|
||||
private String nclobData;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.hibernate.dialect.entity.datatype;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Entity
|
||||
@Table(name = "number_test_table")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class NumberEntity {
|
||||
@Id
|
||||
private Long id;
|
||||
private Byte tinyIntField;
|
||||
private Short smallIntField;
|
||||
private Integer integerField;
|
||||
private Long bigIntField;
|
||||
private Float floatField;
|
||||
private Double doubleField;
|
||||
@Column(columnDefinition = "decimal(19, 2)")
|
||||
private BigDecimal decimalField;
|
||||
private BigDecimal numericField;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package org.hibernate.dialect.entity.datatype;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.Nationalized;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "string_test_table")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class StringEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private String varCharField;
|
||||
@Column(name = "longVarCharField", columnDefinition = "text")
|
||||
private String longVarCharField;
|
||||
@Nationalized
|
||||
private Character nCharField;
|
||||
@Nationalized
|
||||
private String nVarCharField;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package org.hibernate.dialect.entity.function;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "test_table")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TestEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private Double value;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.hibernate.dialect.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class Person implements Serializable {
|
||||
private Integer id;
|
||||
private String name;
|
||||
}
|
||||
|
|
@ -0,0 +1,434 @@
|
|||
package org.hibernate.dialect.unit;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.entity.function.TestEntity;
|
||||
import org.hibernate.dialect.util.HibernateUtil;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class OpenGaussFunctionTest {
|
||||
private static SessionFactory sessionFactory;
|
||||
|
||||
private Session session;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUpAll() {
|
||||
sessionFactory = HibernateUtil.getSessionFactory(TestEntity.class);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.createQuery("DELETE FROM TestEntity").executeUpdate();
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void tearDownALL() {
|
||||
if (sessionFactory != null) {
|
||||
sessionFactory.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : bytes) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) hexString.append('0');
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeMapping() {
|
||||
Transaction transaction = session.beginTransaction();
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMathFunctions() {
|
||||
Transaction transaction = session.beginTransaction();
|
||||
TestEntity testEntity = new TestEntity();
|
||||
testEntity.setValue(0.0);
|
||||
session.save(testEntity);
|
||||
transaction.commit();
|
||||
|
||||
// Test abs function
|
||||
Query<Double> absQuery = session.createQuery("select abs(-17.4) from TestEntity", Double.class);
|
||||
Double absResult = absQuery.getSingleResult();
|
||||
assertEquals(17.4, absResult, 0.001);
|
||||
|
||||
// Test cbrt function
|
||||
Query<Double> cbrtQuery = session.createQuery("select cbrt(27.0) from TestEntity", Double.class);
|
||||
Double cbrtResult = cbrtQuery.getSingleResult();
|
||||
assertEquals(3.0, cbrtResult, 0.001);
|
||||
|
||||
// Test ceil function
|
||||
Query<Double> ceilQuery = session.createQuery("select ceil(-42.8) from TestEntity", Double.class);
|
||||
Double ceilResult = ceilQuery.getSingleResult();
|
||||
assertEquals(-42L, ceilResult);
|
||||
|
||||
// Test degrees function
|
||||
Query<Double> degreesQuery = session.createQuery("select degrees(0.5) from TestEntity", Double.class);
|
||||
Double degreesResult = degreesQuery.getSingleResult();
|
||||
assertEquals(28.6478897565412, degreesResult, 0.001);
|
||||
|
||||
// Test exp function
|
||||
Query<Double> expQuery = session.createQuery("select exp(1.0) from TestEntity", Double.class);
|
||||
Double expResult = expQuery.getSingleResult();
|
||||
assertEquals(2.718281828459045, expResult, 0.001);
|
||||
|
||||
// Test floor function
|
||||
Query<Double> floorQuery = session.createQuery("select floor(-42.8) from TestEntity", Double.class);
|
||||
Double floorResult = floorQuery.getSingleResult();
|
||||
assertEquals(-43L, floorResult);
|
||||
|
||||
// Test ln function
|
||||
Query<Double> lnQuery = session.createQuery("select ln(2.0) from TestEntity", Double.class);
|
||||
Double lnResult = lnQuery.getSingleResult();
|
||||
assertEquals(0.6931471805599453, lnResult, 0.001);
|
||||
|
||||
// Test log function
|
||||
Query<Double> logQuery = session.createQuery("select log(100.0) from TestEntity", Double.class);
|
||||
Double logResult = logQuery.getSingleResult();
|
||||
assertEquals(2.0, logResult, 0.001);
|
||||
|
||||
// Test mod function
|
||||
Query<Integer> modQuery = session.createQuery("select mod(9, 4) from TestEntity", Integer.class);
|
||||
Integer modResult = modQuery.getSingleResult();
|
||||
assertEquals(1, modResult.intValue());
|
||||
|
||||
// Test pi function
|
||||
Query<Double> piQuery = session.createQuery("select pi() from TestEntity", Double.class);
|
||||
Double piResult = piQuery.getSingleResult();
|
||||
assertEquals(3.14159265358979, piResult, 0.001);
|
||||
|
||||
// Test power function
|
||||
Query<Double> powerQuery = session.createQuery("select power(9.0, 3.0) from TestEntity", Double.class);
|
||||
Double powerResult = powerQuery.getSingleResult();
|
||||
assertEquals(729.0, powerResult, 0.001);
|
||||
|
||||
// Test radians function
|
||||
Query<Double> radiansQuery = session.createQuery("select radians(45.0) from TestEntity", Double.class);
|
||||
Double radiansResult = radiansQuery.getSingleResult();
|
||||
assertEquals(0.7853981633974483, radiansResult, 0.001);
|
||||
|
||||
// Test random function
|
||||
Query<Double> randomQuery = session.createQuery("select random() from TestEntity", Double.class);
|
||||
Double randomResult = randomQuery.getSingleResult();
|
||||
assertTrue(randomResult >= 0.0 && randomResult <= 1.0);
|
||||
|
||||
// Test round function
|
||||
Query<Double> roundQuery = session.createQuery("select round(42.6) from TestEntity", Double.class);
|
||||
Double roundResult = roundQuery.getSingleResult();
|
||||
assertEquals(43L, roundResult);
|
||||
|
||||
// Test sign function
|
||||
Query<Integer> signQuery = session.createQuery("select sign(-8.4) from TestEntity", Integer.class);
|
||||
Integer signResult = signQuery.getSingleResult();
|
||||
assertEquals(-1, signResult.intValue());
|
||||
|
||||
// Test sqrt function
|
||||
Query<Double> sqrtQuery = session.createQuery("select sqrt(2.0) from TestEntity", Double.class);
|
||||
Double sqrtResult = sqrtQuery.getSingleResult();
|
||||
assertEquals(1.4142135623730951, sqrtResult, 0.001);
|
||||
|
||||
// Test trunc function
|
||||
Query<Double> truncQuery = session.createQuery("select trunc(42.8) from TestEntity", Double.class);
|
||||
Double truncResult = truncQuery.getSingleResult();
|
||||
assertEquals(42L, truncResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrigonometryFunctions() {
|
||||
Transaction transaction = session.beginTransaction();
|
||||
TestEntity testEntity = new TestEntity();
|
||||
testEntity.setValue(0.0);
|
||||
session.save(testEntity);
|
||||
transaction.commit();
|
||||
|
||||
// Test acos function
|
||||
Query<Double> acosQuery = session.createQuery("select acos(-1) from TestEntity", Double.class);
|
||||
Double acosResult = acosQuery.getSingleResult();
|
||||
assertEquals(Math.PI, acosResult, 0.0001);
|
||||
|
||||
// Test asin function
|
||||
Query<Double> asinQuery = session.createQuery("select asin(0.5) from TestEntity", Double.class);
|
||||
Double asinResult = asinQuery.getSingleResult();
|
||||
assertEquals(Math.asin(0.5), asinResult, 0.0001);
|
||||
|
||||
// Test atan function
|
||||
Query<Double> atanQuery = session.createQuery("select atan(1) from TestEntity", Double.class);
|
||||
Double atanResult = atanQuery.getSingleResult();
|
||||
assertEquals(Math.atan(1), atanResult, 0.0001);
|
||||
|
||||
// Test atan2 function
|
||||
Query<Double> atan2Query = session.createQuery("select atan2(2, 1) from TestEntity", Double.class);
|
||||
Double atan2Result = atan2Query.getSingleResult();
|
||||
assertEquals(Math.atan2(2, 1), atan2Result, 0.0001);
|
||||
|
||||
// Test cos function
|
||||
Query<Double> cosQuery = session.createQuery("select cos(-3.1415927) from TestEntity", Double.class);
|
||||
Double cosResult = cosQuery.getSingleResult();
|
||||
assertEquals(Math.cos(-3.1415927), cosResult, 0.0001);
|
||||
|
||||
// Test cot function
|
||||
Query<Double> cotQuery = session.createQuery("select cot(1) from TestEntity", Double.class);
|
||||
Double cotResult = cotQuery.getSingleResult();
|
||||
assertEquals(1.0 / Math.tan(1), cotResult, 0.0001);
|
||||
|
||||
// Test sin function
|
||||
Query<Double> sinQuery = session.createQuery("select sin(1.57079) from TestEntity", Double.class);
|
||||
Double sinResult = sinQuery.getSingleResult();
|
||||
assertEquals(Math.sin(1.57079), sinResult, 0.0001);
|
||||
|
||||
// Test tan function
|
||||
Query<Double> tanQuery = session.createQuery("select tan(20) from TestEntity", Double.class);
|
||||
Double tanResult = tanQuery.getSingleResult();
|
||||
assertEquals(Math.tan(20), tanResult, 0.0001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringFunctions() {
|
||||
Transaction transaction = session.beginTransaction();
|
||||
TestEntity testEntity = new TestEntity();
|
||||
testEntity.setValue(0.0);
|
||||
session.save(testEntity);
|
||||
transaction.commit();
|
||||
|
||||
// Test string concatenation
|
||||
Query<String> concatQuery = session.createQuery("select 'MPP' || 'DB' as result from TestEntity", String.class);
|
||||
String concatResult = concatQuery.getSingleResult();
|
||||
assertEquals("MPPDB", concatResult);
|
||||
|
||||
// Test convert function
|
||||
Query<byte[]> query = session.createQuery("select convert('text_in_utf8', 'UTF8', 'GBK') from TestEntity", byte[].class);
|
||||
byte[] convertResult = query.getSingleResult();
|
||||
String hexResult = "\\x" + bytesToHex(convertResult);
|
||||
assertEquals("\\x746578745f696e5f75746638", hexResult);
|
||||
|
||||
// Test bit_length function
|
||||
Query<Long> bitLengthQuery = session.createQuery("select bit_length('world') from TestEntity", Long.class);
|
||||
Long bitLengthResult = bitLengthQuery.getSingleResult();
|
||||
assertEquals(40, bitLengthResult.intValue());
|
||||
|
||||
// Test lower function
|
||||
Query<String> lowerQuery = session.createQuery("select lower('TOM') from TestEntity", String.class);
|
||||
String lowerResult = lowerQuery.getSingleResult();
|
||||
assertEquals("tom", lowerResult);
|
||||
|
||||
// Test overlay function
|
||||
Query<String> overlayQuery = session.createQuery("select overlay('hello','world',2,3) from TestEntity", String.class);
|
||||
String overlayResult = overlayQuery.getSingleResult();
|
||||
assertEquals("hworldo", overlayResult);
|
||||
|
||||
// Test position function
|
||||
Query<Integer> positionQuery = session.createQuery("select position('ing','string') from TestEntity", Integer.class);
|
||||
Integer positionResult = positionQuery.getSingleResult();
|
||||
assertEquals(4, positionResult.intValue());
|
||||
|
||||
// Test substring function (with start and length)
|
||||
Query<String> substringQuery = session.createQuery("select substring('Thomas',2,3) from TestEntity", String.class);
|
||||
String substringResult = substringQuery.getSingleResult();
|
||||
assertEquals("hom", substringResult);
|
||||
|
||||
substringQuery = session.createQuery("select substring('Thomas','...$') from TestEntity", String.class);
|
||||
substringResult = substringQuery.getSingleResult();
|
||||
assertEquals("mas", substringResult);
|
||||
|
||||
substringQuery = session.createQuery("select substring('foobar','o(.)b') from TestEntity", String.class);
|
||||
substringResult = substringQuery.getSingleResult();
|
||||
assertEquals("o", substringResult);
|
||||
|
||||
substringQuery = session.createQuery("select substring('foobar','(o(.)b)') from TestEntity", String.class);
|
||||
substringResult = substringQuery.getSingleResult();
|
||||
assertEquals("oob", substringResult);
|
||||
|
||||
// Test trim function
|
||||
Query<String> trimQuery = session.createQuery("select trim(both 'x' from 'xTomxx') from TestEntity", String.class);
|
||||
String trimResult = trimQuery.getSingleResult();
|
||||
assertEquals("Tom", trimResult);
|
||||
|
||||
// Test upper function
|
||||
Query<String> upperQuery = session.createQuery("select upper('tom') from TestEntity", String.class);
|
||||
String upperResult = upperQuery.getSingleResult();
|
||||
assertEquals("TOM", upperResult);
|
||||
|
||||
// Test ascii function
|
||||
Query<Integer> asciiQuery = session.createQuery("select ascii('xyz') from TestEntity", Integer.class);
|
||||
Integer asciiResult = asciiQuery.getSingleResult();
|
||||
assertEquals(120, asciiResult.intValue());
|
||||
|
||||
// Test btrim function
|
||||
Query<String> btrimQuery = session.createQuery("select btrim('sring','ing') from TestEntity", String.class);
|
||||
String btrimResult = btrimQuery.getSingleResult();
|
||||
assertEquals("sr", btrimResult);
|
||||
|
||||
// Test char function
|
||||
Query<Character> chrQuery = session.createQuery("select chr(65) from TestEntity", Character.class);
|
||||
Character chrResult = chrQuery.getSingleResult();
|
||||
assertEquals('A', chrResult);
|
||||
|
||||
// Test initcap function
|
||||
Query<String> initcapQuery = session.createQuery("select initcap('hi THOMAS') from TestEntity", String.class);
|
||||
String initcapResult = initcapQuery.getSingleResult();
|
||||
assertEquals("Hi Thomas", initcapResult);
|
||||
|
||||
// Test length function
|
||||
Query<Integer> lengthQuery = session.createQuery("select length('abcd') from TestEntity", Integer.class);
|
||||
Integer lengthResult = lengthQuery.getSingleResult();
|
||||
assertEquals(4, lengthResult.intValue());
|
||||
|
||||
// Test lpad function
|
||||
Query<String> lpadQuery = session.createQuery("select lpad('hi', 5, 'xyza') from TestEntity", String.class);
|
||||
String lpadResult = lpadQuery.getSingleResult();
|
||||
assertEquals("xyzhi", lpadResult);
|
||||
|
||||
// Test ltrim function
|
||||
Query<String> ltrimQuery = session.createQuery("select ltrim('xxxxTRIM','x') from TestEntity", String.class);
|
||||
String ltrimResult = ltrimQuery.getSingleResult();
|
||||
assertEquals("TRIM", ltrimResult);
|
||||
|
||||
// Test md5 function
|
||||
Query<String> md5Query = session.createQuery("select md5('ABC') from TestEntity", String.class);
|
||||
String md5Result = md5Query.getSingleResult();
|
||||
assertEquals("902fbdd2b1df0c4f70b4a5d23525e932", md5Result);
|
||||
|
||||
// Test repeat function
|
||||
Query<String> repeatQuery = session.createQuery("select repeat('Pg', 4) from TestEntity", String.class);
|
||||
String repeatResult = repeatQuery.getSingleResult();
|
||||
assertEquals("PgPgPgPg", repeatResult);
|
||||
|
||||
// Test replace function
|
||||
Query<String> replaceQuery = session.createQuery("select replace('abcdefabcdef', 'cd', 'XXX') from TestEntity", String.class);
|
||||
String replaceResult = replaceQuery.getSingleResult();
|
||||
assertEquals("abXXXefabXXXef", replaceResult);
|
||||
|
||||
// Test rpad function
|
||||
Query<String> rpadQuery = session.createQuery("select rpad('hi', 5, 'xy') from TestEntity", String.class);
|
||||
String rpadResult = rpadQuery.getSingleResult();
|
||||
assertEquals("hixyx", rpadResult);
|
||||
|
||||
// Test rtrim function
|
||||
Query<String> rtrimQuery = session.createQuery("select rtrim('trimxxxx', 'x') from TestEntity", String.class);
|
||||
String rtrimResult = rtrimQuery.getSingleResult();
|
||||
assertEquals("trim", rtrimResult);
|
||||
|
||||
// Test split_part function
|
||||
Query<String> splitPartQuery = session.createQuery("select split_part('abc~@~def~@~ghi', '~@~', 2) from TestEntity", String.class);
|
||||
String splitPartResult = splitPartQuery.getSingleResult();
|
||||
assertEquals("def", splitPartResult);
|
||||
|
||||
// Test strpos function
|
||||
Query<Integer> strposQuery = session.createQuery("select strpos('source', 'rc') from TestEntity", Integer.class);
|
||||
Integer strposResult = strposQuery.getSingleResult();
|
||||
assertEquals(4, strposResult.intValue());
|
||||
|
||||
// Test to_hex function
|
||||
Query<String> toHexQuery = session.createQuery("select to_hex(2147483647) from TestEntity", String.class);
|
||||
String toHexResult = toHexQuery.getSingleResult();
|
||||
assertEquals("7fffffff", toHexResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toCharTest() {
|
||||
Transaction transaction = session.beginTransaction();
|
||||
TestEntity testEntity = new TestEntity();
|
||||
testEntity.setValue(0.0);
|
||||
session.save(testEntity);
|
||||
transaction.commit();
|
||||
|
||||
Query<String> translateQuery = session.createQuery("select translate('12345', '143', 'ax') from TestEntity", String.class);
|
||||
String translateResult = translateQuery.getSingleResult();
|
||||
assertEquals("a2x5", translateResult);
|
||||
|
||||
Query<String> toCharQuery = session.createQuery("select to_char(current_timestamp, 'HH12:MI:SS') from TestEntity", String.class);
|
||||
String toCharResult = toCharQuery.getSingleResult();
|
||||
System.out.println(toCharResult);
|
||||
|
||||
toCharQuery = session.createNativeQuery(
|
||||
"SELECT to_char(interval '15h 2m 12s', 'HH24:MI:SS') AS formatted_value")
|
||||
.addScalar("formatted_value", StandardBasicTypes.STRING
|
||||
);
|
||||
toCharResult = toCharQuery.getSingleResult();
|
||||
assertEquals("15:02:12", toCharResult);
|
||||
|
||||
toCharQuery = session.createQuery("select to_char(125, '999') from TestEntity", String.class);
|
||||
toCharResult = toCharQuery.getSingleResult();
|
||||
assertEquals(" 125", toCharResult);
|
||||
|
||||
toCharQuery = session.createNativeQuery(
|
||||
"SELECT to_char(CAST(125.8 AS REAL), '999D99') AS formatted_value")
|
||||
.addScalar("formatted_value", StandardBasicTypes.STRING
|
||||
);
|
||||
toCharResult = toCharQuery.getSingleResult();
|
||||
assertEquals(" 125.80", toCharResult);
|
||||
|
||||
toCharQuery = session.createQuery("select to_char(-125.8, '999D99S') from TestEntity", String.class);
|
||||
toCharResult = toCharQuery.getSingleResult();
|
||||
assertEquals("125.80-", toCharResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toDateTest() {
|
||||
Transaction transaction = session.beginTransaction();
|
||||
TestEntity testEntity = new TestEntity();
|
||||
testEntity.setValue(0.0);
|
||||
session.save(testEntity);
|
||||
transaction.commit();
|
||||
|
||||
Query<Date> toTimestampQuery = session.createQuery("select to_timestamp('05 Dec 2000', 'DD Mon YYYY') from TestEntity", Date.class);
|
||||
Date result = toTimestampQuery.getSingleResult();
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toNumberTest() {
|
||||
Transaction transaction = session.beginTransaction();
|
||||
TestEntity testEntity = new TestEntity();
|
||||
testEntity.setValue(0.0);
|
||||
session.save(testEntity);
|
||||
transaction.commit();
|
||||
|
||||
Query<BigDecimal> toNumberQuery = session.createQuery(
|
||||
"select to_number('125.8', '999D99') from TestEntity", BigDecimal.class
|
||||
);
|
||||
BigDecimal toNumberResult = toNumberQuery.getSingleResult();
|
||||
assertEquals(new BigDecimal("125.8"), toNumberResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toTimeStampTest() {
|
||||
Transaction transaction = session.beginTransaction();
|
||||
TestEntity testEntity = new TestEntity();
|
||||
testEntity.setValue(0.0);
|
||||
session.save(testEntity);
|
||||
transaction.commit();
|
||||
Query<Date> toTimestampQuery = session.createQuery(
|
||||
"select to_timestamp('05 Dec 2000', 'DD Mon YYYY') from TestEntity", Date.class
|
||||
);
|
||||
Date toTimestampResult = toTimestampQuery.getSingleResult();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String expectedTimestamp = "2000-12-05 00:00:00";
|
||||
assertEquals(expectedTimestamp, sdf.format(toTimestampResult));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
package org.hibernate.dialect.unit;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.dialect.entity.datatype.*;
|
||||
import org.hibernate.dialect.pojo.Person;
|
||||
import org.hibernate.dialect.util.HibernateUtil;
|
||||
import org.hibernate.dialect.util.JDBCUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class OpenGaussTypeMappingTest {
|
||||
private static SessionFactory sessionFactory;
|
||||
|
||||
public static void formatColumns(List<String[]> columns) {
|
||||
int maxColumnLength = columns.stream().mapToInt(c -> c[0].length()).max().orElse(0);
|
||||
int maxTypeLength = columns.stream().mapToInt(c -> c[1].length()).max().orElse(0);
|
||||
for (String[] column : columns) {
|
||||
System.out.printf("Column %-" + maxColumnLength + "s : %" + maxTypeLength + "s%n", column[0], column[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ColumnFormatter(String tableName) {
|
||||
List<String[]> columns = null;
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sql = "SELECT * FROM " + tableName;
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
ResultSetMetaData rsmd = rs.getMetaData();
|
||||
columns = new ArrayList<>();
|
||||
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
|
||||
String columnName = rsmd.getColumnName(i);
|
||||
String columnType = rsmd.getColumnTypeName(i);
|
||||
columns.add(new String[]{columnName, columnType});
|
||||
}
|
||||
JDBCUtil.disconnect(conn);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
formatColumns(columns);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanMapping() {
|
||||
sessionFactory = HibernateUtil.getSessionFactory(BooleanEntity.class);
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumberMapping() {
|
||||
sessionFactory = HibernateUtil.getSessionFactory(NumberEntity.class);
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharMapping() {
|
||||
sessionFactory = HibernateUtil.getSessionFactory(CharEntity.class);
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringMapping() {
|
||||
sessionFactory = HibernateUtil.getSessionFactory(StringEntity.class);
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateTimeMapping() {
|
||||
sessionFactory = HibernateUtil.getSessionFactory(DateTimeEntity.class);
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBinaryMapping() {
|
||||
sessionFactory = HibernateUtil.getSessionFactory(BinaryEntity.class);
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLobMapping() {
|
||||
sessionFactory = HibernateUtil.getSessionFactory(LobEntity.class);
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertAndRetrieveJsonData() {
|
||||
sessionFactory = HibernateUtil.getSessionFactory(JsonEntity.class);
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
JsonEntity entity = new JsonEntity();
|
||||
entity.setId(1L);
|
||||
entity.setPojoJson(new Person(1, "opengauss"));
|
||||
entity.setPojoJsonb(new Person(2, "opengauss"));
|
||||
session.save(entity);
|
||||
session.getTransaction().commit();
|
||||
JsonEntity retrievedEntity = session.get(JsonEntity.class, entity.getId());
|
||||
System.out.println(retrievedEntity);
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportsNationalizedTypes() {
|
||||
sessionFactory = HibernateUtil.getSessionFactory(NationalizedEntity.class);
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.hibernate.dialect.util;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
public class HibernateUtil {
|
||||
public static SessionFactory getSessionFactory(Class<?>... classes) {
|
||||
Configuration configuration = new Configuration().configure();
|
||||
if (classes != null) {
|
||||
for (Class<?> c : classes) {
|
||||
configuration.addAnnotatedClass(c);
|
||||
}
|
||||
}
|
||||
return configuration.buildSessionFactory();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package org.hibernate.dialect.util;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class JDBCUtil {
|
||||
private static String DRIVER = "org.opengauss.Driver";
|
||||
private static String URL = "jdbc:opengauss://43.138.80.125:25432/osapp";
|
||||
private static String USER = "postgres";
|
||||
private static String PASSWORD = "osapp_openGauss@123";
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName(DRIVER);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() {
|
||||
Connection connect = null;
|
||||
try {
|
||||
connect = DriverManager.getConnection(URL, USER, PASSWORD);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return connect;
|
||||
}
|
||||
|
||||
public static void disconnect(Connection connection) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?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="hibernate.connection.driver_class">org.opengauss.Driver</property>
|
||||
<property name="hibernate.connection.url">jdbc:opengauss://43.138.80.125:25432/osapp</property>
|
||||
<property name="hibernate.connection.username">postgres</property>
|
||||
<property name="hibernate.connection.password">osapp_openGauss@123</property>
|
||||
<property name="hibernate.dialect">org.hibernate.dialect.OpenGaussDialect</property>
|
||||
<property name="hibernate.show_sql">true</property>
|
||||
<property name="hibernate.format_sql">true</property>
|
||||
<property name="hibernate.hbm2ddl.auto">create-drop</property>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
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.
Loading…
Reference in New Issue