Project

General

Profile

« Previous | Next » 

Revision 1751

Added by Jing Tao over 21 years ago

Get rid of to_date function.

View differences:

src/edu/ucsb/nceas/metacat/MetacatReplication.java
27 27

  
28 28
package edu.ucsb.nceas.metacat;
29 29

  
30
import edu.ucsb.nceas.dbadapter.AbstractDatabase;
30 31
import java.util.*;
31 32
import java.io.*;
32 33
import java.sql.*;
......
45 46
  private static MetaCatUtil util = new MetaCatUtil();
46 47
  private Vector fileLocks = new Vector();
47 48
  private Thread lockThread = null;
49
  private static final AbstractDatabase dbAdapter = MetaCatUtil.dbAdapter;
48 50
  
49 51
  /**
50 52
   * Initialize the servlet by creating appropriate database connections
......
293 295
        //Get hub value
294 296
        hub = ((String[])params.get("hub"))[0];
295 297
        
296
        pstmt = dbConn.prepareStatement("INSERT INTO xml_replication " +
298
        /*pstmt = dbConn.prepareStatement("INSERT INTO xml_replication " +
297 299
                  "(server, last_checked, replicate, datareplicate, hub) " +
298 300
                                      "VALUES ('" + server + "', to_date(" +
299 301
                                      "'01/01/00', 'MM/DD/YY'), '" +
300 302
                                      replicate +"', '" +dataReplicate+"', '"
303
                                      + hub +"')");*/
304
        pstmt = dbConn.prepareStatement("INSERT INTO xml_replication " +
305
                  "(server, last_checked, replicate, datareplicate, hub) " +
306
                                      "VALUES ('" + server + "', "+ 
307
                                      dbAdapter.toDate("01/01/00", "MM/DD/YY") 
308
                                      + ", '" +
309
                                      replicate +"', '" +dataReplicate+"', '"
301 310
                                      + hub +"')");
311
        MetaCatUtil.debugMessage("5, new sql for todate:================== ", 1);
312
                              
302 313
        pstmt.execute();
303 314
        pstmt.close();
304 315
        dbConn.commit();
src/edu/ucsb/nceas/metacat/AssociateAccessPolicy.java
451 451
                insertStatement = conn.prepareStatement(
452 452
                  "INSERT INTO xml_access " + 
453 453
                  "(docid, principal_name, permission, perm_type, perm_order,"+
454
                  "begin_time,end_time,ticket_count, accessfileid) VALUES "+
455
               //"(?,?,?,?,?,to_date(?,'mm/dd/yy'),to_date(?,'mm/dd/yy'),?,?)");
456
                  "(?,?,?,?,?,?,?,?,?)");
454
                  "ticket_count, accessfileid) VALUES "+
455
                  "(?,?,?,?,?,?,?)");
457 456
                // Bind the values to the query
458 457
                insertStatement.setString(1, docId);
459 458
                insertStatement.setString(2, principal);
460 459
                insertStatement.setInt(3, permission);
461 460
                insertStatement.setString(4, permType);
462 461
                insertStatement.setString(5, permOrder);
463
                insertStatement.setString(6, beginTime);
464
                insertStatement.setString(7, endTime);
465
                insertStatement.setString(9, accessFileId);
462
                insertStatement.setString(7, accessFileId);
466 463
                if ( ticketCount > 0 ) 
467 464
                { 
468
                  insertStatement.setString(8, "" + ticketCount);
465
                  insertStatement.setString(6, "" + ticketCount);
469 466
                } 
470 467
                else 
471 468
                {
472
                  insertStatement.setString(8, null);
469
                  insertStatement.setString(6, null);
473 470
                }
474 471
                insertStatement.execute();
475 472
                hasRecord=rs.next();
src/edu/ucsb/nceas/metacat/DocumentImpl.java
311 311
      Date localtime = new Date();
312 312
      String dateString = formatter.format(localtime);
313 313
  
314
      String sqlDateString = "to_date('" + dateString + 
315
                                          "', 'YY-MM-DD HH24:MI:SS')";
314
      /*String sqlDateString = "to_date('" + dateString + 
315
                                          "', 'YY-MM-DD HH24:MI:SS')";*/
316
      String sqlDateString=dbAdapter.toDate(dateString, "YY-MM-DD HH24:MI:SS");
316 317
  
317 318
      StringBuffer sql = new StringBuffer();
318 319
      sql.append("insert into xml_documents (docid, docname, doctype, ");
......
329 330
      sql.append(sqlDateString).append(",");
330 331
      sql.append("'0')");
331 332
      pstmt = dbconn.prepareStatement(sql.toString());
333
      MetaCatUtil.debugMessage("2, new sql for todate:================== "+
334
                               sql.toString(), 1);
332 335
      pstmt.execute();
333 336
      pstmt.close();
334 337
      //dbconn.close();
......
428 431
      Date localtime = new Date();
429 432
      String dateString = formatter.format(localtime);
430 433
  
431
      String sqlDateString = "to_date('" + dateString + 
432
                                          "', 'YY-MM-DD HH24:MI:SS')";
433
  
434
      /*String sqlDateString = "to_date('" + dateString + 
435
                                          "', 'YY-MM-DD HH24:MI:SS')";*/
436
      String sqlDateString=dbAdapter.toDate(dateString, "YY-MM-DD HH24:MI:SS");
434 437
      StringBuffer sql = new StringBuffer();
435 438
      sql.append("insert into xml_documents (docid, docname, doctype, ");
