How to retrieve data from database based on date in java? - java

Here is what I have tried
Controller:
public void lovForFincurrency() {
LOG.info("\n\n\nINSIDE \n CLASS == LovController \n METHOD == lovForFincurrency(); ");
try {
apexManagerService = ServiceManagerFactory.getServiceManager(getServletContext());
MmsBean mmsBean = (MmsBean) getControllerObject(ApexManagedBean.MMSBEAN.getName(), MmsBean.class);
PmBean pmBean = (PmBean) getControllerObject(ApexManagedBean.PMBEAN.getName(), PmBean.class);
final FinCurrencyService finsurrencyservice = apexManagerService.getFinCurrencyService();
DateFormat dateFormat = new SimpleDateFormat("MM/DD/YYYY HH:mm:ss");
Date date = new Date();
List<Fincurrency> fincurrencies = finsurrencyservice.readcurrencies("Y", date);
List<Admlov> admlovs = new ArrayList<Admlov>();
for (Fincurrency fincurrency : fincurrencies) {
Admlov admlov = new Admlov();
admlov.setId(fincurrency.getCurrency());
admlov.setCode(fincurrency.getSymbol());
admlov.setDescr(fincurrency.getDescr());
admlovs.add(admlov);
}
if (admlovs != null) {
mmsBean.setAdmlovs(admlovs);
}
} catch (Exception ex) {
LOG.error(ex.getMessage(), ex);
addMessageToFacesContext(ERROR_DELETE);
}
LOG.info("EXITING THIS METHOD \n\n\n");
}
Here is my Repository:
public interface FinCurrencyRepo extends JpaRepository<Fincurrency, String> {
List<Fincurrency> findByEffectivefromAfterAndEffectivetoBeforeAndEnabled(Date sysdate, Date sysdate1,
String enabled);
}
Here is my serviceimplementation:
#Override
public List<Fincurrency> readcurrencies(String enabled, Date sysdate) {
return fincurrencyRepo.findByEffectivefromAfterAndEffectivetoBeforeAndEnabled(sysdate, sysdate, enabled);
}
Here is my Fincurrency Entity: I want to show symbol and currency in datatable of this year and after this year but not before this year. Kindly help me in this issue.
public class Fincurrency implements Serializable {
#Id
private String currency;
//#Temporal(TemporalType.DATE)
private Date effectivefrom;
//#Temporal(TemporalType.DATE)
private Date effectiveto;
private String enabled;
private String symbol;
#Column(name="\"TYPE\"")
private String type;
public Fincurrency() {
}
public String getCurrency() {
return this.currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
public BigDecimal getAfterdecimal() {
return this.afterdecimal;
}
public void setAfterdecimal(BigDecimal afterdecimal) {
this.afterdecimal = afterdecimal;
}
public Date getEffectivefrom() {
return this.effectivefrom;
}
public void setEffectivefrom(Date effectivefrom) {
this.effectivefrom = effectivefrom;
}
public Date getEffectiveto() {
return this.effectiveto;
}
public void setEffectiveto(Date effectiveto) {
this.effectiveto = effectiveto;
}
public String getEnabled() {
return this.enabled;
}
public void setEnabled(String enabled) {
this.enabled = enabled;
}
public String getSymbol() {
return this.symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
}

Related

Realm Migration is not working in Android?

I am at present working on a android chat application like whatsapp but I stuck at a situation in where Realm Migration is issue. I am not knowing so much about realm but testing it for a successful offline chat application. I am not able to use more than one model in realm because it is saying about the migrator. I tried all the ways but my migrator is not working and I also not having idea that what statements I have to use after this (schema.) statement for migrate my model according to my situations.
Here is the Code for my Realm ChatList Model:-
public class RealmChatListModel extends RealmObject {
#Index
private String userID;
private String Username;
private String Descryption;
private String phoneNo;
private String lastMessage;
private String Date;
private String ImageURI;
private long lastMessageTime;
public RealmChatListModel() {
}
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getUsername() {
return Username;
}
public void setUsername(String username) {
Username = username;
}
public String getDescryption() {
return Descryption;
}
public void setDescryption(String descryption) {
Descryption = descryption;
}
public String getPhoneNo() {
return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public String getLastMessage() {
return lastMessage;
}
public void setLastMessage(String lastMessage) {
this.lastMessage = lastMessage;
}
public String getDate() {
return Date;
}
public void setDate(String date) {
Date = date;
}
public String getImageURI() {
return ImageURI;
}
public void setImageURI(String imageURI) {
ImageURI = imageURI;
}
public long getLastMessageTime() {
return lastMessageTime;
}
public void setLastMessageTime(long lastMessageTime) {
this.lastMessageTime = lastMessageTime;
}
}
And here is my code for realm Chat Model :-
public class RealmChat extends RealmObject {
#PrimaryKey
#Index
private String messageKey;
private String time;
private String date;
private String textMessage;
private String type;
private String sender;
private String receiver;
private String uri;
private boolean isSeen;
private String duration;
private String receivername;
private String fileSize;
private boolean isNextDay;
private boolean isDeleted;
private Date extactdate;
private String repMesKey;
private String repMesUri;
private String repMesText;
private String repMesType;
private String repMesSender;
private long timestamp;
private String repMesSendPhone;
private boolean isReplied;
private String phoneNo;
private boolean isForwarded;
public String getMessageKey() {
return messageKey;
}
public void setMessageKey(String messageKey) {
this.messageKey = messageKey;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTextMessage() {
return textMessage;
}
public void setTextMessage(String textMessage) {
this.textMessage = textMessage;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public boolean isSeen() {
return isSeen;
}
public void setSeen(boolean seen) {
isSeen = seen;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
public String getReceivername() {
return receivername;
}
public void setReceivername(String receivername) {
this.receivername = receivername;
}
public String getFileSize() {
return fileSize;
}
public void setFileSize(String fileSize) {
this.fileSize = fileSize;
}
public boolean isNextDay() {
return isNextDay;
}
public void setNextDay(boolean nextDay) {
isNextDay = nextDay;
}
public boolean isDeleted() {
return isDeleted;
}
public void setDeleted(boolean deleted) {
isDeleted = deleted;
}
public Date getExtactdate() {
return extactdate;
}
public void setExtactdate(Date extactdate) {
this.extactdate = extactdate;
}
public String getRepMesKey() {
return repMesKey;
}
public void setRepMesKey(String repMesKey) {
this.repMesKey = repMesKey;
}
public String getRepMesUri() {
return repMesUri;
}
public void setRepMesUri(String repMesUri) {
this.repMesUri = repMesUri;
}
public String getRepMesText() {
return repMesText;
}
public void setRepMesText(String repMesText) {
this.repMesText = repMesText;
}
public String getRepMesType() {
return repMesType;
}
public void setRepMesType(String repMesType) {
this.repMesType = repMesType;
}
public String getRepMesSender() {
return repMesSender;
}
public void setRepMesSender(String repMesSender) {
this.repMesSender = repMesSender;
}
public String getRepMesSendPhone() {
return repMesSendPhone;
}
public void setRepMesSendPhone(String repMesSendPhone) {
this.repMesSendPhone = repMesSendPhone;
}
public boolean isReplied() {
return isReplied;
}
public void setReplied(boolean replied) {
isReplied = replied;
}
public String getPhoneNo() {
return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public boolean isForwarded() {
return isForwarded;
}
public void setForwarded(boolean forwarded) {
isForwarded = forwarded;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
And Here is my code for my migrator :-
public class RealmMigration implements io.realm.RealmMigration {
#Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
// Migrate from version 0 to version 1
if (oldVersion == 0) {
schema.get("RealmChatListModel")
.addField("Username", String.class)
.addRealmListField("lastMessageTime", long.class);
oldVersion++;
}
if (oldVersion == 1) {
schema.get("RealmChat")
.addField("extactdate", Date.class)
.addRealmListField("timestamp",long.class);
}
}
public static RealmConfiguration getDefaultConfig() {
return new RealmConfiguration.Builder()
.schemaVersion(2)
.migration(new RealmMigration())
.build();
}
#Override
public int hashCode() { return RealmMigration.class.hashCode(); }
#Override
public boolean equals(Object object) { return object != null && object instanceof RealmMigration; }
}
Please Help me...................................................................................
<<<<<<<<<<<<<<<<------------------(~~~~~~~~~~~~~~~~~~~)------------------->>>>>>>>>>>>>>>>>>>>>
Yes I got it my migration is working only by a single change :-
#Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
// Migrate from version 0 to version 1
if (oldVersion == 0) {
schema.get("RealmChatListModel")
.addField("userID", String.class, FieldAttribute.REQUIRED);
oldVersion++;
}
}
Here I removed Realm Chat from migrating the old version because it is the last model and added in realmChatListSchema that userID field is required.Noting else reqired. I am happy 🥰 🥰 🥰 .

How to convert Date to string in realm

I am developing app now I want to convert Date to String in realm but I have tried but I can't achieve what I want
below SaveMessage model class
#RealmClass
public class SaveMessage extends RealmObject {
private int mId;
private String mUsername;
private String mContent;
private Date mCreatedAt;
private boolean mRightMessage;
private String mPictureString;
private String mType;
public SaveMessage(int id, String username, String content, Date createdAt, boolean isRightMessage) {
mId = id;
mUsername = username;
mContent = content;
mCreatedAt = createdAt;
mRightMessage = isRightMessage;
}
public SaveMessage() {
}
public int getId() {
return mId;
}
public String getUsername() {
return mUsername;
}
public String getContent() {
return mContent;
}
public Date getDate() {
return mCreatedAt;
}
public void setDate(Date createdAt) {
mCreatedAt = createdAt;
}
below my Date conversion
SimpleDateFormat input = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); SimpleDateFormat
output = new SimpleDateFormat("dd/MM/yyyy");
Date d = new Date();
try {
d = input.parse(output);
} catch (ParseException e) {
e.printStackTrace();
}
public boolean ismRightMessage() {
return mRightMessage;
}
public int getmId() {
return mId;
}
public void setmId(int mId) {
this.mId = mId;
}
public String getmUsername() {
return mUsername;
}
public void setmUsername(String mUsername) {
this.mUsername = mUsername;
}
public String getmContent() {
return mContent;
}
public void setmContent(String mContent) {
this.mContent = mContent;
}
public boolean ismRightMessage(String isRightMessage) {
return mRightMessage;
}
public void setmRightMessage(boolean mRightMessage) {
this.mRightMessage = mRightMessage;
}
public String getPictureString() {
return mPictureString;
}
public void setPictureString(String pictureString) {
mPictureString = pictureString;
}
public String getType() {
return mType;
}
public void setType(String type) {
mType = type;
}
}

Spring Boot Mongodb search by ID returns null

I have created a spring boot project with mongodb , when i insert data into collection it get inserted but when i try to fetch from findOne by id the inserted value based on id it always returns null, I have given my model class and inserting method below,please tell me whats wrong
Account.java
#Document(collection = "account")
public class Account {
#Id
private long _id;
#Field("account_name")
private String accountName;
#Field("connector_type")
private String connectorType;
#Field("xsiURI1")
private String xsiURI1;
#Field("xsiURI2")
private String xsiURI2;
#Field("oci1")
private String OCI1;
#Field("oci2")
private String OCI2;
#Field("telcomadmin_username")
private String telcomadminUsername;
#Field("telcomadmin_password")
private String telcomadminPassword;
#Field("password_expdays")
private String passwordExpdays;
#Field("account_email_address")
private String accountEmailAddress;
#DateTimeFormat(iso = ISO.DATE_TIME)
#Field("inserted_date")
private Date insertedDate;
#DateTimeFormat(iso = ISO.DATE_TIME)
#Field("updated_date")
private Date updatedDate;
#Field("isActive")
private Boolean isActive;
public long get_id() {
return _id;
}
public void set_id(long _id) {
this._id = _id;
}
public String getXsiURI1() {
return xsiURI1;
}
public void setXsiURI1(String xsiURI1) {
this.xsiURI1 = xsiURI1;
}
public String getXsiURI2() {
return xsiURI2;
}
public void setXsiURI2(String xsiURI2) {
this.xsiURI2 = xsiURI2;
}
public String getOCI1() {
return OCI1;
}
public void setOCI1(String oCI1) {
OCI1 = oCI1;
}
public String getOCI2() {
return OCI2;
}
public void setOCI2(String oCI2) {
OCI2 = oCI2;
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public String getConnectorType() {
return connectorType;
}
public void setConnectorType(String connectorType) {
this.connectorType = connectorType;
}
public String getTelcomadminUsername() {
return telcomadminUsername;
}
public void setTelcomadminUsername(String telcomadminUsername) {
this.telcomadminUsername = telcomadminUsername;
}
public String getTelcomadminPassword() {
return telcomadminPassword;
}
public void setTelcomadminPassword(String telcomadminPassword) {
this.telcomadminPassword = telcomadminPassword;
}
public String getPasswordExpdays() {
return passwordExpdays;
}
public void setPasswordExpdays(String passwordExpdays) {
this.passwordExpdays = passwordExpdays;
}
public String getAccountEmailAddress() {
return accountEmailAddress;
}
public void setAccountEmailAddress(String accountEmailAddress) {
this.accountEmailAddress = accountEmailAddress;
}
public Date getInsertedDate() {
return insertedDate;
}
public void setInsertedDate(Date insertedDate) {
this.insertedDate = insertedDate;
}
public Date getUpdatedDate() {
return updatedDate;
}
public void setUpdatedDate(Date updatedDate) {
this.updatedDate = updatedDate;
}
public Boolean getIsActive() {
return isActive;
}
public void setIsActive(Boolean isActive) {
this.isActive = isActive;
}
}
AccountsController.java
#RestController
#RequestMapping("/accounts")
#CrossOrigin("*")
public class AccountsController {
#Autowired
AccountsRepository accountsRepository;
#Autowired
SequenceRepository sequenceRepository;
private static final String ACCOUNT_SEQ_KEY = "accountsequence";
#PostMapping("/create")
public Account createAccount(#Valid #RequestBody Account account) {
account.set_id(sequenceRepository.getNextSequenceId(ACCOUNT_SEQ_KEY));
account.setIsActive(true);
return accountsRepository.save(account);
}
#GetMapping(value = "/findByID/{id}")
public ResponseEntity<Account> getAccountById(#PathVariable("id") String id) {
Account account = accountsRepository.findOne(id);
if (account == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} else {
return new ResponseEntity<>(account, HttpStatus.OK);
}
}
}
AccountsRepository
public interface AccountsRepository {
List<Account> findAll(Sort sortByCreatedAtDesc);
Account save(Account account);
Account findOne(String id);
void delete(String id);
}
AccountsRepositoryIMPL
#Repository
public class AccountsRepositoryImpl implements AccountsRepository {
DBOperations dbOperations = new DBOperations();
#Override
public List<Account> findAll(Sort sortByCreatedAtDesc) {
Query q = new Query().with(new Sort(Sort.Direction.ASC, "inserted_date"));
List<Account> accountList = dbOperations.getMongoOpertion().findAllAndRemove(q, Account.class);
return accountList;
}
#Override
public Account save(Account account) {
try {
dbOperations.getMongoOpertion().save(account);
} catch (Exception e) {
e.printStackTrace();
}
return account;
}
#Override
public Account fin**strong text**dOne(String id) {
Account account = dbOperations.getMongoOpertion().findOne(Query.query(Criteria.where("_id").is(id)),
Account.class, "account");
return account;
}
#Override
public void delete(String id) {
Query query = new Query();
query.addCriteria(Criteria.where("id").is(id));
Account account = dbOperations.getMongoOpertion().findOne(query, Account.class);
dbOperations.getMongoOpertion().remove(account);
}
}
DBOperations.java
public class DBOperations {
ApplicationContext ctx = new GenericXmlApplicationContext("SpringConfig.xml");
public MongoOperations getMongoOpertion() {
MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
return mongoOperation;
}
}
Look at your code.
You have declared _id as Long type.
#Id
private long _id;
But in your below methods you are passing String id to match the criteria.
So it is not working.
#Override
public Account findOne(String id) {
Account account = dbOperations.getMongoOpertion().findOne(Query.query(Criteria.where("_id").is(id)),
Account.class, "account");
return account;
}
#Override
public void delete(String id) {
Query query = new Query();
query.addCriteria(Criteria.where("id").is(id));
Account account = dbOperations.getMongoOpertion().findOne(query, Account.class);
dbOperations.getMongoOpertion().remove(account);
}

How to pass array of string in insert query in ibatis?

How to pass array of string in insert query statement in ibatis. On passing string array as parameter it is giving me this exception of ibatis -
Can't infer the SQL type to use for an instance of [Ljava.lang.String;. Use setObject() with an explicit Types value to specify the type to use.
How to solve this error ?
My method is -
public void insertCampaignData(String campaignData, ObjectMapper jsonObjMapper) {
Campaign campaign = null;
SqlSession session = null;
IfrmCreateCampaign createCampaign = null;
try {
campaign = jsonObjMapper.readValue(campaignData,Campaign.class);
session = DBConnectionFactory.getNewSession();
createCampaign = session.getMapper(IfrmCreateCampaign.class);
createCampaign.insertCampaignData(campaign);
} catch (Exception e) {
e.printStackTrace();
} finally {
session.close();
}
}
My entity class is -
import java.io.File;
import java.util.Date;
public class Campaign {
private long campaignId;
private String campaignName;
private long keywordId;
private String brandName;
private String clientName;
private String mobileNum;
private Date startTime;
private Date endTime;
private double campaignBudget;
private double allocatedFund;
private double campaignRate;
private boolean basicTgt;
private boolean customTgt;
private boolean advTgt;
private boolean chechme;
private boolean couponSend;
private String couponFrom;
private String couponTo;
private String couponFilePath;
private File[] couponFile;
private String[] couponFileFileName;
private String[] couponFileContent;
private String callbackUrl;
private String status;
private int campaignTypeId;
private long roAmount;
// edit
private int roType;
public int getRoType() {
return roType;
}
public void setRoType(int roType) {
this.roType = roType;
}
// edit
private String strStartTime;
private String strEndTime;
private String keyword;
private String keywordNum;
private int goal;
private double spentAmount;
private int goalAchievePercent;
private int dial;
private int uniqueDial;
private long userId;
private double campaignTotalAmount;
private double operatorShare;
private long responseCount;
private String strRoPdfFileName;
private File[] roPdf;
private String[] roPdfFileName;
private String[] roPdfContent;
public long getCampaignId() {
return campaignId;
}
public void setCampaignId(long campaignId) {
this.campaignId = campaignId;
}
public String getCampaignName() {
return campaignName;
}
public void setCampaignName(String campaignName) {
this.campaignName = campaignName;
}
public long getKeywordId() {
return keywordId;
}
public void setKeywordId(long keywordId) {
this.keywordId = keywordId;
}
public String getKeywordNum() {
return keywordNum;
}
public void setKeywordNum(String keywordNum) {
this.keywordNum = keywordNum;
}
public String getBrandName() {
return brandName;
}
public void setBrandName(String brandName) {
this.brandName = brandName;
}
public String getClientName() {
return clientName;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public String getMobileNum() {
return mobileNum;
}
public void setMobileNum(String mobileNum) {
this.mobileNum = mobileNum;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public double getCampaignBudget() {
return campaignBudget;
}
public void setCampaignBudget(double campaignBudget) {
this.campaignBudget = campaignBudget;
}
public double getAllocatedFund() {
return allocatedFund;
}
public void setAllocatedFund(double allocatedFund) {
this.allocatedFund = allocatedFund;
}
public double getCampaignRate() {
return campaignRate;
}
public void setCampaignRate(double campaignRate) {
this.campaignRate = campaignRate;
}
public boolean isBasicTgt() {
return basicTgt;
}
public void setBasicTgt(boolean basicTgt) {
this.basicTgt = basicTgt;
}
public boolean isCustomTgt() {
return customTgt;
}
public void setCustomTgt(boolean customTgt) {
this.customTgt = customTgt;
}
public boolean isAdvTgt() {
return advTgt;
}
public void setAdvTgt(boolean advTgt) {
this.advTgt = advTgt;
}
public boolean isChechme() {
return chechme;
}
public void setChechme(boolean chechme) {
this.chechme = chechme;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getStrStartTime() {
return strStartTime;
}
public void setStrStartTime(String strStartTime) {
this.strStartTime = strStartTime;
}
public String getStrEndTime() {
return strEndTime;
}
public void setStrEndTime(String strEndTime) {
this.strEndTime = strEndTime;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
public int getGoal() {
return goal;
}
public void setGoal(int goal) {
this.goal = goal;
}
public double getSpentAmount() {
return spentAmount;
}
public void setSpentAmount(double spentAmount) {
this.spentAmount = spentAmount;
}
public int getGoalAchievePercent() {
return goalAchievePercent;
}
public void setGoalAchievePercent(int goalAchievePercent) {
this.goalAchievePercent = goalAchievePercent;
}
public int getDial() {
return dial;
}
public void setDial(int dial) {
this.dial = dial;
}
public int getUniqueDial() {
return uniqueDial;
}
public void setUniqueDial(int uniqueDial) {
this.uniqueDial = uniqueDial;
}
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public boolean isCouponSend() {
return couponSend;
}
public void setCouponSend(boolean couponSend) {
this.couponSend = couponSend;
}
public String getCouponFrom() {
return couponFrom;
}
public void setCouponFrom(String couponFrom) {
this.couponFrom = couponFrom;
}
public String getCouponTo() {
return couponTo;
}
public void setCouponTo(String couponTo) {
this.couponTo = couponTo;
}
public String getCouponFilePath() {
return couponFilePath;
}
public void setCouponFilePath(String couponFilePath) {
this.couponFilePath = couponFilePath;
}
public File[] getCouponFile() {
return couponFile;
}
public void setCouponFile(File[] couponFile) {
this.couponFile = couponFile;
}
public String[] getCouponFileFileName() {
return couponFileFileName;
}
public void setCouponFileFileName(String[] couponFileFileName) {
this.couponFileFileName = couponFileFileName;
}
public String[] getCouponFileContent() {
return couponFileContent;
}
public void setCouponFileContent(String[] couponFileContent) {
this.couponFileContent = couponFileContent;
}
public String getCallbackUrl() {
return callbackUrl;
}
public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}
public int getCampaignTypeId() {
return campaignTypeId;
}
public void setCampaignTypeId(int campaignTypeId) {
this.campaignTypeId = campaignTypeId;
}
public long getRoAmount() {
return roAmount;
}
public void setRoAmount(long roAmount) {
this.roAmount = roAmount;
}
public double getOperatorShare() {
return operatorShare;
}
public void setOperatorShare(double operatorShare) {
this.operatorShare = operatorShare;
}
public long getResponseCount() {
return responseCount;
}
public void setResponseCount(long responseCount) {
this.responseCount = responseCount;
}
public double getCampaignTotalAmount() {
return campaignTotalAmount;
}
public void setCampaignTotalAmount(double campaignTotalAmount) {
this.campaignTotalAmount = campaignTotalAmount;
}
public String getStrRoPdfFileName() {
return strRoPdfFileName;
}
public void setStrRoPdfFileName(String strRoPdfFileName) {
this.strRoPdfFileName = strRoPdfFileName;
}
public File[] getRoPdf() {
return roPdf;
}
public void setRoPdf(File[] roPdf) {
this.roPdf = roPdf;
}
public String[] getRoPdfFileName() {
return roPdfFileName;
}
public void setRoPdfFileName(String[] roPdfFileName) {
this.roPdfFileName = roPdfFileName;
}
public String[] getRoPdfContent() {
return roPdfContent;
}
public void setRoPdfContent(String[] roPdfContent) {
this.roPdfContent = roPdfContent;
}
}
My xml mapping file is -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mogae.starStarWebServices.db.dao.IfrmCreateCampaign">
<insert id="insertCampaignData" statementType="PREPARED" >
insert into campaign(campaign_id,campaign_name,keyword_id,brand_name,client_name,mobile_num,start_time,end_time,campaign_type_id,ro_amount,ro_type,ro_pdf_file_name,campaign_budget,allocated_fund,campaign_rate,is_basic_tgt,is_custom_tgt,is_adv_tgt,is_checkme,is_coupon_send,coupon_from,coupon_to,coupon_file,callback_url,status) values (#{campaignId},#{campaignName},#{keywordId},#{brandName},#{clientName},#{mobileNum},#{startTime},#{endTime},#{campaignTypeId},#{roAmount},#{roType},
#{strRoPdfFileName},#{campaignBudget},#{allocatedFund},#{campaignRate},#{basicTgt},#{customTgt},#{advTgt},#{chechme},#{couponSend},#{couponFrom},#{couponTo},#{couponFileFileName},#{callbackUrl},#{status});
</insert>
<insert id="insertKeywordData" statementType="PREPARED" >
insert into keywords(keyword_id,keyword,keyword_num,booked_by,purchased_on,expires_on,status) values (#{keywordId},#{keyword},#{keywordNum},#{bookedBy},#{purchasedOn},#{expiresOn},#{status})
</insert>
</mapper>

Is there a way to set the order of Xstream serialization

I need to generate XML from java objects on Android. XML nodes must be in definite sequence.
Due XStream documentation order of XML nodes match object's fields define. There is no problems when I use java classes(String, Date...) as fields. But there is problem when I need serialize my objects as fields.
Here is my code:
final XStream x = new XStream();
x.autodetectAnnotations(true);
SecondEntity secondEntity = new SecondEntity();
secondEntity.setSecondaryDate(new Date());
secondEntity.setSecondaryString("Secondary String");
InnerEntity innerEntity = new InnerEntity();
innerEntity.setInnerDate(new Date());
innerEntity.setInnerString("Inner String");
SomeEntity someEntity = new SomeEntity();
someEntity.setInnerEntity(innerEntity);
someEntity.setSecondEntity(secondEntity);
someEntity.setSomeDate(new Date());
someEntity.setSomeString("Some string");
x.toXML(someEntity)
SomeEntity:
#XStreamAlias("SomeEntity")
public class SomeEntity {
#XStreamAlias("innerEntity")
private InnerEntity innerEntity;
#XStreamAlias("secondEntity")
private SecondEntity secondEntity;
#XStreamAlias("someString")
private String someString;
#XStreamAlias("someDate")
private Date someDate;
public InnerEntity getInnerEntity() {
return innerEntity;
}
public void setInnerEntity(InnerEntity innerEntity) {
this.innerEntity = innerEntity;
}
public SecondEntity getSecondEntity() {
return secondEntity;
}
public void setSecondEntity(SecondEntity secondEntity) {
this.secondEntity = secondEntity;
}
public String getSomeString() {
return someString;
}
public void setSomeString(String someString) {
this.someString = someString;
}
public Date getSomeDate() {
return someDate;
}
public void setSomeDate(Date someDate) {
this.someDate = someDate;
}
}
InnerEntity:
#XStreamAlias("InnerEntity")
public class InnerEntity {
#XStreamAlias("innerString")
private String innerString;
#XStreamAlias("innerDate")
private Date innerDate;
public String getInnerString() {
return innerString;
}
public void setInnerString(String innerString) {
this.innerString = innerString;
}
public Date getInnerDate() {
return innerDate;
}
public void setInnerDate(Date innerDate) {
this.innerDate = innerDate;
}
}
SecondEntity:
#XStreamAlias("SecondEntity")
public class SecondEntity {
#XStreamAlias("secondaryString")
private String secondaryString;
#XStreamAlias("secondaryDate")
private Date secondaryDate;
public String getSecondaryString() {
return secondaryString;
}
public void setSecondaryString(String secondaryString) {
this.secondaryString = secondaryString;
}
public Date getSecondaryDate() {
return secondaryDate;
}
public void setSecondaryDate(Date secondaryDate) {
this.secondaryDate = secondaryDate;
}
}
I get
<SomeEntity>
<innerEntity>
<innerDate>2013-02-28 18:04:24.184 UTC</innerDate>
<innerString>Inner String</innerString>
</innerEntity>
<secondEntity>
<secondaryDate>2013-02-28 18:04:24.183 UTC</secondaryDate>
<secondaryString>Secondary String</secondaryString>
</secondEntity>
<someDate>2013-02-28 18:04:24.184 UTC</someDate>
<someString>Some string</someString>
</SomeEntity>
When I need:
<SomeEntity>
<innerEntity>
<innerString>Inner String</innerString>
<innerDate>2013-02-28 18:04:24.184 UTC</innerDate>
</innerEntity>
<secondEntity>
<secondaryString>Secondary String</secondaryString>
<secondaryDate>2013-02-28 18:04:24.183 UTC</secondaryDate>
</secondEntity>
<someDate>2013-02-28 18:04:24.184 UTC</someDate>
<someString>Some string</someString>
</SomeEntity>
Please Implement this interface FieldKeySorter for InnerEntity and SecondEntity.

Categories

Resources