Delete Power Query queries' custom XML data using VBA
I have Power Query queries in an Excel 2010 file and would like to delete these queries using VBA. so far I can achieve that manually with the following steps:
unload Power Query addin
run Document Inspector and click to delete Custom XML data
The Macro recorder record the following code for step 2.
Sub Makro1()
' Makro1 Makro
ActiveWorkbook.RemoveDocumentInformation (xlRDIPrinterPath)
ActiveWorkbook.RemoveDocumentInformation (xlRDIDocumentProperties)
ActiveWorkbook.RemoveDocumentInformation (xlRDIInactiveDataConnections)
End Sub
However, using this macro I do not achieve the same result (=PQ query code gone from the workbook).
Any ideas on how to achieve the PQ query codes to be removed using VBA?
On some cases Macro Recording is not complete, and misses to record the full set of VBA to automate the actions you record. This is probably such a case.
We are looking into future ways to allow you automate Power Query cleanup.
For the time being, please see if the
Document Inspector interface can clean the custom XML data (which holds the Power Query data structures).
thx, Gil.
Similar Messages
-
Prepopulating Interactive Form with XML Data using VBA
I have an excel spreadsheet with data on it. I need to click on a button that will cause an Interactive PDF form to open and be populated with data from the spreadsheet. To do this I want to use an XML data file. I know how to create the file, but how do I cause the PDF to open in Adobe Reader with the XML data file using VBA? The link needs to be a soft link, in that the name of the XML file could change.
Many thanks for answers.strXFDFFile = "c:\temp\" & strFileName & "tmp.xfdf"
'Open the PDF file
appPDFInit = True
Status "Processing " & strFileName
DoEvents
' Create PDF File, if any
If strXFDFFile <> "" Then
Dim fldValue As String
Open strXFDFFile For Output As #1
Print #1, "<?xml version=""1.0"" encoding=""UTF-8""?>"
Print #1, "<xfdf xmlns=""http://ns.adobe.com/xfdf/"" xml:space=""preserve"">"
Print #1, "<f href=""" & strFilePath & strFileName & """/>"
Print #1, "<fields>"
For Each fdField In rsData.Fields
If IsNull(fdField.Value) Then
fldValue = ""
Else
fldValue = fdField.Value
fldValue = XMLit(fldValue)
End If
If InStr(1, fdField.Name, "ID") > 0 Then
fldValue = Format(fldValue, "##########")
End If
If InStr(1, fdField.Name, "ZIP") > 0 Then
fldValue = Format(fldValue, "#####")
End If
If InStr(1, fdField.Name, "Rate") > 0 Then
fldValue = Format(fldValue, "#0.00#")
End If
' Write #1, fdField.Name,
Print #1, "<field name=""" & fdField.Name & """>"
Print #1, "<value>" & fldValue & "</value>"
Print #1, "</field>"
Next
Print #1, "</fields>"
Print #1, "</xfdf>"
Close #1
End If
Dim x As Long
For x = 1 To 1000000: Next x
LaunchPDF.LaunchFile strXFDFFile, 0, 2
Make sure you reference the Adobe Acrobat Browser Control Library under Tools | References
It will merge to Adobe Reader. Note that I have made the strXFDFFile variable unique by including the name of the PDF file. This assures that you can merge to more than one PDF at a time (this is taken from a loop for multiple PDF files). Note that the XFDF file must include the path and the PDF file name in order to open the correct PDF for merging.
I don't have time to explain the code, but if you have any questions let me know.
Daniel H. Smith
Smith Enterpises LLC -
Hi all,
From https://www.simple-talk.com/content/print.aspx?article=1756, I mimicked to create the following sql code to do Importing XML data using a CTE:
---Importing XML data using a CTE -----Ad-Hoc XML File Query--simple-talk---1020AM 27 Feb 2015
---query the XML Blob using a CTE (pulling from the XML file each time
USE OPENXMLtesting1
GO
With XmlFile (Contents) AS (
SELECT CONVERT (XML, BulkColumn)
FROM OPENROWSET (BULK 'C:\XML FilesMicrosoft-Samples\books.xml', SINGLE BLOB) AS XmlData
SELECT
FROM XmlFile
GO
I got the following message:
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'BLOB'.
I have no ideas why it is incorrect in that code statment. Please kindly help, advise and respond.
Thanks in advance,
Scott Chang
P. S. The books.xml file was copied from the Microsoft samples:
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
<book id="bk104">
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-03-10</publish_date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
<book id="bk105">
<author>Corets, Eva</author>
<title>The Sundered Grail</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-09-10</publish_date>
<description>The two daughters of Maeve, half-sisters,
battle one another for control of England. Sequel to
Oberon's Legacy.</description>
</book>
<book id="bk106">
<author>Randall, Cynthia</author>
<title>Lover Birds</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-09-02</publish_date>
<description>When Carla meets Paul at an ornithology
conference, tempers fly as feathers get ruffled.</description>
</book>
<book id="bk107">
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-11-02</publish_date>
<description>A deep sea diver finds true love twenty
thousand leagues beneath the sea.</description>
</book>
<book id="bk108">
<author>Knorr, Stefan</author>
<title>Creepy Crawlies</title>
<genre>Horror</genre>
<price>4.95</price>
<publish_date>2000-12-06</publish_date>
<description>An anthology of horror stories about roaches,
centipedes, scorpions and other insects.</description>
</book>
<book id="bk109">
<author>Kress, Peter</author>
<title>Paradox Lost</title>
<genre>Science Fiction</genre>
<price>6.95</price>
<publish_date>2000-11-02</publish_date>
<description>After an inadvertant trip through a Heisenberg
Uncertainty Device, James Salway discovers the problems
of being quantum.</description>
</book>
<book id="bk110">
<author>O'Brien, Tim</author>
<title>Microsoft .NET: The Programming Bible</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-09</publish_date>
<description>Microsoft's .NET initiative is explored in
detail in this deep programmer's reference.</description>
</book>
<book id="bk111">
<author>O'Brien, Tim</author>
<title>MSXML3: A Comprehensive Guide</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-01</publish_date>
<description>The Microsoft MSXML3 parser is covered in
detail, with attention to XML DOM interfaces, XSLT processing,
SAX and more.</description>
</book>
<book id="bk112">
<author>Galos, Mike</author>
<title>Visual Studio 7: A Comprehensive Guide</title>
<genre>Computer</genre>
<price>49.95</price>
<publish_date>2001-04-16</publish_date>
<description>Microsoft Visual Studio 7 is explored in depth,
looking at how Visual Basic, Visual C++, C#, and ASP+ are
integrated into a comprehensive development
environment.</description>
</book>
</catalog>I found the mistakes I made and I corrected them. The newly revised/corrected code is:
USE OPENXMLtesting1
GO
With XmlFile (Contents) AS (
SELECT CONVERT (XML, BulkColumn)
FROM OPENROWSET (BULK 'C:\Temp\books.xml', SINGLE_BLOB) AS XmlData
SELECT *
FROM XmlFile
GO
It worked: Results
Contents
1 <catalog><book.id="bk101"><author>Gambardella.M...
If I clicked on this, I got a listing of the whole book.xml!! I don't know what it means. Please comment and respond.
Thanks,
Scott Chang -
Remove Power Query queries while keeping the query output tables
I use power query to load data from external sources into several excel tables. Before sending this excel to a client, I would like to remove all power query queries (M code) while keeping the output/query tables at place.
My current workaround is:
unload Power Query
convert each table to range
load Power Query
delete queries (M code)
Is there a better/faster way to achieve what I want?You can unlink the existing tables and remove custom XML data in Document Inspector. No need to duplicate the worksheet.
exactly. and even unlinking the tables is not neccessary for DocInspector to remove the custom XML of PQ.
Do you have any suggestion on how to trigger the cleaning of PQ XML code via VBA?
the following code does not work:
ActiveWorkbook.RemoveDocumentInformation (xlRDIAll) -
How to upload different views of customer master data using LSMW-IDOC
I need to upload customer master data using LSMW Idoc method for my client. Now customer will have different views like main view, Sales data, Company code data, Partner function data etc. And except main data all other data can be multiple for each customer. We are going to upload data from tab delimited .TXT file. Should I propose different LSMW for upload different views for the customer from different .TXT files? or we can upload all the customer related data (like main view data and partner function data )from a single .TXT file. Kindly suggest which one in convenient and how we can prepare the data file in both cases.
convinient is the method that you can handle.
but as the guy who loads the data you have to load the data like they are available, like it is convinient for others to prepare the data.
In general there is no problem to use an IDOC method to load a customer master with multiple comany codes and several sales orgs in one shot.
the data can be in one source file, but need then to be maintained in a certain way
Example1: all data in 1 structure
GD1 - CC1 - SO1
GD1 - CC2 - SO2
GD1 - CC2 - SO3
in this case the GD (general data) is redundand in each line which has different Company code data or different Sales Org data
Example2: all data in 3 sturcures but one file
GD1
.CC1
.CC2
..SO1
..SO2
..SO3
Example3: data delivered in 3 files - you join the files in LSMW, they must have a common identifier like the old customer number in the beginning of each file
FILE General data:
GD1
GD2
GD3
file Compamy code data:
CC1
CC2
CC3
file Sales org data:
SO1
SO2
SO3
LSMW is flexible and can handle each of this scenarios, are you flexible too? -
I am unable to upload the customer master data using BAPI.?
Hi Guru's,
i am unable to upload the customer master data using BAPI.(BAPI_CUSTOMER_CREATEFROMDATA1)
Please guide me how upload the data...
Thanks in iadvance
Srinivas...Hello Srinivas
This BAPI does not allow to create a new customer from scratch but only to copy an existing customer to a new one and change its address data.
The reference customer has to be provided using IMPORTING parameter PI_COPYREFERENCE. See also the BAPI documentation for more details.
The BAPI does the same like transaction XD01 with Reference.
Regards
Uwe -
How to send te XML data using HTTPS post call & receiving response in ML
ur present design does the HTTP post for XML data using PL/SQL stored procedure call to a Java program embedded in Oracle database as Oracle Java Stored procedure. The limitation with this is that we are able to do HTTP post; but with HTTPS post; we are not able to achieve because of certificates are not installed on Oracle database.
we fiond that the certificates need to be installed on Oracle apps server; not on database server. As we have to go ultimately with HTTPS post in Production environment; we are planning to shift this part of program(sending XML through HTTPS post call & receiving response in middle layer-Apps server in this case).
how i can do this plz give some solutionIf you can make the source app to an HTTP Post to the Oracle XML DB repository, and POST contains a schema based XML document you can use a trigger on the default table to validate the XML that is posted. The return message would need to be managed using a database trigger. You could raise an HTTP error which the source App would trap....
-
Can I copy Power Query queries to other Excel workbook ?
Can I copy Power Query queries to other Excel workbook ?
I want to copy some Power Query queies to other Excel workbook.
a workbook have some queries about population.
a workbook have some queries about labor market.
I want to build a workbook with population queries and labor market queries for sharing OneDrive.
Regards,
Yoshihiro KawabataThank you, Curt.
Yes, Now I copy by M code.
I want more easy way.
When sharing Query at Power BI, Excel automatically share all related queries by one click.
Regards,
Yoshihiro Kawabata -
Adobe Reader importing XML data using command line reference
Financial Gonverment in Poland prepared new VAT declarations, which are protected from changing.
Restrictions summary is as follows: Printing, Commenting, Filling of form fields: Allowed; other restrictions are not allowed.
I am able to export xml data, using Acrobat Reader, change it to have desired data and than import it and everything works fine. In ERP program I need to fill this document with data from the system. Normally we were doing this using FDF printing channel, but for this document it shows an error with bad user password. We were talking with people from government and only answer was that it is not possible to change document restrictions... We find out the way to create xml document, but we want it now to open from the command line (UNIX commands). But we only find the way to open pdf file with specified fdf file... But when I'm trying to open PDF document with specified fdf URL (url is linked to xml file... i don't know if it is proper... if not than how to create fdf file with desired xml?)
Is there any possible to open a pdf with specified xml url to load to that PDF?I found the mistakes I made and I corrected them. The newly revised/corrected code is:
USE OPENXMLtesting1
GO
With XmlFile (Contents) AS (
SELECT CONVERT (XML, BulkColumn)
FROM OPENROWSET (BULK 'C:\Temp\books.xml', SINGLE_BLOB) AS XmlData
SELECT *
FROM XmlFile
GO
It worked: Results
Contents
1 <catalog><book.id="bk101"><author>Gambardella.M...
If I clicked on this, I got a listing of the whole book.xml!! I don't know what it means. Please comment and respond.
Thanks,
Scott Chang -
Upload XML data using XSQL and HTTP Post ?
Upload XML data using XSLQ and HTTP Post: is that possible ?
An xsql contains an <xsql:insert-request table="aTable">
The XML data file follows the ROWSET/ROW paradigm.
What is the HTML form to upload the xml file to the XSQL ?
I tried:
<form action="myXSQL.xsql" method="POST" ENCTYPE="multipart/form-data">
XML data file to upload: <input type="file">
<input type="submit">
</form>
But the answer of myXSQL is:
<xsql-status action="xsql:insert-request" result="No posted document to process" />
Where is the problem ?
Thank you.Hello,
You are posting your XML file as a parameter therefore you should use the <xsql:insert-params/> tag, not the <xsql:insert-request/>. The insert-request can only handle data not posted via a parameter.
Usage:
<form action="myXSQL.xsql" method="GET" ENCTYPE="multipart/form-data">
XML data file to upload: <input type="file" name="myXML">
<input type="submit">
</form>
in combination with
<xsql>
<xsql:insert-params name="myXML" table="your table"/>
</xsql>
2 remarks:
I was not able to succesfully POST the form. The answer was <xsql-status action="xsql:insert-request" result="No posted document to process" />. With GET is was succesfull.
Second, if you use MSInternet explorer 5 or higher use could post the XML directly (not aw parameter) using an ActiveX object.
Regards,
Harm Verschuren -
How can we store xml data using jsp
hai,
Can anyone please explain in brief how to store xml data using jsp. Also if possible please explain by specifying the code.
regards,
Praveen Vinnakota.[email protected] wrote:
how can we publish Labview data using the web?
You could use shared variables and publish them to the network or use data sockets.
Kudos always welcome for helpful posts -
Hi,
I am really new to Adobe LiveCycle.
If I have something like:
15536455
Charles
Porter
JVBERi0xLjMKJeTjz9IKNSAwIG9iago8PC9MZW5... ZQo+PgpzdHJlYW0KeJylWEtv3DYQvutX8FKgPZj... Z/iUBGstoTDg9cfVfPPgcPjJDxUnDH7wt3GCtPv...
This packet does not represent a PDF subassembly
How can I use the data from the custom XML to bind it to a text field for example. ThanksDo you have a sample XML file? If so, in Designer create a new Data Connection usng your sample XML file. Once you have read the file, then simply drag and drop the nodes in the XML to the fields on your form and the two objects will be bound. Note that if the bind is successful then a chain link will appear in the dataview indicating that the node is bound.
-
Free order of tags when deserialising XML-data using Simple Transformatiosn
Hi everybody,
I'm consuming a WebService and get something like this XML-data in the response:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getSalesResponse>
<getSalesReturn href="#id0"/>
</getSalesResponse>
<multiRef id="id0">
<customer href="#id1"/>
<salesOrg href="#id2"/>
<salesRecord soapenc:arrayType="SalesRecord[2]" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<salesRecord href="#id3"/>
<salesRecord href="#id4"/>
</salesRecord>
</multiRef>
<multiRef id="id1"><customer>124843</customer></multiRef>
<multiRef id="id2"><salesOrg>0001</salesOrg></multiRef>
<multiRef id="id3"><material>mat1</material></multiRef>
<multiRef id="id4"><material>mat2</material></multiRef>
</soapenv:Body>
</soapenv:Envelope>
</xml>
I've written a Simple Transformation: it fills my fields i_customer, i_salesorg, i_mat1 and i_mat2 from this XML-Data from the content of the <multiRef>-tags. But only if the order is exactly like this:
<multiRef><customer><tt:value ref="I_CUSTOMER"/>
</customer></multiRef>
<multiRef><salesOrg><tt:value ref="I_SALESORG"/>
</salesOrg></multiRef>
<multiRef><material><tt:value ref="I_MATERIAL1"/>
</material></multiRef>
<multiRef><material><tt:value ref="I_MATERIAL2"/>
</material></multiRef>
However the WebService doesn't guarantee a certain order for the <multiRef>-tags. That means the salesOrg could be contained ahead of the customer.
In a next step I've tried to use the command '<tt:group>' that allows free order of the first two elements:
<tt:group>
<tt:d-cond frq="1">
<multiRef><customer><tt:value ref="I_CUSTOMER"/>
</customer></multiRef>
</tt:d-cond>
<tt:d-cond frq="1">
<multiRef><salesOrg><tt:value ref="I_SALESORG"/>
</salesOrg></multiRef>
</tt:d-cond>
</tt:group>
<multiRef><material><tt:value ref="I_MATERIAL1"/>
</material></multiRef>
<multiRef><material><tt:value ref="I_MATERIAL2"/>
</material></multiRef>
However the WebService doesn't guarantee any order for the <multiRef>-tags. That means the first material could be contained ahead of the customer.
How can I insert the lines for my materials into to <tt:group>-command? Actually the WebService could deliever n materials, so I tried this (but that didn't work any more):
<tt:group>
<tt:d-cond frq="1">
<multiRef><customer><tt:value ref="I_CUSTOMER"/>
</customer></multiRef>
</tt:d-cond>
<tt:d-cond frq="1">
<multiRef><salesOrg><tt:value ref="I_SALESORG"/>
</salesOrg></multiRef>
</tt:d-cond>
<tt:d-cond frq="*">
<tt:loop name="tab" ref=".IT_MATERIALS">
<multiRef><material><tt:value ref="$tab.MATERIAL"/>
</material></multiRef>
</tt:loop>
</tt:d-cond>
Any help would be greatly appreciated. My colleagues have already begun to leave the office because I look more and more frustrated...
Greeting from Munich,
markus
Message was edited by: Markus Jarasch
Message was edited by: Markus JaraschI have some Interface Mapping questions I was hoping someone could help me with. As you know, my source is an XML File and my target is an OracleDB. I'll start with the "EFFECTIVEDATE" field which was automatically mapped when I added the Source and Target Datastores. As I previously mentioned, this caused an error "Target Column EFFECTIVEDATE: Data may be truncated: the target Column is smaller than the source Column". After looking further into it, would the problem be that the "EFFECTIVEDATE" datatype in the XML is "DATETIME" whereas the "EFFECTIVEDATE" datatype in the database is "TIMESTAMP"? If so, what would be the fix for this? Could I convert it in the Implemenation Mapping like so? -
CONVERT(MONEY.EFFECTIVEDATE,TIMESTAMP)
Would using that in the Implementation simply do the trick?
Anyway, moving onto some of the other TARGET fields...
-ACTIVITYGUID
This should be an automatically generated new GUID value. How could I implement this into the Implementation?
-TRANSACTIONGUID
I'll need to query some of the other tables in the database in order to get this value. Is this allowed in the Implemenation? Do I have to add said tables to the target somehow? Can I just query the other tables in the Implementation field using normal select statements, etc.? I'm a bit confused on how this would work...
-TYPECODE
This needs to be a fixed value of '01'. How do I simply do that in the Implementation?
The other fields will all be implemented similar to the above so those are the main questions I have for now. Any help would be appreciated.
Thanks again for your help. -
Is there any way to improve Query which searches XML data from a table??
hi all,
i have a table which have one column say 'colA' as Varchar(max) datatype which i save xml data and it have other cols too
Currently i am searching data inside this table using like operator
eg:
Select * from tablename where colA like ‘%<tagname>parameterstringvalue</tagname>%’
when i check with the Execution plan i could see it Takes 82% for clusterd index scan ( primarykey col
not ColA)
i added new non clusterd index for the same with include col as ColA and i found nonclusterd index scan
with same estimated I O cost and Extimated operator cost as clusterd index scan
My Question is :-
1. why didnt nonclusterd index seek come?
2. In What way i can improve perfomance for such situvation? i had seen couple of post suggesting to rewrite the Query as SELECT
* FROM myTable WHERE CONTAINS (myCol1, myCol2, "myString").
I Try creating Full text index and found cost increased compared to the original Query ?
3. As per my assumption the wild charecter ('%') in begining makes perfomance issue is there any option
or an alternative for such case?hi...i can give a skeleton
--Table Structure------------
Table1:-
(colA - int(PK),
ColB - Varchar(max),
ColC-uniquieidentifier,
ColD-datetime,
ColE-Bit)
It have clusterd index for ColA
Table2:-
(ColA-int(fk)
colF-int(pk)
colG-varchar(max),
ColH-uniqueidentifier,
colI-int,
colJ-int
ColK-date)
-----------------Query Skeleton-------------------:
select Distinct
s.colA,
s.ColB,
S.colC,
S.colD
from Table1 s with (nolock)
left outer join table2 Q with (nolock) on s.colA=q.ColA
where Q.ColA is null
and s.colB like '%<tag>sometext</tag>%'
and s.colD >='1/1/2010'
and s.colD <='1/1/2014'
i hope this will help to understand it clearly......... -
BC4J Query by example for dates uses wrong date format
When querying by example on date fields, I get the following nested exceptions:
oracle.jbo.SQLStmtException: JBO-27121: SQL error during statement execution.
JBO-26044: Error while getting estimated row count for view object
and
java.sql.SQLException: ORA-01830: date format picture ends before converting entire input string.
It would seem to be caused by the following clause added to the end of the entity object's query:
"QRSLT WHERE ( ( (DATE_FIELD = TO_DATE('23/12/2003', 'yyyy-mm-dd')) ) )"
which causes problems as our entity objects use a 'dd/MM/yyyy' date format.
Is there a way we can make the query by example use the same date format as the rest of our app?Im not an expert on this but I see nobody is replying so this might help you. I've been having problems with dates as well and Im pretty sure that the attached formatter isn't used in find mode. That is because the java date class (can't remember which one) used by the BC4J has the format yyyy-mm-dd. I don't now if it is possible to change it but I got around the problem by writing my own domain. You can take a look at Toystore demo, by Steve Muench, that uses a custom date domain, ExpirationDate (see the code below). It is mapped to a VARCHAR column in the database but it is possible to map it to a DATE column.
I have been watching the postings with questions about dates and I have noticed that a lot of people have problems with this but I havent seen an answer yet.
package toystore.model.datatypes.common;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import oracle.jbo.Transaction;
import oracle.jbo.domain.DataCreationException;
import oracle.jbo.domain.DomainInterface;
import oracle.jbo.domain.DomainOwnerInterface;
// --- File generated by Oracle Business Components for Java.
* This custom datatype implements an immutable domain class that
* maps to a VARCHAR column containing values like '10/2004' representing
* expiration dates of credit cards. We could have chosen to implement
* this as a domain that stores itself in a DATE column instead of a
* VARCHAR column, but since the Java Pet Store demo schema stored the
* information in a VARCHAR column, we decided to illustrate how to
* accommodate that case using domains.
public class ExpirationDate implements DomainInterface, Serializable {
private Date mDate;
private String mDateAsString;
protected ExpirationDate() {
mDate = new Date();
convertDateToStringFormat();
* Return the value of the expiration date as a java.util.Date
public Date getDateValue() {
return mDate;
* Allow expiration date to be constructed from two
* strings representing month and year
public ExpirationDate(String monthVal, String yearVal) {
this(monthVal+'/'+yearVal);
public ExpirationDate(String val) {
validate(val);
convertDateToStringFormat();
* The getData() method must return the type of object that JDBC will
* see for storage in the database. Since we want this ExpirationDate
* datatype to map to a VARCHAR column in the database, we return the
* string format of the date
public Object getData() {
return mDateAsString;
* <b>Internal:</b> <em>Applications should not use this method.</em>
public void setContext(DomainOwnerInterface owner, Transaction trans, Object obj) {
* Performs basic validation on strings that represent expiration dates
* in the format of MM/YYYY. Note that in the process of testing whether
* the string represents a valid month and year, we end up setting
* the private member variable mDate with the date value, so if the
* validate() method does not throw an exception, the mDate will be setup.
protected void validate(String val) {
if (val != null) {
if (val.length() != 7 ||
val.charAt(2) != '/' ||
!isAllDigitsExceptSlashAtPositionTwo(val) ||
!isValidMonthAndYear(val)) {
throw new DataCreationException(ErrorMessages.class,
ErrorMessages.INVALID_EXPRDATE,
null,null);
* Returns true if all digits except position 2 (zero-based) are digits
private boolean isAllDigitsExceptSlashAtPositionTwo(String val) {
for (int z=0, max = val.length(); z < max; z++) {
if (z != 2 && !Character.isDigit(val.charAt(z))) {
return false;
return true;
* Returns true if the val string, assumed to be in "MM/YYYY" format
* is a valid month and year value, setting the mDate member variable
* if they are valid.
private boolean isValidMonthAndYear(String val) {
try {
int month = Integer.parseInt(val.substring(0,2));
int year = Integer.parseInt(val.substring(3));
Calendar c = Calendar.getInstance();
c.setLenient(false);
c.set(year,month-1,1); // Month is zero-based !
mDate = c.getTime();
catch (IllegalArgumentException i) {
return false;
return true;
public String toString() {
return mDateAsString;
* Convert mDate to String format
private void convertDateToStringFormat() {
if (mDate != null) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/yyyy");
mDateAsString = sdf.format(mDate);
* Return true if the expiration date is in the future
public boolean isFutureDate() {
return mDate.compareTo(new Date())> 0;
* Compare the Expiration Dates by comparing their respective
* getData() values
public boolean equals(Object obj) {
if (obj instanceof DomainInterface) {
Object thisData = getData();
if (thisData != null) {
return thisData.equals(((DomainInterface)obj).getData());
return ((DomainInterface)obj).getData() == null;
return false;
Maybe you are looking for
-
Why is my MBP battery is giving me only 3 hours?
i have a macbook pro 2012 2.3 Ghz with Mountain Lion .1 so i heard that the 10.8.1 upgrade would repair the battery issue, i dont see any fix with the battery. is anyone having the same problems with 10.8.1 too? what can i do for the battery? is ther
-
Lightweight chm and djvu (and pdf) viewer?
On windows I have used SumatraPDF, a very fast and lightweight app that can read pdf, djvu, and chm, among others. On arch I'm using epdfview for PDFs, but is there anything light and fast for chm and djvu? and of course, better one app to handle th
-
Am trying to import photos taken with my iPod touch to my windows 7 computer. When I plug in my iPod the Auto play dialogue box doesn't come up. I read the related article and tried to enable the behavior but when I go to the autoplay section and to
-
Hi, I'm a new Bridge CS4 user. When I do edit my pictures on my Epson P5000 by putting stars on chosen pixs, I don't see those stars appearing on Bridge. Is there a trick to resolve that? Those stars appears in Expression Media (ex-Iview Mediapro)...
-
ITunes downloads but has dep error on launch then shuts down
Hello, Computer specs are HP dv7 pavillion 145ca running vista premium 64bit. Enough hard drive space to choke an elephant. Required 4gigs of ram. Current version of norton anti virus spyware loaded. The issue!! Downloaded the new verssion 10.6.3 of