436 439
      sql.append("user_owner, user_updated, server_location, rev,date_created");
......
448 451
      // Set auto commit fasle
449 452
      dbconn.setAutoCommit(false);
450 453
      pstmt = dbconn.prepareStatement(sql.toString());
454
      MetaCatUtil.debugMessage("3, new sql for todate:================== "+
455
                               sql.toString(), 1);
451 456
      pstmt.execute();
452 457
      // Commit the insert
453 458
      dbconn.commit();
......
2729 2734
      {
2730 2735
        // Set auto commit false
2731 2736
        dbConn.setAutoCommit(false);
2732
        pStmt = dbConn.prepareStatement("INSERT INTO xml_replication " +
2737
        /*pStmt = dbConn.prepareStatement("INSERT INTO xml_replication " +
2733 2738
                      "(server, last_checked, replicate, datareplicate, hub) " +
2734 2739
                       "VALUES ('" + server + "', to_date(" +
2735 2740
                       "'01/01/00', 'MM/DD/YY'), '" +
2741
                       replicate +"', '"+dataReplicate+"','"+ hub + "')");*/
2742
        pStmt = dbConn.prepareStatement("INSERT INTO xml_replication " +
2743
                      "(server, last_checked, replicate, datareplicate, hub) " +
2744
                       "VALUES ('" + server + "', " + 
2745
                       dbAdapter.toDate("01/01/00", "MM/DD/YY") + ", '" +
2736 2746
                       replicate +"', '"+dataReplicate+"','"+ hub + "')");
2747
        MetaCatUtil.debugMessage("4, new sql for todate:================== ", 1);
2748
                              
2737 2749
        pStmt.execute();
2738 2750
        dbConn.commit();
2739 2751
        // Increase usage number
src/edu/ucsb/nceas/metacat/ReplicationHandler.java
27 27
 
28 28
package edu.ucsb.nceas.metacat;
29 29

  
30
import edu.ucsb.nceas.dbadapter.AbstractDatabase;
30 31
import java.sql.*;
31 32
import java.util.*;
32 33
import java.lang.Thread; 
......
58 59
  MetaCatUtil util = new MetaCatUtil();
59 60
  ReplicationServerList serverList = null; 
60 61
  PrintWriter out;
62
  private static final AbstractDatabase dbAdapter = MetaCatUtil.dbAdapter;
61 63
  
62 64
  public ReplicationHandler(PrintWriter o)
63 65
  {
......
602 604
      {
603 605
         String datestr = datexml.substring(11, datexml.indexOf('<', 11));
604 606
         StringBuffer sql = new StringBuffer();
605
         sql.append("update xml_replication set last_checked = to_date('");
607
         /*sql.append("update xml_replication set last_checked = to_date('");
606 608
         sql.append(datestr).append("', 'YY-MM-DD HH24:MI:SS') where ");
607
         sql.append("server like '").append(server).append("'");
608
         //System.out.println("sql: " + sql.toString());
609
         sql.append("server like '").append(server).append("'");*/
610
         sql.append("update xml_replication set last_checked = ");
611
         sql.append(dbAdapter.toDate(datestr, "YY-MM-DD HH24:MI:SS"));
612
         sql.append(" where server like '").append(server).append("'");
609 613
         pstmt = dbConn.prepareStatement(sql.toString());
614
         MetaCatUtil.debugMessage("6, new sql for todate:================== "+
615
                                   sql.toString(), 1);
610 616
         pstmt.executeUpdate();
611 617
         dbConn.commit();
612 618
         pstmt.close();
src/edu/ucsb/nceas/metacat/ReplicationServerList.java
28 28

  
29 29
package edu.ucsb.nceas.metacat;
30 30

  
31
import edu.ucsb.nceas.dbadapter.AbstractDatabase;
31 32
import java.util.Vector;
32 33
import java.sql.*;
33 34

  
......
38 39
public class ReplicationServerList
39 40
{
40 41
  private static Vector serverList = null; //Vector to store server list
42
  private static final AbstractDatabase dbAdapter = MetaCatUtil.dbAdapter;
41 43
  
42 44
  /**
43 45
   * constructor of ReplicationServerList
......
442 444
             getDBConnection("ReplicationSErverList.addToServerListIfItIsNot");
443 445
        serialNumber=dbConn.getCheckOutSerialNumber();
444 446
        // Inser it into xml_replication table
445
        pStmt = dbConn.prepareStatement("INSERT INTO xml_replication " +
447
        /*pStmt = dbConn.prepareStatement("INSERT INTO xml_replication " +
446 448
                      "(server, last_checked, replicate, datareplicate, hub) "+
447 449
                       "VALUES ('" + givenServerName + "', to_date(" +
448 450
                       "'01/01/00', 'MM/DD/YY'), '" +
451
                       replicate +"', '"+dataReplicate+"','"+ hub + "')");*/
452
        pStmt = dbConn.prepareStatement("INSERT INTO xml_replication " +
453
                      "(server, last_checked, replicate, datareplicate, hub) "+
454
                       "VALUES ('" + givenServerName + "', "+
455
                        dbAdapter.toDate("01/01/00","MM/DD/YY") + ", '" +
449 456
                       replicate +"', '"+dataReplicate+"','"+ hub + "')");
450 457
        pStmt.execute();
458
        MetaCatUtil.debugMessage("7, new sql for todate:================== ", 1);
451 459
        pStmt.close();
452 460
      }//try
453 461
      catch (Exception e)

Also available in: Unified diff