提交 3f731712 编写于 作者: O o2null

Merge branch 'cherry-pick-1f092817' into 'wrdp'

Merge branch 'fix/gbase' into 'develop_java8'

See merge request o2oa/o2oa!4172
......@@ -13,6 +13,8 @@ import javax.persistence.Lob;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.collections4.ListUtils;
......@@ -144,53 +146,53 @@ public abstract class JpaObject extends GsonPropertyObject implements Serializab
this.sequence = sequence;
}
/* 暂存String */
@Column(length = length_255B, name = ColumnNamePrefix + scratchString_FIELDNAME)
private String scratchString;
/* 暂存Boolean */
@Column(name = ColumnNamePrefix + scratchBoolean_FIELDNAME)
private Boolean scratchBoolean;
/* 暂存Date */
@Column(name = ColumnNamePrefix + scratchDate_FIELDNAME)
private Date scratchDate;
/* 暂存Integer */
@Column(name = ColumnNamePrefix + scratchInteger_FIELDNAME)
private Date scratchInteger;
public String getScratchString() {
return scratchString;
}
public void setScratchString(String scratchString) {
this.scratchString = scratchString;
}
public Boolean getScratchBoolean() {
return scratchBoolean;
}
public void setScratchBoolean(Boolean scratchBoolean) {
this.scratchBoolean = scratchBoolean;
}
public Date getScratchDate() {
return scratchDate;
}
public void setScratchDate(Date scratchDate) {
this.scratchDate = scratchDate;
}
public Date getScratchInteger() {
return scratchInteger;
}
public void setScratchInteger(Date scratchInteger) {
this.scratchInteger = scratchInteger;
}
// /* 暂存String */
// @Column(length = length_255B, name = ColumnNamePrefix + scratchString_FIELDNAME)
// private String scratchString;
//
// /* 暂存Boolean */
// @Column(name = ColumnNamePrefix + scratchBoolean_FIELDNAME)
// private Boolean scratchBoolean;
//
// /* 暂存Date */
// @Column(name = ColumnNamePrefix + scratchDate_FIELDNAME)
// private Date scratchDate;
//
// /* 暂存Integer */
// @Column(name = ColumnNamePrefix + scratchInteger_FIELDNAME)
// private Date scratchInteger;
//
// public String getScratchString() {
// return scratchString;
// }
//
// public void setScratchString(String scratchString) {
// this.scratchString = scratchString;
// }
//
// public Boolean getScratchBoolean() {
// return scratchBoolean;
// }
//
// public void setScratchBoolean(Boolean scratchBoolean) {
// this.scratchBoolean = scratchBoolean;
// }
//
// public Date getScratchDate() {
// return scratchDate;
// }
//
// public void setScratchDate(Date scratchDate) {
// this.scratchDate = scratchDate;
// }
//
// public Date getScratchInteger() {
// return scratchInteger;
// }
//
// public void setScratchInteger(Date scratchInteger) {
// this.scratchInteger = scratchInteger;
// }
public static final int length_1B = 1;
......
......@@ -5,80 +5,53 @@ import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.Calendar;
import java.util.Date;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.openjpa.jdbc.identifier.DBIdentifier;
import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
import org.apache.openjpa.jdbc.schema.Column;
import org.apache.openjpa.jdbc.schema.ForeignKey;
import org.apache.openjpa.jdbc.schema.Index;
import org.apache.openjpa.jdbc.schema.PrimaryKey;
import org.apache.openjpa.jdbc.schema.Table;
import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.jdbc.sql.InformixDictionary;
import org.apache.openjpa.jdbc.sql.SQLBuffer;
import org.apache.openjpa.jdbc.sql.Select;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.util.StoreException;
import org.apache.openjpa.util.UnsupportedException;
public class GBaseDictionary extends DBDictionary {
public static final String VENDOR_OTHER = "gbase";
/**
* If true, then we will issue a "SET LOCK MODE TO WAIT N" statement whenever we
* create a {@link Connection}, in order allow waiting on locks.
*/
public boolean lockModeEnabled = false;
/**
* If {@link #lockModeEnabled} is <code>true</code>, then this parameter
* specifies the number of seconds we will wait to obtain a lock for inserts and
* pessimistic locking.
*/
public int lockWaitSeconds = 30;
/**
* Informix JDBC metadata for all known drivers returns with the table catalog
* and the table schema name swapped. A <code>true</code> value for this
* property indicates that they should be reversed.
*/
public boolean swapSchemaAndCatalog = true;
protected boolean useJCC = false;
public boolean disableRetainUpdateLocksSQL = false;
private static final Localizer _loc = Localizer.forPackage(InformixDictionary.class);
public GBaseDictionary() {
platform = "gbase";
platform = VENDOR_OTHER;
validationSQL = "SELECT 1 FROM DUAL";
supportsDeferredConstraints = false;
constraintNameMode = CONS_NAME_AFTER;
useGetStringForClobs = true;
longVarcharTypeName = "TEXT";
clobTypeName = "TEXT";
smallintTypeName = "INT8";
tinyintTypeName = "INT8";
longVarcharTypeName = "CLOB";
clobTypeName = "CLOB";
smallintTypeName = "INTEGER";
tinyintTypeName = "INTEGER";
floatTypeName = "FLOAT";
bitTypeName = "BOOLEAN";
blobTypeName = "BYTE";
doubleTypeName = "NUMERIC(32,20)";
dateTypeName = "DATE";
timeTypeName = "DATETIME HOUR TO SECOND";
timestampTypeName = "DATETIME YEAR TO FRACTION(3)";
timestampTypeName = "DATETIME YEAR TO FRACTION(5)";
doubleTypeName = "NUMERIC(32,20)";
floatTypeName = "REAL";
bigintTypeName = "NUMERIC(32,0)";
doubleTypeName = "DOUBLE PRECISION";
fixedSizeTypeNameSet.addAll(
Arrays.asList(new String[] { "BYTE", "DOUBLE PRECISION", "INTERVAL", "SMALLFLOAT", "TEXT", "INT8", }));
booleanTypeName = "BOOLEAN";
fixedSizeTypeNameSet.addAll(Arrays.asList(new String[] { "BIT", "DISTINCT", "JAVA_OBJECT", "NULL", "OTHER",
"REAL", "REF", "SMALLINT", "STRUCT", "TINYINT", }));
// OpenJPA-2045: NAME has been removed from common reserved words to
// only specific dictionaries
......@@ -113,6 +86,70 @@ public class GBaseDictionary extends DBDictionary {
trimSchemaName = true;
}
@Override
public void setDate(PreparedStatement stmnt, int idx, Date val, Column col) throws SQLException {
if (col != null && col.getType() == Types.DATE) {
if (null != val) {
val = DateUtils.setMilliseconds(val, 0);
val = DateUtils.setSeconds(val, 0);
val = DateUtils.setMinutes(val, 0);
val = DateUtils.setHours(val, 0);
}
setDate(stmnt, idx, new java.sql.Date(val.getTime()), null, col);
} else if (col != null && col.getType() == Types.TIME) {
if (null != val) {
val = DateUtils.setYears(val, 1970);
val = DateUtils.setMonths(val, 0);
val = DateUtils.setDays(val, 1);
}
setTime(stmnt, idx, new Time(val.getTime()), null, col);
} else if (val instanceof Timestamp) {
setTimestamp(stmnt, idx, (Timestamp) val, null, col);
} else {
setTimestamp(stmnt, idx, new Timestamp(val.getTime()), null, col);
}
}
@Override
public Date getDate(ResultSet rs, int column) throws SQLException {
Timestamp tstamp = getTimestamp(rs, column, null);
if (tstamp == null) {
return null;
}
long millis = (tstamp.getTime() / 1000L) * 1000L;
return new Date(millis);
}
@Override
public Time getTime(ResultSet rs, int column, Calendar cal) throws SQLException {
Time time = null;
if (cal == null) {
time = rs.getTime(column);
} else {
time = rs.getTime(column, cal);
}
if (null != time) {
Calendar calendar = DateUtils.toCalendar(time);
calendar.set(Calendar.YEAR, 1970);
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DATE, 1);
time = new Time(calendar.getTime().getTime());
}
return time;
}
/**
* Convert the specified column of the SQL ResultSet to the proper java type.
*/
@Override
public Timestamp getTimestamp(ResultSet rs, int column, Calendar cal) throws SQLException {
if (cal == null) {
return rs.getTimestamp(column);
} else {
return rs.getTimestamp(column, cal);
}
}
@Override
public Column[] getColumns(DatabaseMetaData meta, String catalog, String schemaName, String tableName,
String columnName, Connection conn) throws SQLException {
......@@ -156,13 +193,6 @@ public class GBaseDictionary extends DBDictionary {
return idx;
}
@Override
public void setBoolean(PreparedStatement stmnt, int idx, boolean val, Column col) throws SQLException {
// informix actually requires that a boolean be set: it cannot
// handle a numeric argument
stmnt.setString(idx, val ? "t" : "f");
}
@Override
public String[] getCreateTableSQL(Table table) {
String[] create = super.getCreateTableSQL(table);
......@@ -191,48 +221,6 @@ public class GBaseDictionary extends DBDictionary {
return !forUpdate && !sel.isLob() && super.supportsRandomAccessResultSet(sel, forUpdate);
}
@Override
public Connection decorate(Connection conn) throws SQLException {
conn = super.decorate(conn);
if (isJDBC3 && conn.getHoldability() != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
if (log.isTraceEnabled()) {
log.trace(_loc.get("connection-defaults",
new Object[] { conn.getAutoCommit(), conn.getHoldability(), conn.getTransactionIsolation() }));
}
}
// // if we haven't already done so, initialize the lock mode of the
// // connection
// if (_seenConnections.add(conn)) {
// if (lockModeEnabled) {
// String sql = "SET LOCK MODE TO WAIT";
// if (lockWaitSeconds > 0)
// sql = sql + " " + lockWaitSeconds;
// execute(sql, conn, true);
// }
//
// if (!disableRetainUpdateLocksSQL) {
// String sql = "SET ENVIRONMENT RETAINUPDATELOCKS 'ALL'";
// execute(sql, conn, false);
// }
// }
// the datadirect driver requires that we issue a rollback before using
// each connection
if (VENDOR_DATADIRECT.equalsIgnoreCase(driverVendor))
try {
conn.rollback();
} catch (SQLException se) {
}
return conn;
}
@Override
public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find, FilterValue start) {
throw new UnsupportedException(_loc.get("function-not-supported", getClass(), "LOCATE"));
}
@Override
public boolean needsToCreateIndex(Index idx, Table table) {
// Informix will automatically create a unique index for the
......@@ -243,70 +231,4 @@ public class GBaseDictionary extends DBDictionary {
return true;
}
public boolean useJCC() {
return useJCC;
}
/**
* Return DB specific schemaCase
*/
@Override
public String getSchemaCase() {
return schemaCase;
}
/**
* Specialized matchErrorState method for Informix. Informix exceptions are
* typically nested multiple levels deep. Correct determination of the exception
* type requires inspection of nested exceptions to determine the root cause. A
* list of Informix (IDS v10) error codes can be found here:
*
* http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.em.doc/errors_ids100.html
*
* @param errorStates classification of SQL error states by their specific
* nature. The keys of the map represent one of the constants
* defined in {@link StoreException}. The value corresponding
* to a key represent the set of SQL Error States
* representing specific category of database error. This
* supplied map is sourced from
* <code>sql-error-state-codes.xml</xml> and filtered the
* error states for the current database.
*
* @param ex original SQL Exception as raised by the database driver.
*
* @return A constant indicating the category of error as defined in
* {@link StoreException}.
*/
@Override
protected int matchErrorState(Map<Integer, Set<String>> errorStates, SQLException ex) {
// Informix SQLState IX000 is a general SQLState that applies to many possible
// conditions
// If the underlying cause is also an IX000 with error code:
// -107 ISAM error: record is locked. || -154 ISAM error: Lock Timeout Expired.
// the exception type is LOCK.
if (checkNestedErrorCodes(ex, "IX000", -107, -154)) {
return StoreException.LOCK;
}
return super.matchErrorState(errorStates, ex);
}
private boolean checkNestedErrorCodes(SQLException ex, String sqlState, int... errorCodes) {
SQLException cause = ex;
int level = 0;
// Query at most 5 exceptions deep to prevent infinite iteration exception loops
// Typically, the root exception is at level 3.
while (cause != null && level < 5) {
String errorState = cause.getSQLState();
if (sqlState == null || sqlState.equals(errorState)) {
for (int ec : errorCodes) {
if (cause.getErrorCode() == ec) {
return true;
}
}
}
cause = cause.getNextException();
level++;
}
return false;
}
}
......@@ -3,13 +3,17 @@ package com.x.program.center.jaxrs.validation;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.StringTools;
......@@ -17,52 +21,366 @@ import com.x.program.center.core.entity.validation.Meta;
class ActionMeta extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
String id = StringTools.uniqueToken();
Meta meta = new Meta();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
meta.setId(id);
assignmentStringValue(meta);
assignmentStringLobValue(meta);
assignmentBooleanValue(meta);
assignmentDateTimeValue(meta);
assignmentDateValue(meta);
assignmentTimeValue(meta);
assignmentIntegerValue(meta);
assignmentLongValue(meta);
assignmentFloatValue(meta);
assignmentDoubleValue(meta);
assignmentListValue(meta);
assignmentMapValue(meta);
assignmentProperties(meta);
emc.beginTransaction(Meta.class);
for (Meta o : emc.listAll(Meta.class)) {
emc.remove(o);
}
emc.commit();
emc.beginTransaction(Meta.class);
Meta meta = new Meta();
meta.setStringValue(StringTools.uniqueToken());
meta.setBooleanValue(true);
meta.setDateTimeValue(new Date());
meta.setDateValue(new Date());
meta.setTimeValue(new Date());
meta.setIntegerValue(123456789);
meta.setLongValue(123456789L);
meta.setDoubleValue(1233456789.987654321d);
meta.setListValueList(new ArrayList<>());
meta.getListValueList().add("AAA");
meta.getListValueList().add("BBB");
meta.getListValueList().add("CCC");
meta.setMapValueMap(new LinkedHashMap<String, String>());
meta.getMapValueMap().put("key1", "value1");
meta.getMapValueMap().put("key2", "true");
meta.getMapValueMap().put("key3", "12.34");
StringBuffer largeString = new StringBuffer();
for (int i = 0; i < 100; i++) {
largeString.append(i + ":测试测试测试,");
}
meta.setStringLobValue(largeString.toString());
emc.persist(meta, CheckPersistType.all);
emc.commit();
emc.flush();
meta = emc.find(meta.getId(), Meta.class);
result.setData(Wo.copier.copy(meta));
return result;
}
Wo wo = new Wo();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Meta o = emc.find(id, Meta.class);
wo.setAssertStringValue(assertStringValue(o, meta));
wo.setAssertStringLobValue(assertStringLobValue(o, meta));
wo.setAssertBooleanValue(assertBooleanValue(o, meta));
wo.setAssertDateTimeValue(assertDateTimeValue(o, meta));
wo.setAssertDateValue(assertDateValue(o, meta));
wo.setAssertTimeValue(assertTimeValue(o, meta));
wo.setAssertIntegerValue(assertIntegerValue(o, meta));
wo.setAssertLongValue(assertLongValue(o, meta));
wo.setAssertFloatValue(assertFloatValue(o, meta));
wo.setAssertDoubleValue(assertDoubleValue(o, meta));
wo.setAssertListValue(assertListValue(o, meta));
wo.setAssertMapValue(assertMapValue(o, meta));
wo.setAssertProperties(assertProperties(o, meta));
}
ActionResult<Wo> result = new ActionResult<>();
result.setData(wo);
return result;
}
public static class Wo extends Meta {
public static class Wo extends GsonPropertyObject {
private static final long serialVersionUID = -4468460971064420534L;
static WrapCopier<Meta, Wo> copier = WrapCopierFactory.wo(Meta.class, Wo.class, null,
JpaObject.FieldsInvisible);
private String assertStringValue;
private String assertStringLobValue;
private String assertBooleanValue;
private String assertDateTimeValue;
private String assertDateValue;
private String assertTimeValue;
private String assertIntegerValue;
private String assertLongValue;
private String assertFloatValue;
private String assertDoubleValue;
private String assertListValue;
private String assertMapValue;
private String assertProperties;
public String getAssertStringValue() {
return assertStringValue;
}
public void setAssertStringValue(String assertStringValue) {
this.assertStringValue = assertStringValue;
}
public String getAssertStringLobValue() {
return assertStringLobValue;
}
public void setAssertStringLobValue(String assertStringLobValue) {
this.assertStringLobValue = assertStringLobValue;
}
public String getAssertBooleanValue() {
return assertBooleanValue;
}
public void setAssertBooleanValue(String assertBooleanValue) {
this.assertBooleanValue = assertBooleanValue;
}
public String getAssertDateTimeValue() {
return assertDateTimeValue;
}
public void setAssertDateTimeValue(String assertDateTimeValue) {
this.assertDateTimeValue = assertDateTimeValue;
}
public String getAssertDateValue() {
return assertDateValue;
}
public void setAssertDateValue(String assertDateValue) {
this.assertDateValue = assertDateValue;
}
public String getAssertTimeValue() {
return assertTimeValue;
}
public void setAssertTimeValue(String assertTimeValue) {
this.assertTimeValue = assertTimeValue;
}
public String getAssertIntegerValue() {
return assertIntegerValue;
}
public void setAssertIntegerValue(String assertIntegerValue) {
this.assertIntegerValue = assertIntegerValue;
}
public String getAssertLongValue() {
return assertLongValue;
}
public void setAssertLongValue(String assertLongValue) {
this.assertLongValue = assertLongValue;
}
public String getAssertFloatValue() {
return assertFloatValue;
}
public void setAssertFloatValue(String assertFloatValue) {
this.assertFloatValue = assertFloatValue;
}
public String getAssertDoubleValue() {
return assertDoubleValue;
}
public void setAssertDoubleValue(String assertDoubleValue) {
this.assertDoubleValue = assertDoubleValue;
}
public String getAssertListValue() {
return assertListValue;
}
public void setAssertListValue(String assertListValue) {
this.assertListValue = assertListValue;
}
public String getAssertMapValue() {
return assertMapValue;
}
public void setAssertMapValue(String assertMapValue) {
this.assertMapValue = assertMapValue;
}
public String getAssertProperties() {
return assertProperties;
}
public void setAssertProperties(String assertProperties) {
this.assertProperties = assertProperties;
}
}
private static void assignmentStringValue(Meta persistObject) {
persistObject.setStringValue("123456789");
}
private static void assignmentStringLobValue(Meta persistObject) {
persistObject.setStringLobValue(StringUtils.repeat("123456789", 40));
}
private static void assignmentBooleanValue(Meta persistObject) {
persistObject.setBooleanValue(true);
}
private static void assignmentDateTimeValue(Meta persistObject) {
persistObject.setDateTimeValue(new Date());
}
private static void assignmentDateValue(Meta persistObject) {
persistObject.setDateValue(new Date());
}
private static void assignmentTimeValue(Meta persistObject) {
persistObject.setTimeValue(new Date());
}
private static void assignmentIntegerValue(Meta persistObject) {
persistObject.setIntegerValue(123456789);
}
private static void assignmentLongValue(Meta persistObject) {
persistObject.setLongValue(Integer.MAX_VALUE * 10L);
}
private static void assignmentFloatValue(Meta persistObject) {
persistObject.setFloatValue(12345.6789);
}
private static void assignmentDoubleValue(Meta persistObject) {
persistObject.setDoubleValue(12345.6789);
}
private static void assignmentListValue(Meta persistObject) {
List<String> list = new ArrayList<>();
list.add("aaaa");
list.add("bbbb");
list.add("cccc");
list.add("dddd");
persistObject.setListValueList(list);
}
private static void assignmentMapValue(Meta persistObject) {
LinkedHashMap<String, String> map = new LinkedHashMap<>();
map.put("1", "aaaa");
map.put("2", "bbbb");
map.put("3", "cccc");
map.put("4", "dddd");
persistObject.setMapValueMap(map);
}
private static void assignmentProperties(Meta persistObject) {
persistObject.getProperties().setName("aaaa");
persistObject.getProperties().setConut(1);
}
private String assertStringValue(Meta fromDbObject, Meta persistObject) {
String message = "stringValue %s formDbObject:%s, persistObject:%s.";
message = String.format(message,
StringUtils.equals(fromDbObject.getStringValue(), persistObject.getStringValue()),
fromDbObject.getStringValue(), persistObject.getStringValue());
return message;
}
private String assertStringLobValue(Meta fromDbObject, Meta persistObject) {
String message = "stringLobValue %s formDbObject:%s, persistObject:%s.";
message = String.format(message,
StringUtils.equals(fromDbObject.getStringLobValue(), persistObject.getStringLobValue()),
fromDbObject.getStringLobValue(), persistObject.getStringLobValue());
return message;
}
private String assertBooleanValue(Meta fromDbObject, Meta persistObject) {
String message = "booleanValue %s formDbObject:%s, persistObject:%s.";
message = String.format(message,
Objects.equals(fromDbObject.getBooleanValue(), persistObject.getBooleanValue()),
fromDbObject.getBooleanValue(), persistObject.getBooleanValue());
return message;
}
private String assertDateTimeValue(Meta fromDbObject, Meta persistObject) {
String message = "dateTimeValue %s formDbObject:%s, persistObject:%s.";
message = String.format(message,
Objects.equals(fromDbObject.getDateTimeValue().getTime(), persistObject.getDateTimeValue().getTime()),
fromDbObject.getDateTimeValue(), persistObject.getDateTimeValue());
return message;
}
private String assertDateValue(Meta fromDbObject, Meta persistObject) {
String message = "dateValue %s formDbObject:%s, persistObject:%s.";
message = String.format(message,
Objects.equals(fromDbObject.getDateValue().getTime(), persistObject.getDateValue().getTime()),
fromDbObject.getDateValue(), persistObject.getDateValue());
return message;
}
private String assertTimeValue(Meta fromDbObject, Meta persistObject) {
String message = "timeValue %s formDbObject:%s, persistObject:%s.";
message = String.format(message,
Objects.equals(fromDbObject.getTimeValue().getTime(), persistObject.getTimeValue().getTime()),
fromDbObject.getTimeValue(), persistObject.getTimeValue());
return message;
}
private String assertIntegerValue(Meta fromDbObject, Meta persistObject) {
String message = "integerValue %s formDbObject:%s, persistObject:%s.";
message = String.format(message,
Objects.equals(fromDbObject.getIntegerValue(), persistObject.getIntegerValue()),
fromDbObject.getIntegerValue(), persistObject.getIntegerValue());
return message;
}
private String assertLongValue(Meta fromDbObject, Meta persistObject) {
String message = "longValue %s formDbObject:%s, persistObject:%s.";
message = String.format(message, Objects.equals(fromDbObject.getLongValue(), persistObject.getLongValue()),
fromDbObject.getLongValue(), persistObject.getLongValue());
return message;
}
private String assertFloatValue(Meta fromDbObject, Meta persistObject) {
String message = "floatValue %s formDbObject:%s, persistObject:%s.";
message = String.format(message, Objects.equals(fromDbObject.getFloatValue(), persistObject.getFloatValue()),
fromDbObject.getFloatValue(), persistObject.getFloatValue());
return message;
}
private String assertDoubleValue(Meta fromDbObject, Meta persistObject) {
String message = "doubleValue %s formDbObject:%s, persistObject:%s.";
message = String.format(message, Objects.equals(fromDbObject.getDoubleValue(), persistObject.getDoubleValue()),
fromDbObject.getDoubleValue(), persistObject.getDoubleValue());
return message;
}
private String assertListValue(Meta fromDbObject, Meta persistObject) {
String message = "listValue %s formDbObject:%s, persistObject:%s.";
boolean check = true;
for (int i = 0; i < fromDbObject.getListValueList().size(); i++) {
if (!StringUtils.equals(fromDbObject.getListValueList().get(i), persistObject.getListValueList().get(i))) {
check = false;
}
}
for (int i = 0; i < persistObject.getListValueList().size(); i++) {
if (!StringUtils.equals(persistObject.getListValueList().get(i), fromDbObject.getListValueList().get(i))) {
check = false;
}
}
message = String.format(message, check, XGsonBuilder.toJson(fromDbObject.getListValueList()),
XGsonBuilder.toJson(persistObject.getListValueList()));
return message;
}
private String assertMapValue(Meta fromDbObject, Meta persistObject) {
String message = "mapValue %s formDbObject:%s, persistObject:%s.";
boolean check = true;
for (Entry<String, String> en : fromDbObject.getMapValueMap().entrySet()) {
if (!StringUtils.equals(en.getValue(), persistObject.getMapValueMap().get(en.getKey()))) {
check = false;
}
}
for (Entry<String, String> en : persistObject.getMapValueMap().entrySet()) {
if (!StringUtils.equals(en.getValue(), fromDbObject.getMapValueMap().get(en.getKey()))) {
check = false;
}
}
message = String.format(message, check, XGsonBuilder.toJson(fromDbObject.getMapValueMap()),
XGsonBuilder.toJson(persistObject.getMapValueMap()));
return message;
}
private String assertProperties(Meta fromDbObject, Meta persistObject) {
String message = "properties %s formDbObject:%s, persistObject:%s.";
message = String.format(message, Objects.equals(fromDbObject.getProperties(), persistObject.getProperties()),
fromDbObject.getProperties(), persistObject.getProperties());
return message;
}
}
......@@ -76,13 +76,13 @@ public final class PersistenceProperties extends AbstractPersistenceProperties {
public static final String table = "CTE_INSTALL_LOG";
}
public static class MPWeixinMenu {
public static final String table = "CTE_MP_WEIXIN_MENU";
}
public static class Validation {
public static class Meta {
public static final String table = "VAL_META";
public static final String table = "CTE_VAL_META";
}
}
public static class MPWeixinMenu {
public static final String table = "CTE_MP_WEIXIN_MENU";
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import org.apache.openjpa.persistence.Persistent;
import org.apache.openjpa.persistence.PersistentCollection;
import org.apache.openjpa.persistence.PersistentMap;
import org.apache.openjpa.persistence.jdbc.ContainerTable;
......@@ -26,8 +27,8 @@ import org.apache.openjpa.persistence.jdbc.ElementIndex;
import org.apache.openjpa.persistence.jdbc.Index;
import org.apache.openjpa.persistence.jdbc.KeyColumn;
import org.apache.openjpa.persistence.jdbc.KeyIndex;
import org.apache.openjpa.persistence.jdbc.Strategy;
import com.x.base.core.entity.AbstractPersistenceProperties;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.SliceJpaObject;
import com.x.base.core.entity.annotation.CheckPersist;
......@@ -69,12 +70,19 @@ public class Meta extends SliceJpaObject {
@Column(length = length_id, name = ColumnNamePrefix + id_FIELDNAME)
private String id = createId();
/* 以上为 JpaObject 默认字段 */
public void onPersist() throws Exception {
}
/* 更新运行方法 */
public MetaProperties getProperties() {
if (null == this.properties) {
this.properties = new MetaProperties();
}
return this.properties;
}
public void setProperties(MetaProperties properties) {
this.properties = properties;
}
public static final String stringValue_FIELDNAME = "stringValue";
@FieldDescribe("文本字段.")
......@@ -135,6 +143,13 @@ public class Meta extends SliceJpaObject {
@Column(name = ColumnNamePrefix + longValue_FIELDNAME)
private Long longValue;
public static final String floatValue_FIELDNAME = "floatValue";
@FieldDescribe("浮点数.")
@CheckPersist(allowEmpty = true)
@Index(name = TABLE + IndexNameMiddle + floatValue_FIELDNAME)
@Column(name = ColumnNamePrefix + floatValue_FIELDNAME)
private Double floatValue;
public static final String doubleValue_FIELDNAME = "doubleValue";
@FieldDescribe("双精度浮点数.")
@CheckPersist(allowEmpty = true)
......@@ -165,6 +180,14 @@ public class Meta extends SliceJpaObject {
@KeyIndex(name = TABLE + IndexNameMiddle + mapValueMap_FIELDNAME + KeyIndexNameSuffix)
private LinkedHashMap<String, String> mapValueMap;
public static final String properties_FIELDNAME = "properties";
@FieldDescribe("属性对象存储字段.")
@Persistent
@Strategy(JsonPropertiesValueHandler)
@Column(length = JpaObject.length_10M, name = ColumnNamePrefix + properties_FIELDNAME)
@CheckPersist(allowEmpty = true)
private MetaProperties properties;
public String getStringValue() {
return stringValue;
}
......@@ -173,6 +196,14 @@ public class Meta extends SliceJpaObject {
this.stringValue = stringValue;
}
public String getStringLobValue() {
return stringLobValue;
}
public void setStringLobValue(String stringLobValue) {
this.stringLobValue = stringLobValue;
}
public Boolean getBooleanValue() {
return booleanValue;
}
......@@ -221,6 +252,14 @@ public class Meta extends SliceJpaObject {
this.longValue = longValue;
}
public Double getFloatValue() {
return floatValue;
}
public void setFloatValue(Double floatValue) {
this.floatValue = floatValue;
}
public List<String> getListValueList() {
return listValueList;
}
......@@ -241,14 +280,6 @@ public class Meta extends SliceJpaObject {
this.doubleValue = doubleValue;
}
public String getStringLobValue() {
return stringLobValue;
}
public void setStringLobValue(String stringLobValue) {
this.stringLobValue = stringLobValue;
}
public LinkedHashMap<String, String> getMapValueMap() {
return mapValueMap;
}
......
package com.x.program.center.core.entity.validation;
import com.x.base.core.entity.JsonProperties;
public class MetaProperties extends JsonProperties {
private static final long serialVersionUID = 3619957195494464187L;
private String name;
private Integer conut;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getConut() {
return conut;
}
public void setConut(Integer conut) {
this.conut = conut;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((conut == null) ? 0 : conut.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
MetaProperties other = (MetaProperties) obj;
if (conut == null) {
if (other.conut != null)
return false;
} else if (!conut.equals(other.conut))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册