[ 1817614 ] Remove not functional sqlj function.
- deprecate instead of remove to preserve backward compatibility - fix some minor bug [ 1817558 ] Function NextId not implemented for PostgreSQL
This commit is contained in:
parent
7976195d15
commit
c98124c138
|
@ -1,6 +1,5 @@
|
||||||
SQLActions[ ] = {
|
SQLActions[ ] = {
|
||||||
"BEGIN INSTALL
|
"BEGIN INSTALL
|
||||||
--CREATE SCHEMA fun;
|
|
||||||
BEGIN PostgreSQL SET search_path TO adempiere END PostgreSQL;
|
BEGIN PostgreSQL SET search_path TO adempiere END PostgreSQL;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION adempiereVersion()
|
CREATE OR REPLACE FUNCTION adempiereVersion()
|
||||||
|
@ -18,36 +17,6 @@ SQLActions[ ] = {
|
||||||
AS 'org.compiere.sqlj.Adempiere.getProperty(java.lang.String)'
|
AS 'org.compiere.sqlj.Adempiere.getProperty(java.lang.String)'
|
||||||
LANGUAGE java VOLATILE;;
|
LANGUAGE java VOLATILE;;
|
||||||
|
|
||||||
--Replace by pl/pgsql implementation
|
|
||||||
--CREATE OR REPLACE FUNCTION TRUNC(datetime TIMESTAMP WITH TIME ZONE)
|
|
||||||
--RETURNS TIMESTAMP WITH TIME ZONE
|
|
||||||
--AS 'org.compiere.sqlj.Adempiere.trunc(java.sql.Timestamp)'
|
|
||||||
--LANGUAGE java VOLATILE;;
|
|
||||||
|
|
||||||
--Replace by pl/pgsql implementation
|
|
||||||
--CREATE OR REPLACE FUNCTION firstOf(datetime TIMESTAMP WITH TIME ZONE ,xx VARCHAR)
|
|
||||||
--RETURNS TIMESTAMP WITH TIME ZONE
|
|
||||||
--AS 'org.compiere.sqlj.Adempiere.firstOf(java.sql.Timestamp,java.lang.String)'
|
|
||||||
--LANGUAGE java VOLATILE;;
|
|
||||||
|
|
||||||
--Replace by pl/pgsql implementation
|
|
||||||
--CREATE OR REPLACE FUNCTION daysBetween(datetime1 TIMESTAMP WITH TIME ZONE , datetime2 TIMESTAMP WITH TIME ZONE)
|
|
||||||
--RETURNS INTEGER
|
|
||||||
--AS 'org.compiere.sqlj.Adempiere.getDaysBetween(java.sql.Timestamp,java.sql.Timestamp)'
|
|
||||||
--LANGUAGE java VOLATILE;;
|
|
||||||
|
|
||||||
--Replace by pl/pgsql implementation
|
|
||||||
--CREATE OR REPLACE FUNCTION addDays(day TIMESTAMP WITH TIME ZONE, days INTEGER)
|
|
||||||
--RETURNS TIMESTAMP WITH TIME ZONE
|
|
||||||
--AS 'org.compiere.sqlj.Adempiere.addDays(java.sql.Timestamp,int)'
|
|
||||||
--LANGUAGE java VOLATILE;;
|
|
||||||
|
|
||||||
--Replace by pl/pgsql implementation
|
|
||||||
--CREATE OR REPLACE FUNCTION charAt(source VARCHAR, pos INTEGER)
|
|
||||||
--RETURNS VARCHAR
|
|
||||||
--AS 'org.compiere.sqlj.Adempiere.charAt (java.lang.String,int)'
|
|
||||||
--LANGUAGE java VOLATILE;;
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION nextID(AD_Sequence_ID INTEGER, System VARCHAR)
|
CREATE OR REPLACE FUNCTION nextID(AD_Sequence_ID INTEGER, System VARCHAR)
|
||||||
RETURNS INTEGER
|
RETURNS INTEGER
|
||||||
AS 'org.compiere.sqlj.Adempiere.nextID(int,java.lang.String)'
|
AS 'org.compiere.sqlj.Adempiere.nextID(int,java.lang.String)'
|
||||||
|
@ -206,15 +175,9 @@ SQLActions[ ] = {
|
||||||
END INSTALL",
|
END INSTALL",
|
||||||
|
|
||||||
"BEGIN REMOVE
|
"BEGIN REMOVE
|
||||||
--DROP SCHEMA fun CASCADE;
|
|
||||||
--DROP FUNCTION adempiereVersion();
|
--DROP FUNCTION adempiereVersion();
|
||||||
--DROP FUNCTION adempiereProperties();
|
--DROP FUNCTION adempiereProperties();
|
||||||
--DROP FUNCTION adempiereProperty(p_key VARCHAR);
|
--DROP FUNCTION adempiereProperty(p_key VARCHAR);
|
||||||
--DROP FUNCTION TRUNC(datetime TIMESTAMP WITH TIME ZONE);
|
|
||||||
--DROP FUNCTION firstOf(datetime TIMESTAMP WITH TIME ZONE ,xx VARCHAR);
|
|
||||||
--DROP FUNCTION daysBetween(datetime1 TIMESTAMP WITH TIME ZONE , datetime2 TIMESTAMP WITH TIME ZONE);
|
|
||||||
--DROP FUNCTION addDays(day TIMESTAMP WITH TIME ZONE, days INTEGER);
|
|
||||||
--DROP FUNCTION charAt(source VARCHAR, pos NUMERIC);
|
|
||||||
--DROP FUNCTION productAttribute (M_AttributeSetInstance_ID INTEGER);
|
--DROP FUNCTION productAttribute (M_AttributeSetInstance_ID INTEGER);
|
||||||
--DROP FUNCTION bomPriceLimit (M_Product_ID INTEGER, M_PriceList_Version_ID INTEGER);
|
--DROP FUNCTION bomPriceLimit (M_Product_ID INTEGER, M_PriceList_Version_ID INTEGER);
|
||||||
--DROP FUNCTION bomPriceList (M_Product_ID INTEGER, M_PriceList_Version_ID INTEGER);
|
--DROP FUNCTION bomPriceList (M_Product_ID INTEGER, M_PriceList_Version_ID INTEGER);
|
||||||
|
|
|
@ -86,11 +86,14 @@ public class Adempiere implements Serializable
|
||||||
{
|
{
|
||||||
if (s_type == null)
|
if (s_type == null)
|
||||||
{
|
{
|
||||||
String vendor = System.getProperty("java.vendor");
|
s_type = "??";
|
||||||
if (vendor.startsWith("Oracle"))
|
try {
|
||||||
s_type = TYPE_ORACLE;
|
String name = getConnection().getClass().getName();
|
||||||
else
|
if (name.indexOf("oracle") >= 0)
|
||||||
s_type = "??";
|
s_type = TYPE_ORACLE;
|
||||||
|
else if (name.indexOf("postgresql") >= 0)
|
||||||
|
s_type = TYPE_POSTGRESQL;
|
||||||
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
return s_type;
|
return s_type;
|
||||||
} // getServerType
|
} // getServerType
|
||||||
|
@ -122,13 +125,6 @@ public class Adempiere implements Serializable
|
||||||
return TYPE_POSTGRESQL.equals(s_type);
|
return TYPE_POSTGRESQL.equals(s_type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// isEDB
|
|
||||||
static boolean isEDB()
|
|
||||||
{
|
|
||||||
if (s_type == null)
|
|
||||||
getServerType();
|
|
||||||
return false;
|
|
||||||
} // isEDB
|
|
||||||
//end vpj-cd e-evolution 02/22/2005 PostgreSQL
|
//end vpj-cd e-evolution 02/22/2005 PostgreSQL
|
||||||
|
|
||||||
|
|
||||||
|
@ -236,9 +232,9 @@ public class Adempiere implements Serializable
|
||||||
/** Hundred 100 */
|
/** Hundred 100 */
|
||||||
public static final BigDecimal HUNDRED = new BigDecimal((double)100.0);
|
public static final BigDecimal HUNDRED = new BigDecimal((double)100.0);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Truncate Date
|
* Truncate Date
|
||||||
|
* @deprecated
|
||||||
* @param p_dateTime date
|
* @param p_dateTime date
|
||||||
* @return day
|
* @return day
|
||||||
*/
|
*/
|
||||||
|
@ -249,18 +245,18 @@ public class Adempiere implements Serializable
|
||||||
time = new Timestamp(System.currentTimeMillis());
|
time = new Timestamp(System.currentTimeMillis());
|
||||||
//
|
//
|
||||||
GregorianCalendar cal = new GregorianCalendar();
|
GregorianCalendar cal = new GregorianCalendar();
|
||||||
cal.setTime(time);
|
cal.setTimeInMillis(time.getTime());
|
||||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
cal.set(Calendar.MINUTE, 0);
|
cal.set(Calendar.MINUTE, 0);
|
||||||
cal.set(Calendar.SECOND, 0);
|
cal.set(Calendar.SECOND, 0);
|
||||||
cal.set(Calendar.MILLISECOND, 0);
|
cal.set(Calendar.MILLISECOND, 0);
|
||||||
//
|
//
|
||||||
java.util.Date temp = cal.getTime();
|
return new Timestamp (cal.getTimeInMillis());
|
||||||
return new Timestamp (temp.getTime());
|
|
||||||
} // trunc
|
} // trunc
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Truncate Date
|
* Truncate Date
|
||||||
|
* @deprecated
|
||||||
* @param p_dateTime date
|
* @param p_dateTime date
|
||||||
* @param XX date part - Supported: DD(default),DY,MM,Q
|
* @param XX date part - Supported: DD(default),DY,MM,Q
|
||||||
* @return day (first)
|
* @return day (first)
|
||||||
|
@ -295,13 +291,13 @@ public class Adempiere implements Serializable
|
||||||
else
|
else
|
||||||
cal.set(Calendar.MONTH, Calendar.OCTOBER);
|
cal.set(Calendar.MONTH, Calendar.OCTOBER);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
java.util.Date temp = cal.getTime();
|
return new Timestamp (cal.getTimeInMillis());
|
||||||
return new Timestamp (temp.getTime());
|
|
||||||
} // trunc
|
} // trunc
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the number of days between start and end.
|
* Calculate the number of days between start and end.
|
||||||
|
* @deprecated
|
||||||
* @param start start date
|
* @param start start date
|
||||||
* @param end end date
|
* @param end end date
|
||||||
* @return number of days (0 = same)
|
* @return number of days (0 = same)
|
||||||
|
@ -333,8 +329,6 @@ public class Adempiere implements Serializable
|
||||||
calEnd.set(Calendar.SECOND, 0);
|
calEnd.set(Calendar.SECOND, 0);
|
||||||
calEnd.set(Calendar.MILLISECOND, 0);
|
calEnd.set(Calendar.MILLISECOND, 0);
|
||||||
|
|
||||||
// System.out.println("Start=" + start + ", End=" + end + ", dayStart=" + cal.get(Calendar.DAY_OF_YEAR) + ", dayEnd=" + calEnd.get(Calendar.DAY_OF_YEAR));
|
|
||||||
|
|
||||||
// in same year
|
// in same year
|
||||||
if (cal.get(Calendar.YEAR) == calEnd.get(Calendar.YEAR))
|
if (cal.get(Calendar.YEAR) == calEnd.get(Calendar.YEAR))
|
||||||
{
|
{
|
||||||
|
@ -345,11 +339,14 @@ public class Adempiere implements Serializable
|
||||||
|
|
||||||
// not very efficient, but correct
|
// not very efficient, but correct
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
while (calEnd.after(cal))
|
while (cal.get(Calendar.YEAR) < calEnd.get(Calendar.YEAR))
|
||||||
{
|
{
|
||||||
cal.add (Calendar.DAY_OF_YEAR, 1);
|
GregorianCalendar yearEnd = new GregorianCalendar(cal.get(Calendar.YEAR), 12, 31, 0, 0, 0);
|
||||||
counter++;
|
int days = getDaysBetween(new Timestamp(cal.getTimeInMillis()), new Timestamp(yearEnd.getTimeInMillis()));
|
||||||
|
cal.add (Calendar.DAY_OF_YEAR, days + 1);
|
||||||
|
counter = counter + days + 1;
|
||||||
}
|
}
|
||||||
|
counter = counter + getDaysBetween(new Timestamp(cal.getTimeInMillis()), new Timestamp(calEnd.getTimeInMillis()));
|
||||||
if (negative)
|
if (negative)
|
||||||
return counter * -1;
|
return counter * -1;
|
||||||
return counter;
|
return counter;
|
||||||
|
@ -357,6 +354,7 @@ public class Adempiere implements Serializable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Day + offset (truncates)
|
* Return Day + offset (truncates)
|
||||||
|
* @deprecated
|
||||||
* @param day Day
|
* @param day Day
|
||||||
* @param offset day offset
|
* @param offset day offset
|
||||||
* @return Day + offset at 00:00
|
* @return Day + offset at 00:00
|
||||||
|
@ -375,10 +373,10 @@ public class Adempiere implements Serializable
|
||||||
if (offset != 0)
|
if (offset != 0)
|
||||||
cal.add(Calendar.DAY_OF_YEAR, offset); // may have a problem with negative (before 1/1)
|
cal.add(Calendar.DAY_OF_YEAR, offset); // may have a problem with negative (before 1/1)
|
||||||
//
|
//
|
||||||
java.util.Date temp = cal.getTime();
|
return new Timestamp (cal.getTimeInMillis());
|
||||||
return new Timestamp (temp.getTime());
|
|
||||||
} // addDays
|
} // addDays
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Next Business Day.
|
* Next Business Day.
|
||||||
* (Only Sa/Su -> Mo)
|
* (Only Sa/Su -> Mo)
|
||||||
|
@ -423,25 +421,26 @@ public class Adempiere implements Serializable
|
||||||
}
|
}
|
||||||
while (isHoliday);
|
while (isHoliday);
|
||||||
// end Goodwill
|
// end Goodwill
|
||||||
//
|
|
||||||
java.util.Date temp = cal.getTime();
|
return new Timestamp (cal.getTimeInMillis());
|
||||||
return new Timestamp (temp.getTime());
|
|
||||||
} // nextBusinessDay
|
} // nextBusinessDay
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Character At Position
|
* Character At Position
|
||||||
|
* @deprecated
|
||||||
* @param source source
|
* @param source source
|
||||||
* @param posIndex position 1 = first
|
* @param posIndex position 1 = first
|
||||||
* @return substring or null
|
* @return substring or null
|
||||||
*/
|
*/
|
||||||
public static String charAt (String source, int posIndex)
|
public static String charAt (String source, int posIndex)
|
||||||
{
|
{
|
||||||
|
posIndex = posIndex - 1;
|
||||||
if (source == null || source.length() == 0 || posIndex < 0 || posIndex >= source.length())
|
if (source == null || source.length() == 0 || posIndex < 0 || posIndex >= source.length())
|
||||||
return null;
|
return null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return (source.substring(posIndex+1, posIndex+2));
|
return (source.substring(posIndex, posIndex+1));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{}
|
{}
|
||||||
|
@ -460,34 +459,74 @@ public class Adempiere implements Serializable
|
||||||
{
|
{
|
||||||
boolean isSystem = System != null && "Y".equals(System);
|
boolean isSystem = System != null && "Y".equals(System);
|
||||||
int retValue = -1;
|
int retValue = -1;
|
||||||
StringBuffer sql = new StringBuffer ("SELECT CurrentNext");
|
String next = "CurrentNext";
|
||||||
if (isSystem)
|
if (isSystem)
|
||||||
sql.append("Sys");
|
next = next + "Sys";
|
||||||
sql.append(",IncrementNo FROM AD_Sequence WHERE AD_Sequence_ID=?");
|
//lock the row
|
||||||
PreparedStatement pstmt = prepareStatement(sql.toString(),
|
StringBuffer sql = new StringBuffer ("UPDATE AD_Sequence SET ");
|
||||||
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
|
sql.append(next)
|
||||||
ResultSet rs = pstmt.executeQuery();
|
.append(" = ")
|
||||||
if (rs.next())
|
.append(next)
|
||||||
|
.append(" WHERE AD_Sequence_ID=?");
|
||||||
|
PreparedStatement pstmt = prepareStatement(sql.toString());
|
||||||
|
try
|
||||||
{
|
{
|
||||||
retValue = rs.getInt(1);
|
pstmt.setInt(1, AD_Sequence_ID);
|
||||||
int incrementNo = rs.getInt(2);
|
pstmt.executeUpdate();
|
||||||
rs.updateInt(2, retValue + incrementNo);
|
|
||||||
pstmt.getConnection().commit();
|
|
||||||
}
|
}
|
||||||
rs.close();
|
finally
|
||||||
pstmt.close();
|
{
|
||||||
//
|
pstmt.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//get current value
|
||||||
|
sql = new StringBuffer ("SELECT ");
|
||||||
|
sql.append(next)
|
||||||
|
.append(" FROM AD_Sequence WHERE AD_Sequence_ID=?");
|
||||||
|
pstmt = prepareStatement(sql.toString(),
|
||||||
|
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pstmt.setInt(1, AD_Sequence_ID);
|
||||||
|
ResultSet rs = pstmt.executeQuery();
|
||||||
|
if (rs.next())
|
||||||
|
{
|
||||||
|
retValue = rs.getInt(1);
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
pstmt.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//update and return
|
||||||
|
sql = new StringBuffer ("UPDATE AD_Sequence SET ");
|
||||||
|
sql.append(next)
|
||||||
|
.append(" = ")
|
||||||
|
.append(next)
|
||||||
|
.append(" + IncrementNo")
|
||||||
|
.append(" WHERE AD_Sequence_ID=?");
|
||||||
|
pstmt = prepareStatement(sql.toString());
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pstmt.setInt(1, AD_Sequence_ID);
|
||||||
|
pstmt.executeUpdate();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
pstmt.close();
|
||||||
|
}
|
||||||
|
|
||||||
return retValue;
|
return retValue;
|
||||||
} // nextID
|
} // nextID
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get current Date (Timestamp)
|
* get current Date (Timestamp)
|
||||||
|
* @deprecated
|
||||||
* @return Timestamp
|
* @return Timestamp
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//jz not found anywhere, add it
|
|
||||||
public static Timestamp getDate()
|
public static Timestamp getDate()
|
||||||
{
|
{
|
||||||
return new Timestamp(new java.util.Date().getTime());
|
return new Timestamp(new java.util.Date().getTime());
|
||||||
|
@ -495,26 +534,14 @@ public class Adempiere implements Serializable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get chars from a number
|
* get chars from a number
|
||||||
* @param n int
|
* @deprecated
|
||||||
* @return String
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
/*jz not found anywhere, add it
|
|
||||||
public static String getChars(int n)
|
|
||||||
{
|
|
||||||
return Integer.toString(n);
|
|
||||||
} // getDate
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get chars from a number
|
|
||||||
* @param d double
|
* @param d double
|
||||||
* @return String
|
* @return String
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
//jz not found anywhere, add it
|
|
||||||
public static String getChars(BigDecimal d)
|
public static String getChars(BigDecimal d)
|
||||||
{
|
{
|
||||||
return d.toString();
|
return d.toString();
|
||||||
} // getDate
|
} // getChars
|
||||||
|
|
||||||
} // Adempiere
|
} // Adempiere
|
||||||
|
|
Loading…
Reference in New Issue